camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-7525: Added readLockMarkerFile to allow end users to turn it off for changed/rename read locks.
Date Fri, 04 Jul 2014 12:59:53 GMT
Repository: camel
Updated Branches:
  refs/heads/master 87bc5d4cd -> 693d289e8


CAMEL-7525: Added readLockMarkerFile to allow end users to turn it off for changed/rename
read locks.


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

Branch: refs/heads/master
Commit: cbc732ae0539e6aa3c46a4d95be216b6e325f949
Parents: 87bc5d4
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jul 4 14:55:27 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jul 4 14:55:27 2014 +0200

----------------------------------------------------------------------
 .../component/file/GenericFileEndpoint.java     | 11 +++++++
 .../GenericFileExclusiveReadLockStrategy.java   |  7 ++++-
 .../FileChangedExclusiveReadLockStrategy.java   |  2 ++
 .../strategy/FileProcessStrategyFactory.java    |  4 +++
 .../FileRenameExclusiveReadLockStrategy.java    | 15 +++++++--
 .../GenericFileProcessStrategyFactory.java      |  4 +++
 ...ericFileRenameExclusiveReadLockStrategy.java |  5 +++
 .../MarkerFileExclusiveReadLockStrategy.java    | 18 +++++++++++
 .../FileChangedReadLockMarkerFileFalseTest.java | 32 ++++++++++++++++++++
 9 files changed, 95 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 c50ff49..d921626 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
@@ -134,6 +134,8 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint
imple
     @UriParam
     protected long readLockTimeout = 10000;
     @UriParam
+    protected boolean readLockMarkerFile = true;
+    @UriParam
     protected LoggingLevel readLockLoggingLevel = LoggingLevel.WARN;
     @UriParam
     protected long readLockMinLength = 1;
@@ -599,6 +601,14 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint
imple
         this.readLockTimeout = readLockTimeout;
     }
 
+    public boolean isReadLockMarkerFile() {
+        return readLockMarkerFile;
+    }
+
+    public void setReadLockMarkerFile(boolean readLockMarkerFile) {
+        this.readLockMarkerFile = readLockMarkerFile;
+    }
+
     public LoggingLevel getReadLockLoggingLevel() {
         return readLockLoggingLevel;
     }
@@ -830,6 +840,7 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint
imple
         if (readLockTimeout > 0) {
             params.put("readLockTimeout", readLockTimeout);
         }
+        params.put("readLockMarkerFile", readLockMarkerFile);
         params.put("readLockMinLength", readLockMinLength);
         params.put("readLockLoggingLevel", readLockLoggingLevel);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 05849d3..36875f5 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
@@ -76,7 +76,6 @@ public interface GenericFileExclusiveReadLockStrategy<T> {
      */
     void setTimeout(long timeout);
 
-
     /**
      * Sets the check interval period.
      * <p/>
@@ -100,5 +99,11 @@ public interface GenericFileExclusiveReadLockStrategy<T> {
      */
     void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel);
 
+    /**
+     * Sets whether marker file should be used or not.
+     *
+     * @param markerFile <tt>true</tt> to use marker files.
+     */
+    void setMarkerFiler(boolean markerFile);
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 f40e12f..f471512 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
@@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory;
 /**
  * Acquires exclusive read lock to the given file by checking whether the file is being
  * changed by scanning the file at different intervals (to detect changes).
+ * <p/>
+ * Setting the option {@link #setMarkerFiler(boolean)} to <tt>false</tt> allows
to turn off using marker files.
  */
 public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveReadLockStrategy
{
     private static final Logger LOG = LoggerFactory.getLogger(FileChangedExclusiveReadLockStrategy.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 73e6e68..7fd3636 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
@@ -138,6 +138,10 @@ public final class FileProcessStrategyFactory {
                 if (readLockLoggingLevel != null) {
                     strategy.setReadLockLoggingLevel(readLockLoggingLevel);
                 }
+                Boolean readLockMarkerFile = (Boolean) params.get("readLockMarkerFile");
+                if (readLockMarkerFile != null) {
+                    strategy.setMarkerFiler(readLockMarkerFile);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenameExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenameExclusiveReadLockStrategy.java
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenameExclusiveReadLockStrategy.java
index ffaf26f..a2bbc49 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenameExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileRenameExclusiveReadLockStrategy.java
@@ -30,15 +30,18 @@ import org.apache.camel.component.file.GenericFileOperations;
  * This implementation is only supported by the File component, that leverages the {@link
MarkerFileExclusiveReadLockStrategy}
  * as well, to ensure only acquiring locks on files, which is not already in progress by
another process,
  * that have marked this using the marker file.
+ * <p/>
+ * Setting the option {@link #setMarkerFiler(boolean)} to <tt>false</tt> allows
to turn off using marker files.
  */
 public class FileRenameExclusiveReadLockStrategy extends GenericFileRenameExclusiveReadLockStrategy<File>
{
 
     private MarkerFileExclusiveReadLockStrategy marker = new MarkerFileExclusiveReadLockStrategy();
+    private boolean markerFile = true;
 
     @Override
     public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
GenericFile<File> file, Exchange exchange) throws Exception {
         // must call marker first
-        if (!marker.acquireExclusiveReadLock(operations, file, exchange)) {
+        if (markerFile && !marker.acquireExclusiveReadLock(operations, file, exchange))
{
             return false;
         }
 
@@ -50,10 +53,18 @@ public class FileRenameExclusiveReadLockStrategy extends GenericFileRenameExclus
                                          GenericFile<File> file, Exchange exchange)
throws Exception {
         // must call marker first
         try {
-            marker.releaseExclusiveReadLock(operations, file, exchange);
+            if (markerFile) {
+                marker.releaseExclusiveReadLock(operations, file, exchange);
+            }
         } finally {
             super.releaseExclusiveReadLock(operations, file, exchange);
         }
     }
 
+
+    @Override
+    public void setMarkerFiler(boolean markerFile) {
+        this.markerFile = markerFile;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
index b3018cf..28edafe 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
@@ -102,6 +102,10 @@ public final class GenericFileProcessStrategyFactory {
                 if (timeout != null) {
                     readLockStrategy.setTimeout(timeout);
                 }
+                Boolean readLockMarkerFile = (Boolean) params.get("readLockMarkerFile");
+                if (readLockMarkerFile != null) {
+                    readLockStrategy.setMarkerFiler(readLockMarkerFile);
+                }
                 return readLockStrategy;
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 cc17a2e..fe8343a 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
@@ -122,4 +122,9 @@ public class GenericFileRenameExclusiveReadLockStrategy<T> implements
GenericFil
     public void setReadLockLoggingLevel(LoggingLevel readLockLoggingLevel) {
         this.readLockLoggingLevel = readLockLoggingLevel;
     }
+
+    @Override
+    public void setMarkerFiler(boolean markerFile) {
+        // noop - we do not use marker file with the rename strategy
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cbc732ae/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 4bf8603..56d6282f 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
@@ -37,6 +37,8 @@ import org.slf4j.LoggerFactory;
 public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy<File>
{
     private static final Logger LOG = LoggerFactory.getLogger(MarkerFileExclusiveReadLockStrategy.class);
 
+    private boolean markerFile = true;
+
     @Override
     public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File>
endpoint) {
         String dir = endpoint.getConfiguration().getDirectory();
@@ -56,6 +58,12 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
     @Override
     public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
                                             GenericFile<File> file, Exchange exchange)
throws Exception {
+
+        if (!markerFile) {
+            // if not using marker file then we assume acquired
+            return true;
+        }
+
         String lockFileName = getLockFileName(file);
         LOG.trace("Locking the file: {} using the lock file name: {}", file, lockFileName);
 
@@ -70,6 +78,11 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
     @Override
     public void releaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange)
throws Exception {
+        if (!markerFile) {
+            // if not using marker file then nothing to release
+            return;
+        }
+
         String lockFileName = exchange.getProperty(Exchange.FILE_LOCK_FILE_NAME, getLockFileName(file),
String.class);
         File lock = new File(lockFileName);
         // only release the file if camel get the lock before
@@ -97,6 +110,11 @@ public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusive
         // noop
     }
 
+    @Override
+    public void setMarkerFiler(boolean markerFile) {
+        this.markerFile = markerFile;
+    }
+
     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/cbc732ae/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMarkerFileFalseTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMarkerFileFalseTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMarkerFileFalseTest.java
new file mode 100644
index 0000000..39f8dca
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMarkerFileFalseTest.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 FileChangedReadLockMarkerFileFalseTest extends FileChangedReadLockTest {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/changed/in?readLock=changed&readLockMarkerFile=false").to("file:target/changed/out",
"mock:result");
+            }
+        };
+    }
+}


Mime
View raw message