Author: davsclaus
Date: Sat Apr 12 08:52:03 2008
New Revision: 647463

URL: http://svn.apache.org/viewvc?rev=647463&view=rev
Log:
CAMEL-443 improved javadoc for file component and polishing of the code

Added:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/package.html
Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProcessStrategy.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenamer.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
 Sat Apr 12 08:52:03 2008
@@ -26,20 +26,24 @@
 import org.apache.commons.logging.LogFactory;
 
 /**
+ * For consuming files.
+ *
  * @version $Revision$
  */
 public class FileConsumer extends ScheduledPollConsumer<FileExchange> {
     private static final transient Log LOG = 
LogFactory.getLog(FileConsumer.class);
-    ConcurrentHashMap<File, File> filesBeingProcessed = new 
ConcurrentHashMap<File, File>();
-    boolean generateEmptyExchangeWhenIdle;
-    private final FileEndpoint endpoint;
+
+    private FileEndpoint endpoint;
+    private ConcurrentHashMap<File, File> filesBeingProcessed = new 
ConcurrentHashMap<File, File>();
+    private ConcurrentHashMap<File, Long> fileSizes = new 
ConcurrentHashMap<File, Long>();
+
+    private boolean generateEmptyExchangeWhenIdle;
     private boolean recursive = true;
     private String regexPattern = "";
-    private long lastPollTime;
 
+    private long lastPollTime;
     private int unchangedDelay;
     private boolean unchangedSize;
-    private ConcurrentHashMap<File, Long> fileSizes = new 
ConcurrentHashMap<File, Long>();
 
     public FileConsumer(final FileEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -59,8 +63,10 @@
     }
 
     /**
-     * @param fileOrDirectory
-     * @param processDir
+     * Pools the given file or directory for files to process.
+     *
+     * @param fileOrDirectory  file or directory
+     * @param processDir  recursive
      * @return the number of files processed or being processed async.
      */
     protected int pollFileOrDirectory(File fileOrDirectory, boolean 
processDir) {
@@ -71,8 +77,8 @@
             if (isValidFile(fileOrDirectory)) {
                 LOG.debug("Polling directory " + fileOrDirectory);
                 File[] files = fileOrDirectory.listFiles();
-                for (int i = 0; i < files.length; i++) {
-                    rc += pollFileOrDirectory(files[i], isRecursive()); // 
self-recursion
+                for (File file : files) {
+                    rc += pollFileOrDirectory(file, isRecursive()); // 
self-recursion
                 }
             }
             return rc;
@@ -83,8 +89,10 @@
     }
 
     /**
-     * @param file
-     * @return the number of files processed or being processed async.
+     * Polls the given file
+     *
+     * @param file  the file
+     * @return returns 1 if the file was processed, 0 otherwise.
      */
     protected int pollFile(final File file) {
 
@@ -123,13 +131,12 @@
             if (processStrategy.begin(endpoint, exchange, file)) {
 
                 // Use the async processor interface so that processing of
-                // the
-                // exchange can happen asynchronously
+                // the exchange can happen asynchronously
                 getAsyncProcessor().process(exchange, new AsyncCallback() {
                     public void done(boolean sync) {
                         if (exchange.getException() == null) {
                             try {
-                                processStrategy.commit(endpoint, 
(FileExchange)exchange, file);
+                                processStrategy.commit(endpoint, exchange, 
file);
                             } catch (Exception e) {
                                 handleException(e);
                             }
@@ -154,8 +161,7 @@
     protected boolean isValidFile(File file) {
         boolean result = false;
         if (file != null && file.exists()) {
-            // TODO: maybe use a configurable strategy instead of the
-            // hardcoded one based on last file change
+            // TODO: maybe use a configurable strategy instead of the 
hardcoded one based on last file change
             if (isMatched(file) && isUnchanged(file)) {
                 result = true;
             }
@@ -184,7 +190,7 @@
             if (isUnchangedSize()) {
                 long prevFileSize = (fileSizes.get(file) == null) ? 0 : 
fileSizes.get(file).longValue();
                 sizeDifference = file.length() - prevFileSize;
-                sizeCheck = 0 == sizeDifference;
+                sizeCheck = (sizeDifference == 0);
             }
 
             boolean answer = lastModifiedCheck && sizeCheck;
@@ -233,30 +239,18 @@
         return true;
     }
 
-    /**
-     * @return the recursive
-     */
     public boolean isRecursive() {
         return this.recursive;
     }
 
-    /**
-     * @param recursive the recursive to set
-     */
     public void setRecursive(boolean recursive) {
         this.recursive = recursive;
     }
 
-    /**
-     * @return the regexPattern
-     */
     public String getRegexPattern() {
         return this.regexPattern;
     }
 
-    /**
-     * @param regexPattern the regexPattern to set
-     */
     public void setRegexPattern(String regexPattern) {
         this.regexPattern = regexPattern;
     }

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
 Sat Apr 12 08:52:03 2008
@@ -121,7 +121,7 @@
     public FileProcessStrategy getFileStrategy() {
         if (fileProcessStrategy == null) {
             fileProcessStrategy = createFileStrategy();
-            LOG.debug("" + this + " using strategy: " + fileProcessStrategy);
+            LOG.debug("Using file process strategy: " + fileProcessStrategy);
         }
         return fileProcessStrategy;
     }
@@ -220,8 +220,6 @@
     /**
      * When writing do we append to the end of the file, or replace it?
      * The default is to append
-     *
-     * @param append whether to append (or replace)
      */
     public void setAppend(boolean append) {
         this.append = append;

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
 Sat Apr 12 08:52:03 2008
@@ -42,16 +42,10 @@
         this.file = file;
     }
 
-    /**
-     * @return the file
-     */
     public File getFile() {
         return this.file;
     }
 
-    /**
-     * @param file the file to set
-     */
     public void setFile(File file) {
         this.file = file;
     }
@@ -59,4 +53,5 @@
     public Exchange newInstance() {
         return new FileExchange(this, getFile());
     }
+
 }

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProcessStrategy.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProcessStrategy.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProcessStrategy.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProcessStrategy.java
 Sat Apr 12 08:52:03 2008
@@ -18,24 +18,33 @@
 
 import java.io.File;
 
-import org.apache.camel.Endpoint;
-
 /**
  * Represents a strategy for marking that a file is processed.
  *
  * @version $Revision$
  */
 public interface FileProcessStrategy {
+
     /**
      * Called when work is about to begin on this file. This method may 
attempt to acquire some file lock before
      * returning true; returning false if the file lock could not be obtained 
so that the file should be ignored.
      *
+     * @param endpoint  the endpoint
+     * @param exchange  the exchange
+     * @param file      the file
      * @return true if the file can be processed (such as if a file lock could 
be obtained)
+     * @throws Exception can be thrown in case of errors
      */
     boolean begin(FileEndpoint endpoint, FileExchange exchange, File file) 
throws Exception;
 
     /**
      * Releases any file locks and possibly deletes or moves the file
+     *
+     * @param endpoint  the endpoint
+     * @param exchange  the exchange
+     * @param file      the file
+     * @throws Exception can be thrown in case of errors
      */
     void commit(FileEndpoint endpoint, FileExchange exchange, File file) 
throws Exception;
+    
 }

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
 Sat Apr 12 08:52:03 2008
@@ -39,7 +39,7 @@
  */
 public class FileProducer extends DefaultProducer {
     private static final transient Log LOG = 
LogFactory.getLog(FileProducer.class);
-    private final FileEndpoint endpoint;
+    private FileEndpoint endpoint;
 
     public FileProducer(FileEndpoint endpoint) {
         super(endpoint);
@@ -50,10 +50,6 @@
         return (FileEndpoint) super.getEndpoint();
     }
 
-    /**
-     * @param exchange
-     * @see org.apache.camel.Processor#process(Exchange)
-     */
     public void process(Exchange exchange) throws Exception {
         // TODO is it really worth using a FileExchange as the core type?
         FileExchange fileExchange = endpoint.createExchange(exchange);
@@ -68,9 +64,11 @@
             endpoint.configureMessage(endpoint.getFile(), out);
             return;
         }
+
         InputStream in = ExchangeHelper.getMandatoryInBody(exchange, 
InputStream.class);
         File file = createFileName(exchange.getIn());
         buildDirectory(file);
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("About to write to: " + file + " from exchange: " + 
exchange);
         }
@@ -82,6 +80,7 @@
             } else {
                 fc = new FileOutputStream(file).getChannel();
             }
+
             int size = getEndpoint().getBufferSize();
             byte[] buffer = new byte[size];
             ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
@@ -114,47 +113,17 @@
                 }
             }
         }
-        /*
-        ByteBuffer payload = exchange.getIn().getBody(ByteBuffer.class);
-        if (payload == null) {
-            InputStream in = ExchangeHelper.getMandatoryInBody(exchange, 
InputStream.class);
-            payload = ExchangeHelper.convertToMandatoryType(exchange, 
ByteBuffer.class, in);
-        }
-        payload.flip();
-        File file = createFileName(exchange);
-        buildDirectory(file);
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Creating file: " + file);
-        }
-        FileChannel fc = null;
-        try {
-            if (getEndpoint().isAppend()) {
-                fc = new RandomAccessFile(file, "rw").getChannel();
-                fc.position(fc.size());
-            }
-            else {
-                fc = new FileOutputStream(file).getChannel();
-            }
-            fc.write(payload);
-        }
-        catch (Throwable e) {
-            LOG.error("Failed to write to File: " + file, e);
-        }
-        finally {
-            if (fc != null) {
-                fc.close();
-            }
-        }
-        */
     }
 
     protected File createFileName(Message message) {
         File answer;
-        File endpointFile = endpoint.getFile();
+
         String name = null;
         if (!endpoint.isIgnoreFileNameHeader()) {
             name = message.getHeader(FileComponent.HEADER_FILE_NAME, 
String.class);
         }
+
+        File endpointFile = endpoint.getFile();
         if (endpointFile.isDirectory()) {
             if (name != null) {
                 answer = new File(endpointFile, name);
@@ -171,6 +140,7 @@
                 answer = new File(endpointFile, name);
             }
         }
+
         return answer;
     }
 
@@ -183,4 +153,5 @@
             dir.mkdirs();
         }
     }
+
 }

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
 Sat Apr 12 08:52:03 2008
@@ -19,6 +19,8 @@
 import java.io.File;
 
 /**
+ * Camel default file renamer.
+ *
  * @version $Revision$
  */
 public class DefaultFileRenamer implements FileRenamer {
@@ -70,7 +72,6 @@
     public void setNamePrefix(String namePrefix) {
         this.namePrefix = namePrefix;
     }
-
 
     protected String renameFileName(File file) {
         StringBuffer buffer = new StringBuffer();

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
 Sat Apr 12 08:52:03 2008
@@ -18,20 +18,24 @@
 
 import org.apache.camel.component.file.FileProcessStrategy;
 
+/**
+ * Factory to provide the [EMAIL PROTECTED] 
org.apache.camel.component.file.FileProcessStrategy} to use.
+ */
 public final class FileProcessStrategyFactory {
+
     private FileProcessStrategyFactory() {
         // Utility class
     }
+
     /**
-     * A strategy method to lazily create the file strategy
+     * A strategy method to lazily create the file strategy to use.
      */
     public static FileProcessStrategy createFileProcessStrategy(boolean 
isNoop, boolean isDelete, boolean isLock, String moveNamePrefix, String 
moveNamePostfix) {
         if (isNoop) {
             return new NoOpFileProcessStrategy();
         } else if (moveNamePostfix != null || moveNamePrefix != null) {
             if (isDelete) {
-                throw new IllegalArgumentException(
-                                                   "You cannot set the 
deleteFiles property and a moveFilenamePostfix or moveFilenamePrefix");
+                throw new IllegalArgumentException("You cannot set the 
deleteFiles property and a moveFilenamePostfix or moveFilenamePrefix");
             }
             return new RenameFileProcessStrategy(isLock, moveNamePrefix, 
moveNamePostfix);
         } else if (isDelete) {

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategySupport.java
 Sat Apr 12 08:52:03 2008
@@ -22,7 +22,6 @@
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 
-import org.apache.camel.Endpoint;
 import org.apache.camel.component.file.FileEndpoint;
 import org.apache.camel.component.file.FileExchange;
 import org.apache.camel.component.file.FileProcessStrategy;
@@ -31,6 +30,8 @@
 import org.apache.commons.logging.LogFactory;
 
 /**
+ * Base class for [EMAIL PROTECTED] 
org.apache.camel.component.file.FileProcessStrategy} implementation to extend.
+ *
  * @version $Revision$
  */
 public abstract class FileProcessStrategySupport implements 
FileProcessStrategy {

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenamer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenamer.java?rev=647463&r1=647462&r2=647463&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenamer.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenamer.java
 Sat Apr 12 08:52:03 2008
@@ -19,9 +19,17 @@
 import java.io.File;
 
 /**
+ * Used for renaming files.
+ *
  * @version $Revision$
  */
 public interface FileRenamer {
 
+    /**
+     * Renames the given file
+     *
+     * @param file  the original file.
+     * @return  the renamed file.
+     */
     File renameFile(File file);
 }

Added: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/package.html
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/package.html?rev=647463&view=auto
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/package.html
 (added)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/package.html
 Sat Apr 12 08:52:03 2008
@@ -0,0 +1,25 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Strategies for the File Component.
+
+</body>
+</html>


Reply via email to