You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/06/07 10:41:38 UTC
[2/7] git commit: CAMEL-5829: File consumer - Allow to configure
logging level of read lock strategy. Thanks to Nerses Aznauryan for the
patch.
CAMEL-5829: File consumer - Allow to configure logging level of read lock strategy. Thanks to Nerses Aznauryan for the patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/92fa56a0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/92fa56a0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/92fa56a0
Branch: refs/heads/master
Commit: 92fa56a006ca0f10ed8725f44c42b1372dc43300
Parents: 741843a
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 7 09:44:48 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 7 09:44:48 2013 +0200
----------------------------------------------------------------------
.../camel/component/file/GenericFileEndpoint.java | 12 ++++
.../file/GenericFileExclusiveReadLockStrategy.java | 12 ++++
.../FileChangedExclusiveReadLockStrategy.java | 14 ++++-
.../FileLockExclusiveReadLockStrategy.java | 16 +++++-
.../file/strategy/FileProcessStrategyFactory.java | 48 ++++++---------
...GenericFileRenameExclusiveReadLockStrategy.java | 16 +++++-
.../MarkerFileExclusiveReadLockStrategy.java | 11 +++
...ileConsumerBridgeRouteExceptionHandlerTest.java | 6 ++
.../FileConsumerCustomExceptionHandlerTest.java | 6 ++
.../FileChangedReadLockLoggingLevelTest.java | 32 ++++++++++
.../FtpChangedExclusiveReadLockStrategy.java | 13 ++++-
.../SftpChangedExclusiveReadLockStrategy.java | 13 ++++-
.../remote/FtpChangedReadLockLoggingLevelTest.java | 27 ++++++++
13 files changed, 192 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.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 d74a334..626a483 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.Component;
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<T> extends ScheduledPollEndpoint imple
@UriParam
protected long readLockTimeout = 10000;
@UriParam
+ protected LoggingLevel readLockLoggingLevel = LoggingLevel.WARN;
+ @UriParam
protected long readLockMinLength = 1;
@UriParam
protected GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy;
@@ -596,6 +599,14 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
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 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
params.put("readLockTimeout", readLockTimeout);
}
params.put("readLockMinLength", readLockMinLength);
+ params.put("readLockLoggingLevel", readLockLoggingLevel);
return params;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 eff1bdb..05849d3 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<T> {
*/
void setCheckInterval(long checkInterval);
+ /**
+ * Sets logging level used when a read lock could not be acquired.
+ * <p/>
+ * Logging level used when a read lock could not be acquired.
+ * <p/>
+ * The default logging level is WARN
+ * @param readLockLoggingLevel LoggingLevel
+ */
+ void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel);
+
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 6d38184..8eb1cce 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 @@ package org.apache.camel.component.file.strategy;
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<File> operations, GenericFile<File> file, Exchange exchange) throws Exception {
// must call super
if (!super.acquireExclusiveReadLock(operations, file, exchange)) {
@@ -55,7 +59,8 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
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 class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
return timeout;
}
+ @Override
public void setTimeout(long timeout) {
this.timeout = timeout;
}
@@ -109,10 +115,16 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
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;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/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 11f370b..60cf941 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.FileChannel;
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<File> operations, GenericFileEndpoint<File> endpoint) {
// noop
}
+ @Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, Exchange exchange) throws Exception {
// must call super
if (!super.acquireExclusiveReadLock(operations, file, exchange)) {
@@ -70,7 +75,8 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
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 class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
return true;
}
+ @Override
public void releaseExclusiveReadLock(GenericFileOperations<File> operations,
GenericFile<File> file, Exchange exchange) throws Exception {
@@ -144,12 +151,19 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
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;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
----------------------------------------------------------------------
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 4701c88..73e6e68 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 java.util.Map;
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 @@ public final class FileProcessStrategyFactory {
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<File> 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<File> 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;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 e8b9b9f..a62b5f6 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<T> 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<T> operations, GenericFileEndpoint<T> endpoint) throws Exception {
// noop
}
+ @Override
public boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file,
Exchange exchange) throws Exception {
LOG.trace("Waiting for exclusive read lock to file: {}", file);
@@ -58,7 +63,8 @@ public class GenericFileRenameExclusiveReadLockStrategy<T> implements GenericFil
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 class GenericFileRenameExclusiveReadLockStrategy<T> implements GenericFil
return true;
}
+ @Override
public void releaseExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file,
Exchange exchange) throws Exception {
// noop
@@ -101,11 +108,18 @@ public class GenericFileRenameExclusiveReadLockStrategy<T> implements GenericFil
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;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 28359f4..fe41919 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 @@ package org.apache.camel.component.file.strategy;
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 @@ import org.slf4j.LoggerFactory;
public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy<File> {
private static final transient Logger LOG = LoggerFactory.getLogger(MarkerFileExclusiveReadLockStrategy.class);
+ @Override
public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint) {
String dir = endpoint.getConfiguration().getDirectory();
File file = new File(dir);
@@ -51,6 +53,7 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
}
}
+ @Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
GenericFile<File> file, Exchange exchange) throws Exception {
String lockFileName = getLockFileName(file);
@@ -64,6 +67,7 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
return acquired;
}
+ @Override
public void releaseExclusiveReadLock(GenericFileOperations<File> operations,
GenericFile<File> file, Exchange exchange) throws Exception {
String lockFileName = exchange.getProperty(Exchange.FILE_LOCK_FILE_NAME, getLockFileName(file), String.class);
@@ -78,14 +82,21 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
}
}
+ @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) {
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBridgeRouteExceptionHandlerTest.java
----------------------------------------------------------------------
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 883672b..3c7fad0 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 java.io.IOException;
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 class FileConsumerBridgeRouteExceptionHandlerTest extends ContextTestSupp
// noop
}
+ @Override
+ public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) {
+ // noop
+ }
+
public int getCounter() {
return counter;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCustomExceptionHandlerTest.java
----------------------------------------------------------------------
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 a5987e1..f074ab8 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 java.io.IOException;
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 class FileConsumerCustomExceptionHandlerTest extends ContextTestSupport {
// noop
}
+ @Override
+ public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) {
+ // noop
+ }
+
public int getCounter() {
return counter;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockLoggingLevelTest.java
----------------------------------------------------------------------
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 0000000..9114e69
--- /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
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/FtpChangedExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 9303ec7..b21a5ae 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 @@ package org.apache.camel.component.file.remote.strategy;
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 class FtpChangedExclusiveReadLockStrategy implements GenericFileExclusive
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 class FtpChangedExclusiveReadLockStrategy implements GenericFileExclusive
return timeout;
}
+ @Override
public void setTimeout(long timeout) {
this.timeout = timeout;
}
@@ -131,10 +136,16 @@ public class FtpChangedExclusiveReadLockStrategy implements GenericFileExclusive
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;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/strategy/SftpChangedExclusiveReadLockStrategy.java
----------------------------------------------------------------------
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 a2e5bcc..5289a66 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 java.util.List;
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 class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv
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 class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv
return timeout;
}
+ @Override
public void setTimeout(long timeout) {
this.timeout = timeout;
}
@@ -131,10 +136,16 @@ public class SftpChangedExclusiveReadLockStrategy implements GenericFileExclusiv
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;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/92fa56a0/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpChangedReadLockLoggingLevelTest.java
----------------------------------------------------------------------
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 0000000..fe500a4
--- /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";
+ }
+}