Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2AD21752A for ; Sat, 1 Nov 2014 14:18:47 +0000 (UTC) Received: (qmail 77715 invoked by uid 500); 1 Nov 2014 10:18:47 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 77570 invoked by uid 500); 1 Nov 2014 10:18:46 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 77554 invoked by uid 99); 1 Nov 2014 10:18:46 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2014 10:18:46 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id AD251993C40; Sat, 1 Nov 2014 10:18:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sat, 01 Nov 2014 10:18:47 -0000 Message-Id: <8a83abdf160a452ba7919725cdf4af44@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: CAMEL-7988: file consumer - Should call abort in case read lock cannot be acquired if exception was thrown 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 Authored: Sat Nov 1 09:35:06 2014 +0100 Committer: Claus Ibsen 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 extends ScheduledBatchPollingConsum String absoluteFileName = file.getAbsoluteFilePath(); // check if we can begin processing the file - try { - final GenericFileProcessStrategy processStrategy = endpoint.getGenericFileProcessStrategy(); + final GenericFileProcessStrategy 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();