Class AbstractPersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.persistence.AbstractPersistenceManager<PS>
-
- Type Parameters:
PS
- the type of AbstractPersistentStore
- All Implemented Interfaces:
com.oracle.coherence.persistence.PersistenceManager<ReadBuffer>
,com.oracle.datagrid.persistence.PersistenceManager<ReadBuffer>
public abstract class AbstractPersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore> extends Base implements com.oracle.datagrid.persistence.PersistenceManager<ReadBuffer>
Abstract implementation of a ReadBuffer-based PersistentManager.- Author:
- jh 2012.10.04
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractPersistenceManager.AbstractPersistenceSnapshotTools
Abstract implementation of PersistenceTools which can be extended to support local snapshot operations for specific implementations.class
AbstractPersistenceManager.AbstractPersistentStore
Abstract implementation of a ReadBuffer-based PersistentStore.protected static class
AbstractPersistenceManager.BatchTasks
A collection of tasks to execute in a loop.class
AbstractPersistenceManager.Task
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
Fields Modifier and Type Field Description protected File
f_dirData
The directory used to store persisted data.protected File
f_dirLock
The directory used to store lock files (to protect against multi-process file system clean up).protected File
f_dirTrash
The directory used to store "safe-deleted" data.protected ConcurrentMap<String,PS>
f_mapStores
Map of open AbstractPersistentStore instances.protected Set<AbstractPersistenceManager.Task>
f_setTasks
Set of outstanding tasks.protected String
f_sName
The name of this AbstractPersistenceManager.protected AbstractPersistenceEnvironment
m_env
The environment that created this AbstractPersistenceManager.protected boolean
m_fReleased
Whether this PersistenceManager has been released.protected com.tangosol.internal.util.DaemonPool
m_pool
An optional DaemonPool used to execute tasks.protected static long[]
NO_LONGS
An empty long array (by definition immutable).protected static String[]
NO_STRINGS
An empty String array (by definition immutable).protected static int
STORE_STATE_CLOSED
The state of a PersistenceStore once it has been released and closed.protected static int
STORE_STATE_INITIALIZED
The initial state of a PersistenceStore.protected static int
STORE_STATE_OPENING
The state of a PersistenceStore when it is in the process of being opened.protected static int
STORE_STATE_READY
The state of a PersistenceStore once it has been opened and is ready to process requests.
-
Constructor Summary
Constructors Constructor Description AbstractPersistenceManager(File fileData, File fileTrash, String sName)
Create a new AbstractPersistenceManager.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addTask(AbstractPersistenceManager.Task task)
Add the provided task to the set of tasks.void
close(String sId)
Close the associated PersistentStore and release exclusive access to the associated resources.boolean
contains(String sGUID)
Return the identifiers of the PersistentStores known to this manager.PS
createStore(String sId)
Create aPersistentStore
associated with the specified identifier.boolean
delete(String sId, boolean fSafe)
Remove the PersistentStore associated with the specified identifier.protected void
ensureActive()
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
ensureTrashDir()
Ensure trash directory is created.protected void
executeTask(AbstractPersistenceManager.Task task)
Execute the specified task with the calling thread.protected void
executeTaskExclusive(AbstractPersistenceManager.Task task)
Execute the specified task with the calling thread.com.tangosol.internal.util.DaemonPool
getDaemonPool()
Return the optional DaemonPool used to execute tasks.File
getDataDirectory()
Return the directory used to store persisted data.protected abstract int
getImplVersion()
Return the implementation version of this manager.protected File
getLockDirectory()
Return the directory used to store lock files.protected Properties
getMetadata()
Return metadata for this manager.String
getName()
Return the name of this manager.protected AbstractPersistenceEnvironment
getPersistenceEnvironment()
Return the environment that created this manager.com.oracle.datagrid.persistence.PersistenceTools
getPersistenceTools()
Return an instance ofPersistenceTools
allowing offline operations to be performed against the associated PersistenceManager and appropriatePersistentStore
.Map<String,PS>
getPersistentStoreMap()
Return the map of open PersistentStore instances keyed by their identifiers.protected abstract String
getStorageFormat()
Return the storage format used by this manager.protected abstract int
getStorageVersion()
Return the version of the storage format used by this manager.File
getTrashDirectory()
Return the directory used to store "safe-deleted" persisted data.protected abstract com.oracle.datagrid.persistence.PersistenceTools
instantiatePersistenceTools(com.oracle.datagrid.persistence.OfflinePersistenceInfo info)
Factory method to create aPersistenceTools
implementation.protected abstract PS
instantiatePersistentStore(String sId)
Factory method for PersistentStore implementations managed by this PersistenceManager.protected boolean
isMetadataCompatible(Properties prop)
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
setPersistenceEnvironment(AbstractPersistenceEnvironment env)
Configure the environment that created this manager.protected void
submitTask(AbstractPersistenceManager.Task task)
Submit the given task for execution by the daemon pool.protected void
submitTasks(List<? extends AbstractPersistenceManager.Task> listTasks)
Submit the provided list of tasks for execution to the pool or execute directly.String
toString()
Return a human readable description of this AbstractPersistenceManager.String
validatePersistentStoreId(String sId)
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
writeSafe(String sId)
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
-
-
-
-
Field Detail
-
NO_LONGS
protected static final long[] NO_LONGS
An empty long array (by definition immutable).
-
NO_STRINGS
protected static final String[] NO_STRINGS
An empty String array (by definition immutable).
-
STORE_STATE_INITIALIZED
protected static final int STORE_STATE_INITIALIZED
The initial state of a PersistenceStore.- See Also:
- Constant Field Values
-
STORE_STATE_OPENING
protected static final int STORE_STATE_OPENING
The state of a PersistenceStore when it is in the process of being opened.- See Also:
- Constant Field Values
-
STORE_STATE_READY
protected static final int STORE_STATE_READY
The state of a PersistenceStore once it has been opened and is ready to process requests.- See Also:
- Constant Field Values
-
STORE_STATE_CLOSED
protected static final int STORE_STATE_CLOSED
The state of a PersistenceStore once it has been released and closed.- See Also:
- Constant Field Values
-
f_dirData
protected final File f_dirData
The directory used to store persisted data.
-
f_dirTrash
protected final File f_dirTrash
The directory used to store "safe-deleted" data.
-
f_dirLock
protected final File f_dirLock
The directory used to store lock files (to protect against multi-process file system clean up).
-
f_sName
protected final String f_sName
The name of this AbstractPersistenceManager.
-
f_mapStores
protected final ConcurrentMap<String,PS extends AbstractPersistenceManager.AbstractPersistentStore> f_mapStores
Map of open AbstractPersistentStore instances.
-
f_setTasks
protected final Set<AbstractPersistenceManager.Task> f_setTasks
Set of outstanding tasks.
-
m_fReleased
protected volatile boolean m_fReleased
Whether this PersistenceManager has been released.
-
m_env
protected AbstractPersistenceEnvironment m_env
The environment that created this AbstractPersistenceManager.
-
m_pool
protected com.tangosol.internal.util.DaemonPool m_pool
An optional DaemonPool used to execute tasks.
-
-
Constructor Detail
-
AbstractPersistenceManager
public AbstractPersistenceManager(File fileData, File fileTrash, String sName) throws IOException
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 Detail
-
getName
public String 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
public PS createStore(String sId)
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
public void close(String sId)
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
public boolean delete(String sId, boolean fSafe)
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
public String[] 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
public boolean contains(String sGUID)
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
public String[] 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
public void read(String sId, ReadBuffer.BufferInput in) throws IOException
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
public void write(String sId, WriteBuffer.BufferOutput out) throws IOException
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.datagrid.persistence.PersistenceTools getPersistenceTools()
Description copied from interface:com.oracle.datagrid.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>
- Specified by:
getPersistenceTools
in interfacecom.oracle.datagrid.persistence.PersistenceManager<PS extends AbstractPersistenceManager.AbstractPersistentStore>
- Returns:
- a PersistenceTools implementation
-
writeSafe
public void writeSafe(String sId)
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
public String toString()
Return a human readable description of this AbstractPersistenceManager.
-
getMetadata
protected Properties getMetadata()
Return metadata for this manager.- Returns:
- the metadata for this manager
-
readMetadata
protected Properties readMetadata(File fileDir) throws IOException
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
protected void writeMetadata(File fileDir) throws IOException
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
protected boolean isMetadataComplete(Properties prop)
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
protected boolean isMetadataCompatible(Properties prop)
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
protected abstract String 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
protected File ensureTrashDir() throws IOException
Ensure trash directory is created.- Returns:
- the configured trash directory
- Throws:
IOException
-
submitTasks
protected void submitTasks(List<? extends AbstractPersistenceManager.Task> listTasks)
Submit the provided list of tasks for execution to the pool or execute directly.- Parameters:
listTasks
- the tasks to execute
-
validatePersistentStoreId
public String validatePersistentStoreId(String sId)
Validate that the given identifier can be used for a persistent store.- Parameters:
sId
- the identifier to check- Returns:
- the validated identifier
-
submitTask
protected void submitTask(AbstractPersistenceManager.Task task)
Submit the given task for execution by the daemon pool.- Parameters:
task
- the task to submit
-
addTask
protected void addTask(AbstractPersistenceManager.Task task)
Add the provided task to the set of tasks.- Parameters:
task
- the task to add
-
executeTask
protected void executeTask(AbstractPersistenceManager.Task task)
Execute the specified task with the calling thread.- Parameters:
task
- the task to execute
-
executeTaskExclusive
protected void executeTaskExclusive(AbstractPersistenceManager.Task task)
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
protected abstract PS instantiatePersistentStore(String sId)
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.datagrid.persistence.PersistenceTools instantiatePersistenceTools(com.oracle.datagrid.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
public File getDataDirectory()
Return the directory used to store persisted data.- Returns:
- the data storage directory
-
getTrashDirectory
public File getTrashDirectory()
Return the directory used to store "safe-deleted" persisted data.- Returns:
- the trash storage directory
-
getLockDirectory
protected File getLockDirectory()
Return the directory used to store lock files.- Returns:
- the directory used to store lock files
-
getPersistenceEnvironment
protected AbstractPersistenceEnvironment getPersistenceEnvironment()
Return the environment that created this manager.- Returns:
- the environment that created this manager
-
setPersistenceEnvironment
protected void setPersistenceEnvironment(AbstractPersistenceEnvironment env)
Configure the environment that created this manager.- Parameters:
env
- the environment that created this manager
-
getPersistentStoreMap
public Map<String,PS> 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
-
-