Class StorerModeController
java.lang.Object
one.microstream.persistence.types.StorerModeController
- All Implemented Interfaces:
PersistenceStorerDeactivatableRegistry
public class StorerModeController extends Object implements PersistenceStorerDeactivatableRegistry
The StorerModeController provides API to control the write mode of
registered PersistenceStorer implementations from a central instance.
Storers are register with
As this class starts an internal thread use the
Usage:
Storers are register with
register(PersistenceStorerDeactivatable).
They will be registers using WeakReferences. That will be checked and
cleaned up periodically.
As this class starts an internal thread use the
shutdown() call to speed up
termination. Otherwise the internal thread will run until all registered stores
are disposed by the JVMs garbage collector.
Usage:
final StorerModeController storerModeController = new StorerModeController();
final EmbeddedStorageManager storage = EmbeddedStorage
.Foundation()
.onConnectionFoundation(connectionFoundation ->
connectionFoundation.setStorerCreator(
PersistenceStorerCreatorDeactivatable.New(
connectionFoundation,
storerModeController)))
.start();
storerModeController.disableWriting();
assertThrows(PersistenceExceptionStorerDeactivated.class,
() -> storage.store("Hello World"));
-
Constructor Summary
Constructors Constructor Description StorerModeController() -
Method Summary
Modifier and Type Method Description voidclean()Cleanup all no more valid (garbage collected) Storer instances.voiddisableWrites()Switch all registered storers to the read only mode.voidenableWrites()Switch all registered storers to the writing mode.booleanhasRegisteredStorers()Returns true if there are any registered PersistenceStorerDeactivatable instances.booleanisActive()Returns the state of this StorerModeController.booleanisWriteEnabled()Gets the current state if writing is allowed or not.PersistenceStorerDeactivatableregister(PersistenceStorerDeactivatable deactivatableStorer)Register a PersistenceStorerDeactivatable instance to the StorerModeController.voidsetWriteEnabled(boolean enableWrites)Enable or disable writing support for all registered storers.voidshutdown()Shutdown this StorerModeController.
-
Constructor Details
-
StorerModeController
public StorerModeController()
-
-
Method Details
-
isActive
public boolean isActive()Returns the state of this StorerModeController.- Returns:
- true if not shut down.
-
shutdown
public void shutdown()Shutdown this StorerModeController. -
setWriteEnabled
public void setWriteEnabled(boolean enableWrites)Enable or disable writing support for all registered storers.- Parameters:
enableWrites- true to enable writing, false to disable.
-
isWriteEnabled
public boolean isWriteEnabled()Gets the current state if writing is allowed or not.- Returns:
- true if writing is allowed, otherwise false.
-
enableWrites
public void enableWrites()Switch all registered storers to the writing mode. -
disableWrites
public void disableWrites()Switch all registered storers to the read only mode. -
register
Description copied from interface:PersistenceStorerDeactivatableRegistryRegister a PersistenceStorerDeactivatable instance to the StorerModeController.- Specified by:
registerin interfacePersistenceStorerDeactivatableRegistry- Parameters:
deactivatableStorer- the PersistenceStorerDeactivatable to be registered.- Returns:
- the registered instance.
-
hasRegisteredStorers
public boolean hasRegisteredStorers()Description copied from interface:PersistenceStorerDeactivatableRegistryReturns true if there are any registered PersistenceStorerDeactivatable instances.- Specified by:
hasRegisteredStorersin interfacePersistenceStorerDeactivatableRegistry- Returns:
- true or false.
-
clean
public void clean()Description copied from interface:PersistenceStorerDeactivatableRegistryCleanup all no more valid (garbage collected) Storer instances.- Specified by:
cleanin interfacePersistenceStorerDeactivatableRegistry
-