@ManagedResource(description="File based state repository") public class FileStateRepository extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.StateRepository<String,String>
FileStateRepository
class is a file-based implementation of a StateRepository
.Constructor and Description |
---|
FileStateRepository() |
FileStateRepository(File fileStore,
Map<String,String> cache) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart() |
protected void |
doStop() |
static FileStateRepository |
fileStateRepository(File fileStore)
Creates a new file based repository using as 1st level cache
|
static FileStateRepository |
fileStateRepository(File fileStore,
long maxFileStoreSize)
Creates a new file based repository using a
HashMap as 1st level cache. |
static FileStateRepository |
fileStateRepository(File store,
Map<String,String> cache)
Creates a new file based repository using the given
Map 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 cache
|
void |
reset()
Resets and clears the store to force it to reload from file
|
void |
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.
|
build, doBuild, doInit, doResume, doShutdown, doSuspend, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public static FileStateRepository fileStateRepository(File fileStore)
fileStore
- the file storepublic static FileStateRepository fileStateRepository(File fileStore, long maxFileStoreSize)
HashMap
as 1st level cache.fileStore
- the file storemaxFileStoreSize
- the max size in bytes for the fileStore filepublic static FileStateRepository fileStateRepository(File store, Map<String,String> cache)
Map
as 1st level cache.
Care should be taken to use a suitable underlying Map
to avoid this class being a
memory leak.store
- the file storecache
- the cache to use as 1st level cache@ManagedOperation(description="Adds the value of the given key to the store") public void setState(String key, String value)
@ManagedOperation(description="Gets the value of the given key from store") public String getState(String key)
@ManagedOperation(description="Reset and reloads the file store") public void reset() throws IOException
IOException
protected void trunkStore()
protected void loadStore() throws IOException
IOException
protected void doStart() throws Exception
doStart
in class org.apache.camel.support.service.ServiceSupport
Exception
protected void doStop() throws Exception
doStop
in class org.apache.camel.support.service.ServiceSupport
Exception
public File getFileStore()
public void setFileStore(File fileStore)
@ManagedAttribute(description="The file path for the store") public String getFilePath()
@ManagedAttribute(description="The maximum file size for the file store in bytes") public long getMaxFileStoreSize()
@ManagedAttribute(description="The maximum file size for the file store in bytes") public void setMaxFileStoreSize(long maxFileStoreSize)
Apache Camel