From 892178bedab648d06cb0fec63fac7a76e0079511 Mon Sep 17 00:00:00 2001 From: Nerses Aznauryan Date: Thu, 6 Jun 2013 21:55:02 +0100 Subject: [PATCH] CAMEL-5829: Adding readLockLoggingLevel to allow to configure logging level of read lock strategy. --- .../component/file/GenericFileEndpoint.java | 12 +++++ .../GenericFileExclusiveReadLockStrategy.java | 12 +++++ .../FileChangedExclusiveReadLockStrategy.java | 14 +++++- .../FileLockExclusiveReadLockStrategy.java | 16 ++++++- .../strategy/FileProcessStrategyFactory.java | 48 ++++++++----------- ...icFileRenameExclusiveReadLockStrategy.java | 16 ++++++- .../MarkerFileExclusiveReadLockStrategy.java | 11 +++++ ...nsumerBridgeRouteExceptionHandlerTest.java | 6 +++ ...ileConsumerCustomExceptionHandlerTest.java | 6 +++ .../FileChangedReadLockLoggingLevelTest.java | 32 +++++++++++++ .../FtpChangedExclusiveReadLockStrategy.java | 13 ++++- .../SftpChangedExclusiveReadLockStrategy.java | 13 ++++- .../FtpChangedReadLockLoggingLevelTest.java | 27 +++++++++++ 13 files changed, 192 insertions(+), 34 deletions(-) create mode 100644 camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockLoggingLevelTest.java create mode 100644 components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockLoggingLevelTest.java diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java index d74a334877e03..626a483d59598 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java @@ -29,6 +29,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Expression; import org.apache.camel.ExpressionIllegalSyntaxException; +import org.apache.camel.LoggingLevel; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.impl.ScheduledPollEndpoint; @@ -133,6 +134,8 @@ public abstract class GenericFileEndpoint extends ScheduledPollEndpoint imple @UriParam protected long readLockTimeout = 10000; @UriParam + protected LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; + @UriParam protected long readLockMinLength = 1; @UriParam protected GenericFileExclusiveReadLockStrategy exclusiveReadLockStrategy; @@ -596,6 +599,14 @@ public void setReadLockTimeout(long readLockTimeout) { this.readLockTimeout = readLockTimeout; } + public LoggingLevel getReadLockLoggingLevel() { + return readLockLoggingLevel; + } + + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } + public long getReadLockMinLength() { return readLockMinLength; } @@ -820,6 +831,7 @@ protected Map getParamsAsMap() { params.put("readLockTimeout", readLockTimeout); } params.put("readLockMinLength", readLockMinLength); + params.put("readLockLoggingLevel", readLockLoggingLevel); return params; } diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java index eff1bdb883741..05849d3dbf399 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java @@ -17,6 +17,7 @@ package org.apache.camel.component.file; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; /** * Strategy for acquiring exclusive read locks for files to be consumed. After @@ -89,4 +90,15 @@ public interface GenericFileExclusiveReadLockStrategy { */ void setCheckInterval(long checkInterval); + /** + * Sets logging level used when a read lock could not be acquired. + *

+ * Logging level used when a read lock could not be acquired. + *

+ * The default logging level is WARN + * @param readLockLoggingLevel LoggingLevel + */ + void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel); + + } diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java index 6d381846ae447..8eb1cce5572b6 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java @@ -19,8 +19,10 @@ import java.io.File; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileOperations; +import org.apache.camel.util.CamelLogger; import org.apache.camel.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +36,9 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea private long timeout; private long checkInterval = 1000; private long minLength = 1; + private LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; + @Override public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { // must call super if (!super.acquireExclusiveReadLock(operations, file, exchange)) { @@ -55,7 +59,8 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, if (timeout > 0) { long delta = watch.taken(); if (delta > timeout) { - LOG.warn("Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file); + 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; } @@ -101,6 +106,7 @@ public long getTimeout() { return timeout; } + @Override public void setTimeout(long timeout) { this.timeout = timeout; } @@ -109,10 +115,16 @@ public long getCheckInterval() { return checkInterval; } + @Override public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } + public long getMinLength() { return minLength; } 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 11f370b27f386..60cf941383e91 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 @@ -24,9 +24,11 @@ import java.nio.channels.FileLock; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; import org.apache.camel.component.file.GenericFileOperations; +import org.apache.camel.util.CamelLogger; import org.apache.camel.util.IOHelper; import org.apache.camel.util.StopWatch; import org.slf4j.Logger; @@ -43,11 +45,14 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo private long checkInterval = 1000; private FileLock lock; private String lockFileName; + private LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; + @Override public void prepareOnStartup(GenericFileOperations operations, GenericFileEndpoint endpoint) { // noop } + @Override public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { // must call super if (!super.acquireExclusiveReadLock(operations, file, exchange)) { @@ -70,7 +75,8 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, if (timeout > 0) { long delta = watch.taken(); if (delta > timeout) { - LOG.warn("Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + target); + CamelLogger.log(LOG, readLockLoggingLevel, + "Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + target); // we could not get the lock within the timeout period, so return false return false; } @@ -112,6 +118,7 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, return true; } + @Override public void releaseExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { @@ -144,12 +151,19 @@ public long getTimeout() { return timeout; } + @Override public void setTimeout(long timeout) { this.timeout = timeout; } + @Override public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } + } diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java index 4701c88831433..73e6e68a7b6ef 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java @@ -21,6 +21,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.Expression; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy; import org.apache.camel.component.file.GenericFileProcessStrategy; import org.apache.camel.spi.Language; @@ -109,48 +110,37 @@ private static GenericFileExclusiveReadLockStrategy getExclusiveReadLockSt if (ObjectHelper.isNotEmpty(readLock)) { if ("none".equals(readLock) || "false".equals(readLock)) { return null; + } else if ("markerFile".equals(readLock)) { + return new MarkerFileExclusiveReadLockStrategy(); } else if ("fileLock".equals(readLock)) { - GenericFileExclusiveReadLockStrategy readLockStrategy = new FileLockExclusiveReadLockStrategy(); - Long timeout = (Long) params.get("readLockTimeout"); - if (timeout != null) { - readLockStrategy.setTimeout(timeout); - } - Long checkInterval = (Long) params.get("readLockCheckInterval"); - if (checkInterval != null) { - readLockStrategy.setCheckInterval(checkInterval); - } - return readLockStrategy; + strategy = new FileLockExclusiveReadLockStrategy(); } else if ("rename".equals(readLock)) { - GenericFileExclusiveReadLockStrategy readLockStrategy = new FileRenameExclusiveReadLockStrategy(); - Long timeout = (Long) params.get("readLockTimeout"); - if (timeout != null) { - readLockStrategy.setTimeout(timeout); - } - Long checkInterval = (Long) params.get("readLockCheckInterval"); - if (checkInterval != null) { - readLockStrategy.setCheckInterval(checkInterval); - } - return readLockStrategy; + strategy = new FileRenameExclusiveReadLockStrategy(); } else if ("changed".equals(readLock)) { FileChangedExclusiveReadLockStrategy readLockStrategy = new FileChangedExclusiveReadLockStrategy(); + Long minLength = (Long) params.get("readLockMinLength"); + if (minLength != null) { + readLockStrategy.setMinLength(minLength); + } + strategy = readLockStrategy; + } + + if (strategy != null) { Long timeout = (Long) params.get("readLockTimeout"); if (timeout != null) { - readLockStrategy.setTimeout(timeout); + strategy.setTimeout(timeout); } Long checkInterval = (Long) params.get("readLockCheckInterval"); if (checkInterval != null) { - readLockStrategy.setCheckInterval(checkInterval); + strategy.setCheckInterval(checkInterval); } - Long minLength = (Long) params.get("readLockMinLength"); - if (minLength != null) { - readLockStrategy.setMinLength(minLength); + LoggingLevel readLockLoggingLevel = (LoggingLevel) params.get("readLockLoggingLevel"); + if (readLockLoggingLevel != null) { + strategy.setReadLockLoggingLevel(readLockLoggingLevel); } - return readLockStrategy; - } else if ("markerFile".equals(readLock)) { - return new MarkerFileExclusiveReadLockStrategy(); } } - return null; + return strategy; } } diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java index e8b9b9fe4dc2a..a62b5f6b06da3 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java @@ -17,10 +17,12 @@ package org.apache.camel.component.file.strategy; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy; import org.apache.camel.component.file.GenericFileOperations; +import org.apache.camel.util.CamelLogger; import org.apache.camel.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,11 +36,14 @@ public class GenericFileRenameExclusiveReadLockStrategy implements GenericFil private static final transient Logger LOG = LoggerFactory.getLogger(GenericFileRenameExclusiveReadLockStrategy.class); private long timeout; private long checkInterval; + private LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; + @Override public void prepareOnStartup(GenericFileOperations operations, GenericFileEndpoint endpoint) throws Exception { // noop } + @Override public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { LOG.trace("Waiting for exclusive read lock to file: {}", file); @@ -58,7 +63,8 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, Gen if (timeout > 0) { long delta = watch.taken(); if (delta > timeout) { - LOG.warn("Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file); + 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; } @@ -81,6 +87,7 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, Gen return true; } + @Override public void releaseExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { // noop @@ -101,11 +108,18 @@ public long getTimeout() { return timeout; } + @Override public void setTimeout(long timeout) { this.timeout = timeout; } + @Override public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; } + + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } } diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java index 28359f40c8bb7..fe419192fc740 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java @@ -19,6 +19,7 @@ import java.io.File; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.FileComponent; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; @@ -36,6 +37,7 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy { private static final transient Logger LOG = LoggerFactory.getLogger(MarkerFileExclusiveReadLockStrategy.class); + @Override public void prepareOnStartup(GenericFileOperations operations, GenericFileEndpoint endpoint) { String dir = endpoint.getConfiguration().getDirectory(); File file = new File(dir); @@ -51,6 +53,7 @@ public void prepareOnStartup(GenericFileOperations operations, GenericFile } } + @Override public boolean acquireExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { String lockFileName = getLockFileName(file); @@ -64,6 +67,7 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operations, return acquired; } + @Override public void releaseExclusiveReadLock(GenericFileOperations operations, GenericFile file, Exchange exchange) throws Exception { String lockFileName = exchange.getProperty(Exchange.FILE_LOCK_FILE_NAME, getLockFileName(file), String.class); @@ -78,14 +82,21 @@ public void releaseExclusiveReadLock(GenericFileOperations operations, } } + @Override public void setTimeout(long timeout) { // noop } + @Override public void setCheckInterval(long checkInterval) { // noop } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + // noop + } + private static void deleteLockFiles(File dir, boolean recursive) { File[] files = dir.listFiles(); if (files == null || files.length == 0) { diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBridgeRouteExceptionHandlerTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBridgeRouteExceptionHandlerTest.java index 883672b1931af..3c7fad01bd602 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBridgeRouteExceptionHandlerTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBridgeRouteExceptionHandlerTest.java @@ -21,6 +21,7 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.JndiRegistry; @@ -110,6 +111,11 @@ public void setCheckInterval(long checkInterval) { // noop } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + // noop + } + public int getCounter() { return counter; } diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java index a5987e167896c..f074ab820665a 100644 --- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java +++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java @@ -21,6 +21,7 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.Processor; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; @@ -167,6 +168,11 @@ public void setCheckInterval(long checkInterval) { // noop } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + // noop + } + public int getCounter() { return counter; } diff --git a/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockLoggingLevelTest.java b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockLoggingLevelTest.java new file mode 100644 index 0000000000000..9114e697d4f67 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockLoggingLevelTest.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.strategy; + +import org.apache.camel.builder.RouteBuilder; + +public class FileChangedReadLockLoggingLevelTest extends FileChangedReadLockTest { + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("file:target/changed/in?readLock=changed&readLockLoggingLevel=DEBUG").to("file:target/changed/out", "mock:result"); + } + }; + } +} \ No newline at end of file diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java index 9303ec795eeba..b21a5ae82d09e 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java @@ -19,10 +19,12 @@ import java.util.List; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy; import org.apache.camel.component.file.GenericFileOperations; +import org.apache.camel.util.CamelLogger; import org.apache.camel.util.StopWatch; import org.apache.commons.net.ftp.FTPFile; import org.slf4j.Logger; @@ -32,6 +34,7 @@ public class FtpChangedExclusiveReadLockStrategy implements GenericFileExclusive private static final transient Logger LOG = LoggerFactory.getLogger(FtpChangedExclusiveReadLockStrategy.class); private long timeout; private long checkInterval = 5000; + private LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; private long minLength = 1; private boolean fastExistsCheck; @@ -54,7 +57,8 @@ public boolean acquireExclusiveReadLock(GenericFileOperations operation if (timeout > 0) { long delta = watch.taken(); if (delta > timeout) { - LOG.warn("Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file); + 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; } @@ -123,6 +127,7 @@ public long getTimeout() { return timeout; } + @Override public void setTimeout(long timeout) { this.timeout = timeout; } @@ -131,10 +136,16 @@ public long getCheckInterval() { return checkInterval; } + @Override public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } + public long getMinLength() { return minLength; } diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java index a2e5bcc67f71d..5289a66c44464 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java @@ -20,10 +20,12 @@ import com.jcraft.jsch.ChannelSftp; import org.apache.camel.Exchange; +import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy; import org.apache.camel.component.file.GenericFileOperations; +import org.apache.camel.util.CamelLogger; import org.apache.camel.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,6 +34,7 @@ public class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv private static final transient Logger LOG = LoggerFactory.getLogger(SftpChangedExclusiveReadLockStrategy.class); private long timeout; private long checkInterval = 5000; + private LoggingLevel readLockLoggingLevel = LoggingLevel.WARN; private long minLength = 1; private boolean fastExistsCheck; @@ -54,7 +57,8 @@ public boolean acquireExclusiveReadLock(GenericFileOperations 0) { long delta = watch.taken(); if (delta > timeout) { - LOG.warn("Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file); + 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; } @@ -123,6 +127,7 @@ public long getTimeout() { return timeout; } + @Override public void setTimeout(long timeout) { this.timeout = timeout; } @@ -131,10 +136,16 @@ public long getCheckInterval() { return checkInterval; } + @Override public void setCheckInterval(long checkInterval) { this.checkInterval = checkInterval; } + @Override + public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) { + this.readLockLoggingLevel = readLockLoggingLevel; + } + public long getMinLength() { return minLength; } diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockLoggingLevelTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockLoggingLevelTest.java new file mode 100644 index 0000000000000..fe500a4b189f7 --- /dev/null +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockLoggingLevelTest.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.remote; + +/** + * + */ +public class FtpChangedReadLockLoggingLevelTest extends FtpChangedReadLockTest { + + protected String getFtpUrl() { + return super.getFtpUrl() + "&readLockLoggingLevel=DEBUG"; + } +}