camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-7988: file consumer - Should call abort in case read lock cannot be acquired if exception was thrown
Date Sat, 01 Nov 2014 10:18:47 GMT
CAMEL-7988: file consumer - Should call abort in case read lock cannot be acquired if exception
was thrown


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3ff3d94a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3ff3d94a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3ff3d94a

Branch: refs/heads/camel-2.14.x
Commit: 3ff3d94a5d791050c83711c1fc447f1bb82bf670
Parents: 9bebbe7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Nov 1 09:35:06 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Nov 1 11:18:38 2014 +0100

----------------------------------------------------------------------
 .../component/file/GenericFileConsumer.java     | 48 ++++++++++++--------
 .../FileLockExclusiveReadLockStrategy.java      |  4 +-
 2 files changed, 31 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3ff3d94a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
index 8a39211..a0907ac 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
@@ -342,27 +342,37 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum
         String absoluteFileName = file.getAbsoluteFilePath();
 
         // check if we can begin processing the file
-        try {
-            final GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
+        final GenericFileProcessStrategy<T> processStrategy = endpoint.getGenericFileProcessStrategy();
 
-            boolean begin = processStrategy.begin(operations, endpoint, exchange, file);
-            if (!begin) {
-                log.debug("{} cannot begin processing file: {}", endpoint, file);
-                try {
-                    // abort
-                    processStrategy.abort(operations, endpoint, exchange, file);
-                } finally {
-                    // begin returned false, so remove file from the in progress list as
its no longer in progress
-                    endpoint.getInProgressRepository().remove(absoluteFileName);
-                }
-                return false;
-            }
+        Exception beginCause = null;
+        boolean begin = false;
+        try {
+            begin = processStrategy.begin(operations, endpoint, exchange, file);
         } catch (Exception e) {
-            // remove file from the in progress list due to failure
-            endpoint.getInProgressRepository().remove(absoluteFileName);
-
-            String msg = endpoint + " cannot begin processing file: " + file + " due to:
" + e.getMessage();
-            handleException(msg, e);
+            beginCause = e;
+        }
+
+        if (!begin) {
+            // no something was wrong, so we need to abort and remove the file from the in
progress list
+            Exception abortCause = null;
+            log.debug("{} cannot begin processing file: {}", endpoint, file);
+            try {
+                // abort
+                processStrategy.abort(operations, endpoint, exchange, file);
+            } catch (Exception e) {
+                abortCause = e;
+            } finally {
+                // begin returned false, so remove file from the in progress list as its
no longer in progress
+                endpoint.getInProgressRepository().remove(absoluteFileName);
+            }
+            if (beginCause != null) {
+                String msg = endpoint + " cannot begin processing file: " + file + " due
to: " + beginCause.getMessage();
+                handleException(msg, beginCause);
+            }
+            if (abortCause != null) {
+                String msg2 = endpoint + " cannot abort processing file: " + file + " due
to: " + abortCause.getMessage();
+                handleException(msg2, abortCause);
+            }
             return false;
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3ff3d94a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
index 1d0c4d7..ca6797c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
@@ -107,8 +107,8 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
             // must handle IOException as some apps on Windows etc. will still somehow hold
a lock to a file
             // such as AntiVirus or MS Office that has special locks for it's supported files
             if (timeout == 0) {
-                // if not using timeout, then we cant retry, so rethrow
-                throw e;
+                // if not using timeout, then we cant retry, so return false
+                return false;
             }
             LOG.debug("Cannot acquire read lock. Will try again.", e);
             boolean interrupted = sleep();


Mime
View raw message