Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3FCB8200BD8 for ; Tue, 22 Nov 2016 09:44:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3E819160B0A; Tue, 22 Nov 2016 08:44:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9138F160B0C for ; Tue, 22 Nov 2016 09:43:59 +0100 (CET) Received: (qmail 41099 invoked by uid 500); 22 Nov 2016 08:43:58 -0000 Mailing-List: contact issues-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 issues@camel.apache.org Received: (qmail 41078 invoked by uid 99); 22 Nov 2016 08:43:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Nov 2016 08:43:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 98C272C4C79 for ; Tue, 22 Nov 2016 08:43:58 +0000 (UTC) Date: Tue, 22 Nov 2016 08:43:58 +0000 (UTC) From: "Andrey Poltavtsev (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (CAMEL-10505) "FILE" component with option "readLock=rename" throws FileNotFound exception in case of work file is locked/used by another application MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 22 Nov 2016 08:44:00 -0000 [ https://issues.apache.org/jira/browse/CAMEL-10505?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Andrey Poltavtsev updated CAMEL-10505: -------------------------------------- Description: Option "readLock=rename" (according to htttp://camel.apache.org/file2.html) is necessary to lock work file in case of it is not used by another application. But currently we see "FileNotFound" during test rename operation and "FILE" component tries to lock and process corresponding work file. This issue can be resolved by wrapping of corresponding rename operation by try-catch block. See locally corrected code for "camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java" in attachment (diff.txt) was: Option "readLock=rename" (according to htttp://camel.apache.org/file2.html) is necessary to lock work file in case of it is not used by another application. But currently we see "FileNotFound" during test rename operation and "FILE" component tries to lock and process corresponding work file. This issue can be resolved by wrapping of corresponding rename operation by try-catch block. See locally corrected code for "camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java" @Override public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { LOG.trace("Waiting for exclusive read lock to file: {}", file); // the trick is to try to rename the file, if we can rename then we have exclusive read // since its a Generic file we cannot use java.nio to get a RW lock String newName = file.getFileName() + ".camelExclusiveReadLock"; // make a copy as result and change its file name GenericFile newFile = file.copyFrom(file); newFile.changeFileName(newName); StopWatch watch = new StopWatch(); boolean exclusive = false; while (!exclusive) { // timeout check if (timeout > 0) { long delta = watch.taken(); if (delta > timeout) { CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file); // we could not get the lock within the timeout period, so return false return false; } } try{ exclusive = operations.renameFile(file.getAbsoluteFilePath(), newFile.getAbsoluteFilePath()); }catch(GenericFileOperationFailedException ex){ if(ex.getCause() !=null && ex.getCause() instanceof FileNotFoundException){ exclusive = false; }else{ throw ex; } } if (exclusive) { LOG.trace("Acquired exclusive read lock to file: {}", file); // rename it back so we can read it operations.renameFile(newFile.getAbsoluteFilePath(), file.getAbsoluteFilePath()); } else { boolean interrupted = sleep(); if (interrupted) { // we were interrupted while sleeping, we are likely being shutdown so return false return false; } } } return true; } > "FILE" component with option "readLock=rename" throws FileNotFound exception in case of work file is locked/used by another application > --------------------------------------------------------------------------------------------------------------------------------------- > > Key: CAMEL-10505 > URL: https://issues.apache.org/jira/browse/CAMEL-10505 > Project: Camel > Issue Type: Bug > Components: camel-core > Affects Versions: 2.17.3 > Environment: Windows 7 / Java 8. > Reporter: Andrey Poltavtsev > Fix For: 2.17.4, 2.18.1, 2.19.0 > > Attachments: diff.txt > > > Option "readLock=rename" (according to htttp://camel.apache.org/file2.html) is necessary to lock work file in case of it is not used by another application. But currently we see "FileNotFound" during test rename operation and "FILE" component tries to lock and process corresponding work file. > This issue can be resolved by wrapping of corresponding rename operation by try-catch block. See locally corrected code for "camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java" in attachment (diff.txt) > -- This message was sent by Atlassian JIRA (v6.3.4#6332)