Class FileIdempotentRepository
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.processor.idempotent.FileIdempotentRepository
-
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.IdempotentRepository,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
@ManagedResource(description="File based idempotent repository") public class FileIdempotentRepository extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.IdempotentRepositoryA file based implementation ofIdempotentRepository. This implementation provides a 1st-level in-memoryLRUCachefor fast check of the most frequently used keys. Whenadd(String)orcontains(String)methods are being used then in case of 1st-level cache miss, the underlying file is scanned which may cost additional performance. So try to find the right balance of the size of the 1st-level cache, the default size is 1000. The file store has a maximum capacity of 32mb by default (you can turn this off and have unlimited size). If the file store grows bigger than the maximum capacity, then thegetDropOldestFileStore()(is default 1000) number of entries from the file store is dropped to reduce the file store and make room for newer entries.
-
-
Constructor Summary
Constructors Constructor Description FileIdempotentRepository()FileIdempotentRepository(File fileStore, Map<String,Object> set)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(String key)protected voidappendToStore(String key)Appends the given key to the file storeprotected voidcleanup()Cleanup the 1st-level cache.voidclear()protected voidclearStore()Clears the file-store (danger this deletes all entries)booleanconfirm(String key)booleancontains(String key)protected booleancontainsStore(String key)Checks the file store if the key existsprotected voiddoStart()protected voiddoStop()static org.apache.camel.spi.IdempotentRepositoryfileIdempotentRepository(File fileStore)Creates a new file based repository using aLRUCacheas 1st level cache with a default of 1000 entries in the cache.static org.apache.camel.spi.IdempotentRepositoryfileIdempotentRepository(File fileStore, int cacheSize)Creates a new file based repository using aLRUCacheas 1st level cache.static org.apache.camel.spi.IdempotentRepositoryfileIdempotentRepository(File fileStore, int cacheSize, long maxFileStoreSize)Creates a new file based repository using aLRUCacheas 1st level cache.static org.apache.camel.spi.IdempotentRepositoryfileIdempotentRepository(File store, Map<String,Object> cache)Creates a new file based repository using the givenMapas 1st level cache.Map<String,Object>getCache()intgetCacheSize()longgetDropOldestFileStore()StringgetFilePath()FilegetFileStore()longgetMaxFileStoreSize()protected voidloadStore()Loads the given file store into the 1st level cachebooleanremove(String key)protected voidremoveFromStore(String key)voidreset()Reset and clears the 1st-level cache to force it to reload from filevoidsetCache(Map<String,Object> cache)voidsetCacheSize(int size)Sets the 1st-level cache size.voidsetDropOldestFileStore(long dropOldestFileStore)Sets the number of oldest entries to drop from the file store when the maximum capacity is hit to reduce disk space to allow room for new entries.voidsetFileStore(File fileStore)voidsetMaxFileStoreSize(long maxFileStoreSize)Sets the maximum file size for the file store in bytes.protected voidtrunkStore()Trunks the file store when the max store size is hit by dropping the most oldest entries.-
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.camel.spi.IdempotentRepository
add, confirm, contains, remove
-
-
-
-
Method Detail
-
fileIdempotentRepository
public static org.apache.camel.spi.IdempotentRepository fileIdempotentRepository(File fileStore)
Creates a new file based repository using aLRUCacheas 1st level cache with a default of 1000 entries in the cache.- Parameters:
fileStore- the file store
-
fileIdempotentRepository
public static org.apache.camel.spi.IdempotentRepository fileIdempotentRepository(File fileStore, int cacheSize)
Creates a new file based repository using aLRUCacheas 1st level cache.- Parameters:
fileStore- the file storecacheSize- the cache size
-
fileIdempotentRepository
public static org.apache.camel.spi.IdempotentRepository fileIdempotentRepository(File fileStore, int cacheSize, long maxFileStoreSize)
Creates a new file based repository using aLRUCacheas 1st level cache.- Parameters:
fileStore- the file storecacheSize- the cache sizemaxFileStoreSize- the max size in bytes for the filestore file
-
fileIdempotentRepository
public static org.apache.camel.spi.IdempotentRepository fileIdempotentRepository(File store, Map<String,Object> cache)
Creates a new file based repository using the givenMapas 1st level cache. Care should be taken to use a suitable underlyingMapto avoid this class being a memory leak.- Parameters:
store- the file storecache- the cache to use as 1st level cache
-
add
@ManagedOperation(description="Adds the key to the store") public boolean add(String key)
- Specified by:
addin interfaceorg.apache.camel.spi.IdempotentRepository
-
contains
@ManagedOperation(description="Does the store contain the given key") public boolean contains(String key)
- Specified by:
containsin interfaceorg.apache.camel.spi.IdempotentRepository
-
remove
@ManagedOperation(description="Remove the key from the store") public boolean remove(String key)
- Specified by:
removein interfaceorg.apache.camel.spi.IdempotentRepository
-
confirm
public boolean confirm(String key)
- Specified by:
confirmin interfaceorg.apache.camel.spi.IdempotentRepository
-
clear
@ManagedOperation(description="Clear the store (danger this removes all entries)") public void clear()
- Specified by:
clearin interfaceorg.apache.camel.spi.IdempotentRepository
-
getFileStore
public File getFileStore()
-
setFileStore
public void setFileStore(File fileStore)
-
getFilePath
@ManagedAttribute(description="The file path for the store") public String getFilePath()
-
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. You can set the value to 0 or negative to turn this off, and have unlimited file store size. The default is 32mb.
-
getDropOldestFileStore
public long getDropOldestFileStore()
-
setDropOldestFileStore
@ManagedAttribute(description="Number of oldest elements to drop from file store if maximum file size reached") public void setDropOldestFileStore(long dropOldestFileStore)
Sets the number of oldest entries to drop from the file store when the maximum capacity is hit to reduce disk space to allow room for new entries. The default is 1000.
-
setCacheSize
public void setCacheSize(int size)
Sets the 1st-level cache size. Setting cache size is only possible when using the defaultLRUCachecache implementation.
-
getCacheSize
@ManagedAttribute(description="The current 1st-level cache size") public int getCacheSize()
-
reset
@ManagedOperation(description="Reset and reloads the file store") public void reset() throws IOExceptionReset and clears the 1st-level cache to force it to reload from file- Throws:
IOException
-
containsStore
protected boolean containsStore(String key)
Checks the file store if the key exists- Parameters:
key- the key- Returns:
- true if exists in the file, false otherwise
-
appendToStore
protected void appendToStore(String key)
Appends the given key to the file store- Parameters:
key- the key
-
removeFromStore
protected void removeFromStore(String key)
-
clearStore
protected void clearStore()
Clears the file-store (danger this deletes all entries)
-
trunkStore
protected void trunkStore()
Trunks the file store when the max store size is hit by dropping the most oldest entries.
-
cleanup
protected void cleanup()
Cleanup the 1st-level cache.
-
loadStore
protected void loadStore() throws IOExceptionLoads the given file store into the 1st level cache- Throws:
IOException
-
doStart
protected void doStart() throws Exception- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
-