camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r988034 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/strategy/ test/java/org/apache/camel/component/file/
Date Mon, 23 Aug 2010 08:57:38 GMT
Author: davsclaus
Date: Mon Aug 23 08:57:37 2010
New Revision: 988034

URL: http://svn.apache.org/viewvc?rev=988034&view=rev
Log:
CAMEL-1895: file locks is stored on completion instead of Exchange.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=988034&r1=988033&r2=988034&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
Mon Aug 23 08:57:37 2010
@@ -28,7 +28,6 @@ import org.apache.camel.component.file.G
 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.ExchangeHelper;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.StopWatch;
 import org.apache.commons.logging.Log;
@@ -42,6 +41,8 @@ import org.apache.commons.logging.LogFac
 public class FileLockExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy<File>
{
     private static final transient Log LOG = LogFactory.getLog(FileLockExclusiveReadLockStrategy.class);
     private long timeout;
+    private FileLock lock;
+    private String lockFileName;
 
     public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File>
endpoint) {
         // noop
@@ -73,7 +74,6 @@ public class FileLockExclusiveReadLockSt
                 }
 
                 // get the lock using either try lock or not depending on if we are using
timeout or not
-                FileLock lock = null;
                 try {
                     lock = timeout > 0 ? channel.tryLock() : channel.lock();
                 } catch (IllegalStateException ex) {
@@ -83,11 +83,7 @@ public class FileLockExclusiveReadLockSt
                     if (LOG.isTraceEnabled()) {
                         LOG.trace("Acquired exclusive read lock: " + lock + " to file: "
+ target);
                     }
-
-                    // store lock so we can release it later
-                    exchange.setProperty("CamelFileLock", lock);
-                    exchange.setProperty("CamelFileLockName", target.getName());
-
+                    lockFileName = target.getName();
                     exclusive = true;
                 } else {
                     boolean interrupted = sleep();
@@ -119,14 +115,14 @@ public class FileLockExclusiveReadLockSt
 
     public void releaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange)
throws Exception {
-        FileLock lock = ExchangeHelper.getMandatoryProperty(exchange, "CamelFileLock", FileLock.class);
-        String lockFileName = ExchangeHelper.getMandatoryProperty(exchange, "CamelFileLockName",
String.class);
-        Channel channel = lock.channel();
-        try {
-            lock.release();
-        } finally {
-            // must close channel first
-            IOHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName,
LOG);
+        if (lock != null) {
+            Channel channel = lock.channel();
+            try {
+                lock.release();
+            } finally {
+                // must close channel first
+                IOHelper.close(channel, "while acquiring exclusive read lock for file: "
+ lockFileName, LOG);
+            }
         }
     }
 
@@ -152,7 +148,7 @@ public class FileLockExclusiveReadLockSt
     /**
      * Sets an optional timeout period.
      * <p/>
-     * If the readlock could not be granted within the timeperiod then the wait is stopped
and the
+     * If the readlock could not be granted within the time period then the wait is stopped
and the
      * acquireReadLock returns <tt>false</tt>.
      *
      * @param timeout period in millis

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java?rev=988034&r1=988033&r2=988034&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategyFactory.java
Mon Aug 23 08:57:37 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.file.strategy;
 
-import java.io.File;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java?rev=988034&r1=988033&r2=988034&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
Mon Aug 23 08:57:37 2010
@@ -24,7 +24,6 @@ import org.apache.camel.component.file.G
 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.ExchangeHelper;
 import org.apache.camel.util.FileUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,6 +34,8 @@ import org.apache.commons.logging.LogFac
  */
 public class MarkerFileExclusiveReadLockStrategy implements GenericFileExclusiveReadLockStrategy<File>
{
     private static final transient Log LOG = LogFactory.getLog(MarkerFileExclusiveReadLockStrategy.class);
+    private File lock;
+    private String lockFileName;
 
     public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File>
endpoint) {
         String dir = endpoint.getConfiguration().getDirectory();
@@ -49,18 +50,17 @@ public class MarkerFileExclusiveReadLock
 
     public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations,
                                             GenericFile<File> file, Exchange exchange)
throws Exception {
-
-        String lockFileName = file.getAbsoluteFilePath() + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
+        lockFileName = file.getAbsoluteFilePath() + FileComponent.DEFAULT_LOCK_FILE_POSTFIX;
         if (LOG.isTraceEnabled()) {
             LOG.trace("Locking the file: " + file + " using the lock file name: " + lockFileName);
         }
 
         // create a plain file as marker filer for locking (do not use FileLock)
-        File lock = new File(lockFileName);
+        lock = new File(lockFileName);
         boolean acquired = lock.createNewFile();
-        if (acquired) {
-            exchange.setProperty("CamelFileLock", lock);
-            exchange.setProperty("CamelFileLockName", lockFileName);
+        if (!acquired) {
+            lock = null;
+
         }
 
         return acquired;
@@ -68,17 +68,15 @@ public class MarkerFileExclusiveReadLock
 
     public void releaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange)
throws Exception {
+        if (lock != null) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Unlocking file: " + lockFileName);
+            }
 
-        File lock = ExchangeHelper.getMandatoryProperty(exchange, "CamelFileLock", File.class);
-        String lockFileName = ExchangeHelper.getMandatoryProperty(exchange, "CamelFileLockName",
String.class);
-
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Unlocking file: " + lockFileName);
-        }
-
-        boolean deleted = FileUtil.deleteFile(lock);
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Lock file: " + lockFileName + " was deleted: " + deleted);
+            boolean deleted = FileUtil.deleteFile(lock);
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Lock file: " + lockFileName + " was deleted: " + deleted);
+            }
         }
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java?rev=988034&r1=988033&r2=988034&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
Mon Aug 23 08:57:37 2010
@@ -59,9 +59,9 @@ public class FileConsumePollEnrichFileTe
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file://target/enrich?move=.done&readLock=none")
+                from("file://target/enrich?move=.done")
                     .to("mock:start")
-                    .pollEnrich("file://target/enrichdata?move=.done&readLock=none")
+                    .pollEnrich("file://target/enrichdata?move=.done")
                     .to("mock:result");
             }
         };



Mime
View raw message