org.apache.camel.processor.idempotent
Class FileIdempotentRepository

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.processor.idempotent.FileIdempotentRepository
All Implemented Interfaces:
Service, ShutdownableService, IdempotentRepository<String>, StatefulService, SuspendableService

@ManagedResource(description="File based idempotent repository")
public class FileIdempotentRepository
extends ServiceSupport
implements IdempotentRepository<String>

A file based implementation of IdempotentRepository.

Care should be taken to use a suitable underlying Map to avoid this class being a memory leak.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
FileIdempotentRepository()
           
FileIdempotentRepository(File fileStore, Map<String,Object> set)
           
 
Method Summary
 boolean add(String key)
          Adds the key to the repository.
protected  void appendToStore(String messageId)
          Appends the given message id to the file store
 boolean confirm(String key)
          Confirms the key, after the exchange has been processed successfully.
 boolean contains(String key)
          Returns true if this repository contains the specified element.
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
static IdempotentRepository<String> fileIdempotentRepository(File fileStore)
          Creates a new file based repository using a LRUCache as 1st level cache with a default of 1000 entries in the cache.
static IdempotentRepository<String> fileIdempotentRepository(File fileStore, int cacheSize)
          Creates a new file based repository using a LRUCache as 1st level cache.
static IdempotentRepository<String> fileIdempotentRepository(File fileStore, int cacheSize, long maxFileStoreSize)
          Creates a new file based repository using a LRUCache as 1st level cache.
static IdempotentRepository<String> fileIdempotentRepository(File store, Map<String,Object> cache)
          Creates a new file based repository using the given Map as 1st level cache.
 Map<String,Object> getCache()
           
 int getCacheSize()
           
 String getFilePath()
           
 File getFileStore()
           
 long getMaxFileStoreSize()
           
protected  void loadStore()
          Loads the given file store into the 1st level cache
 boolean remove(String key)
          Removes the key from the repository.
 void reset()
          Reset and clears the store to force it to reload from file
 void setCache(Map<String,Object> cache)
           
 void setCacheSize(int size)
          Sets the cache size
 void setFileStore(File fileStore)
           
 void setMaxFileStoreSize(long maxFileStoreSize)
          Sets the maximum file size for the file store in bytes.
protected  void trunkStore()
          Trunks the file store when the max store size is hit by rewriting the 1st level cache to the file store.
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

FileIdempotentRepository

public FileIdempotentRepository()

FileIdempotentRepository

public FileIdempotentRepository(File fileStore,
                                Map<String,Object> set)
Method Detail

fileIdempotentRepository

public static IdempotentRepository<String> fileIdempotentRepository(File fileStore)
Creates a new file based repository using a LRUCache as 1st level cache with a default of 1000 entries in the cache.

Parameters:
fileStore - the file store

fileIdempotentRepository

public static IdempotentRepository<String> fileIdempotentRepository(File fileStore,
                                                                    int cacheSize)
Creates a new file based repository using a LRUCache as 1st level cache.

Parameters:
fileStore - the file store
cacheSize - the cache size

fileIdempotentRepository

public static IdempotentRepository<String> fileIdempotentRepository(File fileStore,
                                                                    int cacheSize,
                                                                    long maxFileStoreSize)
Creates a new file based repository using a LRUCache as 1st level cache.

Parameters:
fileStore - the file store
cacheSize - the cache size
maxFileStoreSize - the max size in bytes for the filestore file

fileIdempotentRepository

public static IdempotentRepository<String> fileIdempotentRepository(File store,
                                                                    Map<String,Object> cache)
Creates a new file based repository using the given Map as 1st level cache.

Care should be taken to use a suitable underlying Map to avoid this class being a memory leak.

Parameters:
store - the file store
cache - the cache to use as 1st level cache

add

@ManagedOperation(description="Adds the key to the store")
public boolean add(String key)
Description copied from interface: IdempotentRepository
Adds the key to the repository.

Specified by:
add in interface IdempotentRepository<String>
Parameters:
key - the key of the message for duplicate test
Returns:
true if this repository did not already contain the specified element

contains

@ManagedOperation(description="Does the store contain the given key")
public boolean contains(String key)
Description copied from interface: IdempotentRepository
Returns true if this repository contains the specified element.

This operation is used if the option eager has been enabled.

Specified by:
contains in interface IdempotentRepository<String>
Parameters:
key - the key of the message
Returns:
true if this repository contains the specified element

remove

@ManagedOperation(description="Remove the key from the store")
public boolean remove(String key)
Description copied from interface: IdempotentRepository
Removes the key from the repository.

Is usually invoked if the exchange failed.

Specified by:
remove in interface IdempotentRepository<String>
Parameters:
key - the key of the message for duplicate test
Returns:
true if the key was removed

confirm

public boolean confirm(String key)
Description copied from interface: IdempotentRepository
Confirms the key, after the exchange has been processed successfully.

This operation is used if the option eager has been enabled.

Specified by:
confirm in interface IdempotentRepository<String>
Parameters:
key - the key of the message for duplicate test
Returns:
true if the key was confirmed

getFileStore

public File getFileStore()

setFileStore

public void setFileStore(File fileStore)

getFilePath

@ManagedAttribute(description="The file path for the store")
public String getFilePath()

getCache

public Map<String,Object> getCache()

setCache

public void setCache(Map<String,Object> cache)

getMaxFileStoreSize

@ManagedAttribute(description="The maximum file size for the file store in bytes")
public long getMaxFileStoreSize()

setMaxFileStoreSize

@ManagedAttribute(description="The maximum file size for the file store in bytes")
public void setMaxFileStoreSize(long maxFileStoreSize)
Sets the maximum file size for the file store in bytes.

The default is 1mb.


setCacheSize

public void setCacheSize(int size)
Sets the cache size


getCacheSize

@ManagedAttribute(description="The current cache size")
public int getCacheSize()

reset

@ManagedOperation(description="Reset and reloads the file store")
public void reset()
Reset and clears the store to force it to reload from file


appendToStore

protected void appendToStore(String messageId)
Appends the given message id to the file store

Parameters:
messageId - the message id

trunkStore

protected void trunkStore()
Trunks the file store when the max store size is hit by rewriting the 1st level cache to the file store.


loadStore

protected void loadStore()
Loads the given file store into the 1st level cache


doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()


Apache CAMEL