servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r486860 - /incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java
Date Wed, 13 Dec 2006 22:14:57 GMT
Author: gnodet
Date: Wed Dec 13 14:14:57 2006
New Revision: 486860

URL: http://svn.apache.org/viewvc?view=rev&rev=486860
Log:
SM-706: Improve support for errors while processing jbi exchange and errors while deleting
file

Modified:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java?view=diff&rev=486860&r1=486859&r2=486860
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java
(original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollingEndpoint.java
Wed Dec 13 14:14:57 2006
@@ -25,6 +25,7 @@
 
 import javax.jbi.JBIException;
 import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
@@ -241,29 +242,38 @@
             public void run() {
                 final Lock lock = lockManager.getLock(file);
                 if (lock.tryLock()) {
+                    boolean unlock = true;
                     try {
-                        processFileAndDelete(file);
+                        unlock = processFileAndDelete(file);
                     }
                     finally {
-                        lock.unlock();
+                        if (unlock) {
+                            lock.unlock();
+                        }
                     }
                 }
             }
         });
     }
 
-    protected void processFileAndDelete(String file) {
+    protected boolean processFileAndDelete(String file) {
         FTPClient ftp = null;
+        boolean unlock = true;
         try {
             ftp = borrowClient();
             if (logger.isDebugEnabled()) {
                 logger.debug("Processing file " + file);
             }
+            // Process the file. If processing fails, an exception should be thrown.
             processFile(ftp, file);
+            // Processing is succesfull
+            // We should not unlock until the file has been deleted
+            unlock = false;
             if (isDeleteFile()) {
                 if (!ftp.deleteFile(file)) {
                     throw new IOException("Could not delete file " + file);
                 }
+                unlock = true;
             }
         }
         catch (Exception e) {
@@ -271,6 +281,7 @@
         } finally {
             returnClient(ftp);
         }
+        return unlock;
     }
 
     protected void processFile(FTPClient ftp, String file) throws Exception {
@@ -283,6 +294,13 @@
         sendSync(exchange);
         in.close();
         ftp.completePendingCommand();
+        if (exchange.getStatus() == ExchangeStatus.ERROR) {
+            Exception e = exchange.getError();
+            if (e == null) {
+                e = new JBIException("Unkown error");
+            }
+            throw e;
+        }
     }
 
     public String getLocationURI() {



Mime
View raw message