Package org.apache.camel.impl.engine
Class FileStateRepository
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.impl.engine.FileStateRepository
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.StateRepository<String,String>
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@ManagedResource(description="File based state repository") public class FileStateRepository extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.StateRepository<String,String>
ThisFileStateRepository
class is a file-based implementation of aStateRepository
.
-
-
Constructor Summary
Constructors Constructor Description FileStateRepository()
FileStateRepository(File fileStore, Map<String,String> cache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doStart()
protected void
doStop()
static FileStateRepository
fileStateRepository(File fileStore)
Creates a new file based repository using as 1st level cachestatic FileStateRepository
fileStateRepository(File fileStore, long maxFileStoreSize)
Creates a new file based repository using aHashMap
as 1st level cache.static FileStateRepository
fileStateRepository(File store, Map<String,String> cache)
Creates a new file based repository using the givenMap
as 1st level cache.Map<String,String>
getCache()
String
getFilePath()
File
getFileStore()
long
getMaxFileStoreSize()
String
getState(String key)
protected void
loadStore()
Loads the given file store into the 1st level cachevoid
reset()
Resets and clears the store to force it to reload from filevoid
setCache(Map<String,String> cache)
void
setFileStore(File fileStore)
void
setMaxFileStoreSize(long maxFileStoreSize)
Sets the maximum file size for the file store in bytes.void
setState(String key, String value)
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.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
-
-
-
-
Method Detail
-
fileStateRepository
public static FileStateRepository fileStateRepository(File fileStore)
Creates a new file based repository using as 1st level cache- Parameters:
fileStore
- the file store
-
fileStateRepository
public static FileStateRepository fileStateRepository(File fileStore, long maxFileStoreSize)
Creates a new file based repository using aHashMap
as 1st level cache.- Parameters:
fileStore
- the file storemaxFileStoreSize
- the max size in bytes for the fileStore file
-
fileStateRepository
public static FileStateRepository fileStateRepository(File store, Map<String,String> cache)
Creates a new file based repository using the givenMap
as 1st level cache. Care should be taken to use a suitable underlyingMap
to avoid this class being a memory leak.- Parameters:
store
- the file storecache
- the cache to use as 1st level cache
-
setState
@ManagedOperation(description="Adds the value of the given key to the store") public void setState(String key, String value)
-
getState
@ManagedOperation(description="Gets the value of the given key from store") public String getState(String key)
-
reset
@ManagedOperation(description="Reset and reloads the file store") public void reset() throws IOException
Resets and clears the store to force it to reload from file- Throws:
IOException
-
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() throws IOException
Loads the given file store into the 1st level cache- Throws:
IOException
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
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. The default is 1mb.
-
-