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 void
clean()
Cleanup all no more valid (garbage collected) Storer instances.void
disableWrites()
Switch all registered storers to the read only mode.void
enableWrites()
Switch all registered storers to the writing mode.boolean
hasRegisteredStorers()
Returns true if there are any registered PersistenceStorerDeactivatable instances.boolean
isActive()
Returns the state of this StorerModeController.boolean
isWriteEnabled()
Gets the current state if writing is allowed or not.PersistenceStorerDeactivatable
register(PersistenceStorerDeactivatable deactivatableStorer)
Register a PersistenceStorerDeactivatable instance to the StorerModeController.void
setWriteEnabled(boolean enableWrites)
Enable or disable writing support for all registered storers.void
shutdown()
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:PersistenceStorerDeactivatableRegistry
Register a PersistenceStorerDeactivatable instance to the StorerModeController.- Specified by:
register
in interfacePersistenceStorerDeactivatableRegistry
- Parameters:
deactivatableStorer
- the PersistenceStorerDeactivatable to be registered.- Returns:
- the registered instance.
-
hasRegisteredStorers
public boolean hasRegisteredStorers()Description copied from interface:PersistenceStorerDeactivatableRegistry
Returns true if there are any registered PersistenceStorerDeactivatable instances.- Specified by:
hasRegisteredStorers
in interfacePersistenceStorerDeactivatableRegistry
- Returns:
- true or false.
-
clean
public void clean()Description copied from interface:PersistenceStorerDeactivatableRegistry
Cleanup all no more valid (garbage collected) Storer instances.- Specified by:
clean
in interfacePersistenceStorerDeactivatableRegistry
-