@ManagedResource(description="File based state repository") public class FileStateRepository extends ServiceSupport implements StateRepository<String,String>
FileStateRepository class is a file-based implementation of a StateRepository.shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending| Constructor and Description |
|---|
FileStateRepository() |
FileStateRepository(File fileStore,
Map<String,String> cache) |
| Modifier and Type | Method and Description |
|---|---|
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 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)
Gets the state value for the given 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)
Sets the state value for the given key.
|
protected void |
trunkStore()
Trunks the file store when the max store size is hit by rewriting the 1st level cache
to the file store.
|
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendpublic FileStateRepository()
public FileStateRepository(File fileStore, Map<String,String> cache)
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)
StateRepositorysetState in interface StateRepository<String,String>key - State keyvalue - State value@ManagedOperation(description="Gets the value of the given key from store") public String getState(String key)
StateRepositorynull if the key is unknown.getState in interface StateRepository<String,String>key - State key@ManagedOperation(description="Reset and reloads the file store") public void reset() throws IOException
IOExceptionprotected void trunkStore()
protected void loadStore() throws IOException
IOExceptionprotected void doStart() throws Exception
ServiceSupportServiceSupport.doStop() for more details.doStart in class ServiceSupportExceptionServiceSupport.doStop()protected void doStop() throws Exception
ServiceSupportServiceSupport.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.doStop in class ServiceSupportExceptionServiceSupport.doStart()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