Class AbstractPersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Type Parameters:
PS
- the type of AbstractPersistentStore
- All Implemented Interfaces:
com.oracle.coherence.persistence.PersistenceManager<ReadBuffer>
- Author:
- jh 2012.10.04
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Abstract implementation of PersistenceTools which can be extended to support local snapshot operations for specific implementations.class
Abstract implementation of a ReadBuffer-based PersistentStore.protected static class
A collection of tasks to execute in a loop.class
Runnable extension that adds the ability to notify the task that it has been canceled.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected final File
The directory used to store persisted data.protected final File
The directory used to store lock files (to protect against multi-process file system clean up).protected final File
The directory used to store "safe-deleted" data.protected final ConcurrentMap
<String, PS> Map of open AbstractPersistentStore instances.protected final Set
<AbstractPersistenceManager<PS>.Task> Set of outstanding tasks.protected final String
The name of this AbstractPersistenceManager.protected AbstractPersistenceEnvironment
The environment that created this AbstractPersistenceManager.protected boolean
Whether this PersistenceManager has been released.protected com.tangosol.internal.util.DaemonPool
An optional DaemonPool used to execute tasks.protected static final long[]
An empty long array (by definition immutable).protected static final String[]
An empty String array (by definition immutable).protected static final int
The state of a PersistenceStore once it has been released and closed.protected static final int
The initial state of a PersistenceStore.protected static final int
The state of a PersistenceStore when it is in the process of being opened.protected static final int
The state of a PersistenceStore once it has been opened and is ready to process requests. -
Constructor Summary
ConstructorDescriptionAbstractPersistenceManager
(File fileData, File fileTrash, String sName) Create a new AbstractPersistenceManager. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addTask
(AbstractPersistenceManager<PS>.Task task) Add the provided task to the set of tasks.void
Close the associated PersistentStore and release exclusive access to the associated resources.boolean
Return the identifiers of the PersistentStores known to this manager.createStore
(String sId) Create aPersistentStore
associated with the specified identifier.boolean
Remove the PersistentStore associated with the specified identifier.protected void
Return control if this PersistenceManager is still active, otherwise throw an exception.protected com.oracle.coherence.persistence.PersistenceException
ensurePersistenceException
(Throwable eCause) Return a PersistenceException with the given cause.protected com.oracle.coherence.persistence.PersistenceException
ensurePersistenceException
(Throwable eCause, String sMessage) Return a PersistenceException with the given cause and detail message.protected File
Ensure trash directory is created.protected void
Execute the specified task with the calling thread.protected void
Execute the specified task with the calling thread.com.tangosol.internal.util.DaemonPool
Return the optional DaemonPool used to execute tasks.Return the directory used to store persisted data.protected abstract int
Return the implementation version of this manager.protected File
Return the directory used to store lock files.protected Properties
Return metadata for this manager.getName()
Return the name of this manager.protected AbstractPersistenceEnvironment
Return the environment that created this manager.com.oracle.coherence.persistence.PersistenceTools
Return an instance ofPersistenceTools
allowing offline operations to be performed against the associated PersistenceManager and appropriatePersistentStore
.Return the map of open PersistentStore instances keyed by their identifiers.protected abstract String
Return the storage format used by this manager.protected abstract int
Return the version of the storage format used by this manager.Return the directory used to store "safe-deleted" persisted data.protected abstract com.oracle.coherence.persistence.PersistenceTools
instantiatePersistenceTools
(com.oracle.coherence.persistence.OfflinePersistenceInfo info) Factory method to create aPersistenceTools
implementation.protected abstract PS
Factory method for PersistentStore implementations managed by this PersistenceManager.protected boolean
Determine if the given metadata is compatible with this manager.protected boolean
isMetadataComplete
(Properties prop) Determine if the given metadata in theProperties
is complete.String[]
list()
Return the identifiers of the PersistentStores known to this manager.String[]
listOpen()
Return the identifiers of PersistentStores that are currently open.com.oracle.coherence.persistence.PersistentStore
<ReadBuffer> open
(String sId, com.oracle.coherence.persistence.PersistentStore<ReadBuffer> storeFrom) Open or create aPersistentStore
associated with the specified identifier and based on the providedstore
.com.oracle.coherence.persistence.PersistentStore
<ReadBuffer> open
(String sId, com.oracle.coherence.persistence.PersistentStore<ReadBuffer> storeFrom, Collector<Object> collector) Open or create aPersistentStore
associated with the specified identifier and based on the providedstore
.void
read
(String sId, ReadBuffer.BufferInput in) Read the PersistenceStore associated with the specified identifier from the given input stream, making it available to this manager.protected Properties
readMetadata
(File fileDir) Read persistence metadata from the specified directory.void
release()
Release all resources held by this manager.void
setDaemonPool
(com.tangosol.internal.util.DaemonPool pool) Configure the DaemonPool used to execute tasks.protected void
Configure the environment that created this manager.protected void
Submit the given task for execution by the daemon pool.protected void
submitTasks
(List<? extends AbstractPersistenceManager<PS>.Task> listTasks) Submit the provided list of tasks for execution to the pool or execute directly.toString()
Return a human readable description of this AbstractPersistenceManager.Validate that the given identifier can be used for a persistent store.void
write
(String sId, WriteBuffer.BufferOutput out) Write the PersistentStore associated with the specified identifier to the given output buffer.protected void
writeMetadata
(File fileDir) Write persistence metadata for this manager to the specified directory.void
Copy the PersistentStore associated with the specified identifier to the configured safe area.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.oracle.coherence.persistence.PersistenceManager
read, write
-
Field Details
-
NO_LONGS
protected static final long[] NO_LONGSAn empty long array (by definition immutable). -
NO_STRINGS
An empty String array (by definition immutable). -
STORE_STATE_INITIALIZED
protected static final int STORE_STATE_INITIALIZEDThe initial state of a PersistenceStore.- See Also:
-
STORE_STATE_OPENING
protected static final int STORE_STATE_OPENINGThe state of a PersistenceStore when it is in the process of being opened.- See Also:
-
STORE_STATE_READY
protected static final int STORE_STATE_READYThe state of a PersistenceStore once it has been opened and is ready to process requests.- See Also:
-
STORE_STATE_CLOSED
protected static final int STORE_STATE_CLOSEDThe state of a PersistenceStore once it has been released and closed.- See Also:
-
f_dirData
The directory used to store persisted data. -
f_dirTrash
The directory used to store "safe-deleted" data. -
f_dirLock
The directory used to store lock files (to protect against multi-process file system clean up). -
f_sName
The name of this AbstractPersistenceManager. -
f_mapStores
protected final ConcurrentMap<String,PS extends AbstractPersistenceManager.AbstractPersistentStore> f_mapStoresMap of open AbstractPersistentStore instances. -
f_setTasks
protected final Set<AbstractPersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>.Task> f_setTasksSet of outstanding tasks. -
m_fReleased
protected volatile boolean m_fReleasedWhether this PersistenceManager has been released. -
m_env
The environment that created this AbstractPersistenceManager. -
m_pool
protected com.tangosol.internal.util.DaemonPool m_poolAn optional DaemonPool used to execute tasks.
-
-
Constructor Details
-
AbstractPersistenceManager
Create a new AbstractPersistenceManager.- Parameters:
fileData
- the directory used to store persisted datafileTrash
- an optional trash directorysName
- an optional name to give the new manager- Throws:
IOException
- on error creating the data or trash directory
-
-
Method Details
-
getName
Return the name of this manager.- Specified by:
getName
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- the name of this manager
-
createStore
Create aPersistentStore
associated with the specified identifier.Creation of a store suggests its registration but has no usage until it transitions into a state of open. The implementation may choose to forgo any resource allocation until the caller
opens
the same identifier.- Specified by:
createStore
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier of the store- Returns:
- a persistent store
-
open
public com.oracle.coherence.persistence.PersistentStore<ReadBuffer> open(String sId, com.oracle.coherence.persistence.PersistentStore<ReadBuffer> storeFrom) Open or create aPersistentStore
associated with the specified identifier and based on the providedstore
.Upon a new store being created the provided store should be used as the basis for the new store such that the extents and associated data is available in the returned store. This provides an opportunity for an implementation to optimize initializing the new store based upon knowledge of the storage mechanics.
- Specified by:
open
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier for the storestoreFrom
- the PersistenceStore the new store should be based upon- Returns:
- a PersistentStore associated with the specified identifier
-
open
public com.oracle.coherence.persistence.PersistentStore<ReadBuffer> open(String sId, com.oracle.coherence.persistence.PersistentStore<ReadBuffer> storeFrom, Collector<Object> collector) Open or create aPersistentStore
associated with the specified identifier and based on the providedstore
.Upon a new store being created the provided store should be used as the basis for the new store such that the extents and associated data is available in the returned store. This provides an opportunity for an implementation to optimize initializing the new store based upon knowledge of the storage mechanics.
Providing a
Collector
allows the open operation to be performed asynchronously. This may be desirable when the calling thread can not be blocked on IO operations that are required when creating a new store based on an old store (storeFrom
). Open is only non-blocking when both an old store and a Collector are provided. Upon completion of an asynchronous open request the provided Collector is called with either a String (GUID) or an AsyncPersistenceException, thus notifying the collector of success of failure respectively.Note: the behavior of a returned store that has not been opened is undefined.
- Specified by:
open
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier for the storestoreFrom
- the PersistenceStore the new store should be based uponcollector
- the Collector to notify once the store has been opened or failed to open; the collector will either receive a String (GUID) or an AsyncPersistenceException- Returns:
- a PersistentStore associated with the specified identifier
-
close
Close the associated PersistentStore and release exclusive access to the associated resources.- Specified by:
close
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier of the store to close
-
delete
Remove the PersistentStore associated with the specified identifier.- Specified by:
delete
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier of the store to removefSafe
- if true, remove the store by moving it to a restorable location (if possible) rather than deleting it- Returns:
- true if the store was successfully removed, false otherwise
-
list
Return the identifiers of the PersistentStores known to this manager.- Specified by:
list
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- a list of the known store identifiers
-
contains
Description copied from interface:com.oracle.coherence.persistence.PersistenceManager
Return the identifiers of the PersistentStores known to this manager.- Specified by:
contains
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- a list of the known store identifiers
-
listOpen
Return the identifiers of PersistentStores that are currently open.- Specified by:
listOpen
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- a list of the open store identifiers
-
read
Read the PersistenceStore associated with the specified identifier from the given input stream, making it available to this manager.- Specified by:
read
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier of the store to readin
- the stream to read from- Throws:
IOException
- if an error occurred while reading from the stream
-
write
Write the PersistentStore associated with the specified identifier to the given output buffer.- Specified by:
write
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Parameters:
sId
- a unique identifier of the store to writeout
- the output buffer to write to- Throws:
IOException
- if an error occurred while writing to the stream
-
release
public void release()Release all resources held by this manager. Note that the behavior of all other methods on this manager is undefined after this method is called.- Specified by:
release
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
-
getPersistenceTools
public com.oracle.coherence.persistence.PersistenceTools getPersistenceTools()Description copied from interface:com.oracle.coherence.persistence.PersistenceManager
Return an instance ofPersistenceTools
allowing offline operations to be performed against the associated PersistenceManager and appropriatePersistentStore
.- Specified by:
getPersistenceTools
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- a PersistenceTools implementation
-
writeSafe
Copy the PersistentStore associated with the specified identifier to the configured safe area.- Specified by:
writeSafe
in interfacecom.oracle.coherence.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
-
toString
Return a human readable description of this AbstractPersistenceManager. -
getMetadata
Return metadata for this manager.- Returns:
- the metadata for this manager
-
readMetadata
Read persistence metadata from the specified directory.- Parameters:
fileDir
- the directory to read metadata from- Returns:
- the metadata
- Throws:
IOException
- on error reading the metadata file
-
writeMetadata
Write persistence metadata for this manager to the specified directory.- Parameters:
fileDir
- the directory to write metadata to- Throws:
IOException
- on error writing the metadata file
-
isMetadataComplete
Determine if the given metadata in theProperties
is complete.- Parameters:
prop
- the metadata to analyze- Returns:
- true if the given metadata is complete; false otherwise
-
isMetadataCompatible
Determine if the given metadata is compatible with this manager.- Parameters:
prop
- the metadata to analyze- Returns:
- true if the given metadata is compatible with this manager; false otherwise
-
getImplVersion
protected abstract int getImplVersion()Return the implementation version of this manager.- Returns:
- the implementation version of this manager
-
getStorageFormat
Return the storage format used by this manager.- Returns:
- the storage format used by this manager
-
getStorageVersion
protected abstract int getStorageVersion()Return the version of the storage format used by this manager.- Returns:
- the version of the storage format used by this manager
-
ensurePersistenceException
protected com.oracle.coherence.persistence.PersistenceException ensurePersistenceException(Throwable eCause) Return a PersistenceException with the given cause. The returned exception is also initialized with this manager and its environment (if available).- Parameters:
eCause
- an optional cause- Returns:
- a PersistenceException with the given cause
-
ensurePersistenceException
protected com.oracle.coherence.persistence.PersistenceException ensurePersistenceException(Throwable eCause, String sMessage) Return a PersistenceException with the given cause and detail message. The returned exception is also initialized with this manager and its environment (if available).- Parameters:
eCause
- an optional causesMessage
- an optional detail message- Returns:
- a PersistenceException with the given cause and detail message
-
ensureActive
protected void ensureActive()Return control if this PersistenceManager is still active, otherwise throw an exception.- Throws:
IllegalStateException
- if this PersistenceManager has been released
-
ensureTrashDir
Ensure trash directory is created.- Returns:
- the configured trash directory
- Throws:
IOException
-
submitTasks
Submit the provided list of tasks for execution to the pool or execute directly.- Parameters:
listTasks
- the tasks to execute
-
validatePersistentStoreId
Validate that the given identifier can be used for a persistent store.- Parameters:
sId
- the identifier to check- Returns:
- the validated identifier
-
submitTask
Submit the given task for execution by the daemon pool.- Parameters:
task
- the task to submit
-
addTask
Add the provided task to the set of tasks.- Parameters:
task
- the task to add
-
executeTask
Execute the specified task with the calling thread.- Parameters:
task
- the task to execute
-
executeTaskExclusive
Execute the specified task with the calling thread. No other access to this manager or any of its persistent stores is guaranteed to occur while the task is being executed.- Parameters:
task
- the task to execute
-
instantiatePersistentStore
Factory method for PersistentStore implementations managed by this PersistenceManager.- Parameters:
sId
- the identifier of the store to create- Returns:
- a new AbstractPersistentStore with the given identifier
-
instantiatePersistenceTools
protected abstract com.oracle.coherence.persistence.PersistenceTools instantiatePersistenceTools(com.oracle.coherence.persistence.OfflinePersistenceInfo info) Factory method to create aPersistenceTools
implementation.- Parameters:
info
- theOfflinePersistenceInfo
relevant to the PersistenceTools- Returns:
- a new PersistenceTools implementation
-
getDaemonPool
public com.tangosol.internal.util.DaemonPool getDaemonPool()Return the optional DaemonPool used to execute tasks.- Returns:
- the DaemonPool or null if one hasn't been configured
-
setDaemonPool
public void setDaemonPool(com.tangosol.internal.util.DaemonPool pool) Configure the DaemonPool used to execute tasks.- Parameters:
pool
- the DaemonPool
-
getDataDirectory
Return the directory used to store persisted data.- Returns:
- the data storage directory
-
getTrashDirectory
Return the directory used to store "safe-deleted" persisted data.- Returns:
- the trash storage directory
-
getLockDirectory
Return the directory used to store lock files.- Returns:
- the directory used to store lock files
-
getPersistenceEnvironment
Return the environment that created this manager.- Returns:
- the environment that created this manager
-
setPersistenceEnvironment
Configure the environment that created this manager.- Parameters:
env
- the environment that created this manager
-
getPersistentStoreMap
Return the map of open PersistentStore instances keyed by their identifiers.Note: The return map is "live". Any attempt to access or mutate it should be done while holding a monitor on this manager.
- Returns:
- the map of open PersistentStore instances
-