Class FileIdempotentRenameRepositoryReadLockStrategy

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, GenericFileExclusiveReadLockStrategy<File>, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    public class FileIdempotentRenameRepositoryReadLockStrategy
    extends org.apache.camel.support.service.ServiceSupport
    implements GenericFileExclusiveReadLockStrategy<File>, org.apache.camel.CamelContextAware
    A file read lock that uses an IdempotentRepository and rename as the lock strategy. This allows to plugin and use existing idempotent repositories that for example supports clustering. The other read lock strategies that are using marker files or file locks, are not guaranteed to work in clustered setup with various platform and file systems.
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acquireExclusiveReadLock​(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange)
      Acquires exclusive read lock to the file.
      protected String asKey​(GenericFile<File> file)  
      protected void doStart()  
      protected void doStop()  
      org.apache.camel.CamelContext getCamelContext()  
      org.apache.camel.spi.IdempotentRepository getIdempotentRepository()
      The idempotent repository to use as the store for the read locks.
      boolean isRemoveOnCommit()
      Whether to remove the file from the idempotent repository when doing a commit.
      boolean isRemoveOnRollback()
      Whether to remove the file from the idempotent repository when doing a rollback.
      void prepareOnStartup​(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint)
      Allows custom logic to be run on startup preparing the strategy, such as removing old lock files etc.
      void releaseExclusiveReadLockOnAbort​(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange)
      Releases the exclusive read lock granted by the acquireExclusiveReadLock method due an abort operation (acquireExclusiveReadLock returned false).
      void releaseExclusiveReadLockOnCommit​(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange)
      Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a commit operation (Exchange processing succeeded)
      void releaseExclusiveReadLockOnRollback​(GenericFileOperations<File> operations, GenericFile<File> file, org.apache.camel.Exchange exchange)
      Releases the exclusive read lock granted by the acquireExclusiveReadLock method due a rollback operation (Exchange processing failed)
      void setCamelContext​(org.apache.camel.CamelContext camelContext)  
      void setCheckInterval​(long checkInterval)
      Sets the check interval period.
      void setDeleteOrphanLockFiles​(boolean deleteOrphanLockFiles)
      Sets whether orphan marker files should be deleted upon startup
      void setIdempotentRepository​(org.apache.camel.spi.IdempotentRepository idempotentRepository)
      The idempotent repository to use as the store for the read locks.
      void setMarkerFiler​(boolean markerFile)
      Sets whether marker file should be used or not.
      void setReadLockLoggingLevel​(org.apache.camel.LoggingLevel readLockLoggingLevel)
      Sets logging level used when a read lock could not be acquired.
      void setRemoveOnCommit​(boolean removeOnCommit)
      Whether to remove the file from the idempotent repository when doing a commit.
      void setRemoveOnRollback​(boolean removeOnRollback)
      Whether to remove the file from the idempotent repository when doing a rollback.
      void setTimeout​(long timeout)
      Sets an optional timeout period.
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • FileIdempotentRenameRepositoryReadLockStrategy

        public FileIdempotentRenameRepositoryReadLockStrategy()
    • Method Detail

      • setCheckInterval

        public void setCheckInterval​(long checkInterval)
        Description copied from interface: GenericFileExclusiveReadLockStrategy
        Sets the check interval period.

        The check interval is used for sleeping between attempts to acquire read lock. Setting a high value allows to cater for slow writes in case the producer of the file is slow.

        The default period is 1000 millis.

        Specified by:
        setCheckInterval in interface GenericFileExclusiveReadLockStrategy<File>
        Parameters:
        checkInterval - interval in millis
      • getCamelContext

        public org.apache.camel.CamelContext getCamelContext()
        Specified by:
        getCamelContext in interface org.apache.camel.CamelContextAware
      • setCamelContext

        public void setCamelContext​(org.apache.camel.CamelContext camelContext)
        Specified by:
        setCamelContext in interface org.apache.camel.CamelContextAware
      • getIdempotentRepository

        public org.apache.camel.spi.IdempotentRepository getIdempotentRepository()
        The idempotent repository to use as the store for the read locks.
      • setIdempotentRepository

        public void setIdempotentRepository​(org.apache.camel.spi.IdempotentRepository idempotentRepository)
        The idempotent repository to use as the store for the read locks.
      • isRemoveOnRollback

        public boolean isRemoveOnRollback()
        Whether to remove the file from the idempotent repository when doing a rollback.

        By default this is true.

      • setRemoveOnRollback

        public void setRemoveOnRollback​(boolean removeOnRollback)
        Whether to remove the file from the idempotent repository when doing a rollback.

        By default this is true.

      • isRemoveOnCommit

        public boolean isRemoveOnCommit()
        Whether to remove the file from the idempotent repository when doing a commit.

        By default this is false.

      • setRemoveOnCommit

        public void setRemoveOnCommit​(boolean removeOnCommit)
        Whether to remove the file from the idempotent repository when doing a commit.

        By default this is false.

      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.service.BaseService
        Throws:
        Exception