You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2009/06/30 16:32:15 UTC

svn commit: r789761 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ test/java/org/apache/camel/component/file/

Author: hadrian
Date: Tue Jun 30 14:32:14 2009
New Revision: 789761

URL: http://svn.apache.org/viewvc?rev=789761&view=rev
Log:
CAMEL-1078.  Prepare for removal of GenericFileExchange.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java Tue Jun 30 14:32:14 2009
@@ -130,12 +130,12 @@
         return null;
     }
 
-    public boolean retrieveFile(String name, GenericFileExchange<File> exchange) throws GenericFileOperationFailedException {
+    public boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException {
         // noop as we use type converters to read the body content for java.io.File
         return true;
     }
 
-    public boolean storeFile(String fileName, GenericFileExchange<File> exchange) throws GenericFileOperationFailedException {
+    public boolean storeFile(String fileName, Exchange exchange) throws GenericFileOperationFailedException {
         ObjectHelper.notNull(endpoint, "endpoint");
 
         File file = new File(fileName);
@@ -267,5 +267,4 @@
         }
         return out;
     }
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Tue Jun 30 14:32:14 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -112,7 +113,7 @@
         for (int index = 0; index < total && isRunAllowed(); index++) {
             // only loop if we are started (allowed to run)
             // use poll to remove the head so it does not consume memory even after we have processed it
-            GenericFileExchange<T> exchange = (GenericFileExchange<T>) exchanges.poll();
+            Exchange exchange = (Exchange) exchanges.poll();
             // add current index and total as properties
             exchange.setProperty(Exchange.BATCH_INDEX, index);
             exchange.setProperty(Exchange.BATCH_SIZE, total);
@@ -124,9 +125,11 @@
         
         // remove the file from the in progress list in case the batch was limited by max messages per poll
         for (int index = 0; index < exchanges.size() && isRunAllowed(); index++) {
-            GenericFileExchange<T> exchange = (GenericFileExchange<T>) exchanges.poll();
-            String key = exchange.getGenericFile().getFileName();
-            endpoint.getInProgressRepository().remove(key);
+            Exchange exchange = (Exchange) exchanges.poll();
+            GenericFile<T> file = (GenericFile<T>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+            if (file != null) {
+                endpoint.getInProgressRepository().remove(file.getFileName());
+            }
         }
     }
 
@@ -153,25 +156,25 @@
      *
      * @param exchange the exchange
      */
-    protected void processExchange(final GenericFileExchange<T> exchange) {
+    protected void processExchange(final Exchange exchange) {
+        final GenericFile<T> target = (GenericFile<T>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
         if (log.isTraceEnabled()) {
-            log.trace("Processing remote file: " + exchange.getGenericFile());
+            log.trace("Processing remote file: " + target);
         }
 
         try {
             final GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
 
-            boolean begin = processStrategy.begin(operations, endpoint, exchange, exchange.getGenericFile());
+            boolean begin = processStrategy.begin(operations, endpoint, exchange, target);
             if (!begin) {
-                log.debug(endpoint + " cannot begin processing file: " + exchange.getGenericFile());
+                log.debug(endpoint + " cannot begin processing file: " + target);
                 // remove file from the in progress list as its no longer in progress
-                endpoint.getInProgressRepository().remove(exchange.getGenericFile().getFileName());
+                endpoint.getInProgressRepository().remove(target.getFileName());
                 return;
             }
 
             // must use file from exchange as it can be updated due the
             // preMoveNamePrefix/preMoveNamePostfix options
-            final GenericFile<T> target = exchange.getGenericFile();
             // must use full name when downloading so we have the correct path
             final String name = target.getAbsoluteFilePath();
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java Tue Jun 30 14:32:14 2009
@@ -41,6 +41,7 @@
     }
 
     public Exchange newInstance() {
-        return new GenericFileExchange<T>(this, getGenericFile());
+        GenericFile<T> file = (GenericFile<T>) getProperty(FileComponent.FILE_EXCHANGE_FILE);
+        return new GenericFileExchange<T>(this, file);
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOnCompletion.java Tue Jun 30 14:32:14 2009
@@ -68,7 +68,7 @@
         GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
 
         // after processing
-        final GenericFile<T> file = exchange.getGenericFile();
+        final GenericFile<T> file = (GenericFile<T>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
         boolean failed = exchange.isFailed();
 
         if (log.isDebugEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java Tue Jun 30 14:32:14 2009
@@ -18,6 +18,8 @@
 
 import java.util.List;
 
+import org.apache.camel.Exchange;
+
 public interface GenericFileOperations<T> {
 
     /**
@@ -65,7 +67,7 @@
      * @return true if file has been retrieved, false if not
      * @throws GenericFileOperationFailedException can be thrown
      */
-    boolean retrieveFile(String name, GenericFileExchange<T> exchange) throws GenericFileOperationFailedException;
+    boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException;
 
     /**
      * Stores the content as a new remote file (upload)
@@ -75,7 +77,7 @@
      * @return true if the file was stored, false if not
      * @throws GenericFileOperationFailedException can be thrown
      */
-    boolean storeFile(String name, GenericFileExchange<T> exchange) throws GenericFileOperationFailedException;
+    boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException;
 
     /**
      * Gets the current remote directory

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java Tue Jun 30 14:32:14 2009
@@ -66,8 +66,9 @@
                 from("file://target/reports?preMove=../inprogress/${file:name.noext}.bak&move=../done/${file:name}&consumer.delay=5000")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
-                                assertTrue(fe.getGenericFile().getRelativeFilePath().indexOf("inprogress") > -1);
+                                GenericFile<File> file = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+                                assertNotNull(file);
+                                assertTrue(file.getRelativeFilePath().indexOf("inprogress") > -1);
                             }
                         })
                         .to("mock:report");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java Tue Jun 30 14:32:14 2009
@@ -76,8 +76,9 @@
                 from("file://target/reports?preMove=../inprogress/${file:name}&move=../done/${file:name}&delay=5000")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
-                                assertTrue(fe.getGenericFile().getRelativeFilePath().indexOf("inprogress") > -1);
+                                GenericFile<File> file = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+                                assertNotNull(file);
+                                assertTrue(file.getRelativeFilePath().indexOf("inprogress") > -1);
                             }
                         })
                         .to("mock:report");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java Tue Jun 30 14:32:14 2009
@@ -75,8 +75,9 @@
                 from("file://target/reports?preMove=../inprogress/${file:name.noext}.bak&consumer.delay=5000")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
-                                assertTrue(fe.getGenericFile().getRelativeFilePath().indexOf("inprogress") > -1);
+                                GenericFile<File> file = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+                                assertNotNull(file);
+                                assertTrue(file.getRelativeFilePath().indexOf("inprogress") > -1);
                             }
                         })
                         .to("mock:report");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java?rev=789761&r1=789760&r2=789761&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java Tue Jun 30 14:32:14 2009
@@ -73,8 +73,9 @@
                 from("file://target/reports?preMove=../inprogress/${file:name}&consumer.delay=5000")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                GenericFileExchange<File> fe = (GenericFileExchange<File>) exchange;
-                                assertTrue(fe.getGenericFile().getRelativeFilePath().indexOf("inprogress") > -1);
+                                GenericFile<File> file = (GenericFile<File>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
+                                assertNotNull(file);
+                                assertTrue(file.getRelativeFilePath().indexOf("inprogress") > -1);
                             }
                         })
                         .to("mock:report");