Class AbstractPersistenceEnvironment

java.lang.Object
com.tangosol.util.Base
com.tangosol.persistence.AbstractPersistenceEnvironment
All Implemented Interfaces:
com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>, PersistenceEnvironmentInfo

public abstract class AbstractPersistenceEnvironment extends Base implements com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>, PersistenceEnvironmentInfo
Abstract implementation of a ReadBuffer-based PersistentEnvironment.
Author:
jh 2013.05.21
  • Field Details

    • NO_STRINGS

      protected static final String[] NO_STRINGS
      An empty String array (by definition immutable).
    • DELETED_PREFIX

      protected static final String DELETED_PREFIX
      A filename prefix for deleted snapshots used to handle concurrent deletions.
      See Also:
    • f_atomicRemovesCounter

      protected final AtomicInteger f_atomicRemovesCounter
      An atomic counter counter used during snapshot removal.
    • f_fileActive

      protected final File f_fileActive
      The data directory of the active persistence manager.
    • f_fileBackup

      protected final File f_fileBackup
      The data directory of the backup persistence manager.
    • f_fileEvents

      protected final File f_fileEvents
      The events directory of the events persistence manager.
    • f_fileSnapshot

      protected final File f_fileSnapshot
      The snapshot directory.
    • f_fileTrash

      protected final File f_fileTrash
      An optional trash directory.
    • m_managerActive

      protected AbstractPersistenceManager<?> m_managerActive
      This singleton active manager.
    • m_managerBackup

      protected AbstractPersistenceManager<?> m_managerBackup
      This singleton backup manager.
    • m_managerEvents

      protected AbstractPersistenceManager<?> m_managerEvents
      This singleton events manager.
    • f_mapSnapshots

      protected final Map<String,AbstractPersistenceManager> f_mapSnapshots
      The map of snapshots, keyed by snapshot name.
    • m_pool

      protected com.tangosol.internal.util.DaemonPool m_pool
      An optional DaemonPool used to execute tasks.
  • Constructor Details

    • AbstractPersistenceEnvironment

      public AbstractPersistenceEnvironment(File fileActive, File fileSnapshot, File fileTrash) throws IOException
      Create a new BerkeleyDBEnvironment that manages a singleton BerkeleyDBManager with the specified directories:
      1. data - active persistence
      2. snapshot - location for snapshots
      3. trash - optional location trashed stores
      4. events - optional location for event storage
      Parameters:
      fileActive - the data directory of the singleton active manager or null if an active manager shouldn't be maintained by this environment
      fileSnapshot - the snapshot directory
      fileTrash - an optional trash directory used for "safe" deletes
      Throws:
      IOException - if the data directory could not be created
      IllegalArgumentException - if the data, snapshot, and trash directories are not unique
    • AbstractPersistenceEnvironment

      public AbstractPersistenceEnvironment(File fileActive, File fileSnapshot, File fileTrash, File fileEvents) throws IOException
      Create a new BerkeleyDBEnvironment that manages a singleton BerkeleyDBManager with the specified directories:
      1. data - active persistence
      2. snapshot - location for snapshots
      3. trash - optional location trashed stores
      4. events - optional location for event storage
      5. backup - optional location for backup storage
      Parameters:
      fileActive - the data directory of the singleton active manager or null if an active manager shouldn't be maintained by this environment
      fileSnapshot - the snapshot directory
      fileTrash - an optional trash directory used for "safe" deletes
      fileEvents - an optional events directory used for to store map events
      Throws:
      IOException - if the data directory could not be created
      IllegalArgumentException - if the data, snapshot, and trash directories are not unique
    • AbstractPersistenceEnvironment

      public AbstractPersistenceEnvironment(File fileActive, File fileBackup, File fileEvents, File fileSnapshot, File fileTrash) throws IOException
      Create a new BerkeleyDBEnvironment that manages a singleton BerkeleyDBManager with the specified directories:
      1. data - active persistence
      2. backup - optional location for backup storage
      3. events - optional location for event storage
      4. snapshot - location for snapshots
      5. trash - optional location trashed stores
      Parameters:
      fileActive - the data directory of the singleton active manager or null if an active manager shouldn't be maintained by this environment
      fileBackup - an optional backup directory used to store backup map data
      fileEvents - an optional events directory used to store map events
      fileSnapshot - the snapshot directory
      fileTrash - an optional trash directory used for "safe" deletes
      Throws:
      IOException - if the data directory could not be created
      IllegalArgumentException - if the data, backup, snapshot, and trash directories are not unique
  • Method Details

    • openBackup

      public com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> openBackup()
      Open and return a singleton PersistenceManager to store backup data.
      Specified by:
      openBackup in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Returns:
      the singleton backup PersistenceManager or null if an active PersistenceManager has not been configured
    • openEvents

      public com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> openEvents()
      Open and return a singleton PersistenceManager to store MapEvents.
      Specified by:
      openEvents in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Returns:
      the singleton store of MapEvents or null if durable events is not enabled
    • openActive

      public com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> openActive()
      Open and return the singleton active PersistenceManager.
      Specified by:
      openActive in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Returns:
      the singleton active PersistenceManager or null if an active PersistenceManager has not been configured
    • openSnapshot

      public com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> openSnapshot(String sSnapshot)
      Open a PersistenceManager used to access the snapshot with the specified identifier.
      Specified by:
      openSnapshot in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Parameters:
      sSnapshot -  the snapshot identifier
      Returns:
      a PersistenceManager representing the snapshot
    • createSnapshot

      public com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> createSnapshot(String sSnapshot, com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> manager)
      Create a PersistenceManager used to manage the snapshot with the specified identifier.
      Specified by:
      createSnapshot in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Parameters:
      sSnapshot -  the snapshot identifier
      manager - the optional PersistenceManager to create a snapshot of; if null, an empty snapshot will be created
      Returns:
      a PersistenceManager representing the snapshot
    • removeSnapshot

      public boolean removeSnapshot(String sSnapshot)
      Remove the persistent artifacts associated with the snapshot with the specified identifier.
      Specified by:
      removeSnapshot in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Parameters:
      sSnapshot -  the snapshot identifier
      Returns:
      true if the snapshot was successfully deleted, false otherwise
    • listSnapshots

      public String[] listSnapshots()
      Return the identifiers of the snapshots known to this environment.
      Specified by:
      listSnapshots in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
      Returns:
      a list of the known snapshot identifiers
    • release

      public void release()
      Release all resources held by this environment. Note that the behavior of all other methods on this environment is undefined after this method is called.
      Specified by:
      release in interface com.oracle.coherence.persistence.PersistenceEnvironment<ReadBuffer>
    • getPersistenceActiveDirectory

      public File getPersistenceActiveDirectory()
      Return the directory under which cached data is actively persisted by the environment.
      Specified by:
      getPersistenceActiveDirectory in interface PersistenceEnvironmentInfo
      Returns:
      the active directory
    • getPersistenceBackupDirectory

      public File getPersistenceBackupDirectory()
      Return the directory under which cached data is actively persisted by the environment.
      Specified by:
      getPersistenceBackupDirectory in interface PersistenceEnvironmentInfo
      Returns:
      the backup directory
    • getPersistenceEventsDirectory

      public File getPersistenceEventsDirectory()
      Return the directory under which cached data is actively persisted by the environment.
      Specified by:
      getPersistenceEventsDirectory in interface PersistenceEnvironmentInfo
      Returns:
      the events directory
    • getPersistenceSnapshotDirectory

      public File getPersistenceSnapshotDirectory()
      Return the directory under which copies of cached data are persisted by the environment.
      Specified by:
      getPersistenceSnapshotDirectory in interface PersistenceEnvironmentInfo
      Returns:
      the snapshot directory
    • getPersistenceTrashDirectory

      public File getPersistenceTrashDirectory()
      Return the directory under which potentially corrupted persisted data is stored by the environment.
      Specified by:
      getPersistenceTrashDirectory in interface PersistenceEnvironmentInfo
      Returns:
      the trash directory
    • getPersistenceActiveSpaceUsed

      public long getPersistenceActiveSpaceUsed()
      Return the total size in bytes used by the persistence layer to persist mutating cache operations.
      Specified by:
      getPersistenceActiveSpaceUsed in interface PersistenceEnvironmentInfo
      Returns:
      the total size
    • getPersistenceBackupSpaceUsed

      public long getPersistenceBackupSpaceUsed()
      Return the total size in bytes used by the persistence layer to persist backups of mutating cache operations.
      Specified by:
      getPersistenceBackupSpaceUsed in interface PersistenceEnvironmentInfo
      Returns:
      the total size
    • 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 environment.
      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 environment.
      Parameters:
      eCause - an optional cause
      sMessage - an optional detail message
      Returns:
      a PersistenceException with the given cause and detail message
    • onReleased

      protected void onReleased(AbstractPersistenceManager manager)
      Called by the specified manager when it has been released.
      Parameters:
      manager - the manager that was released
    • openActiveInternal

      protected abstract AbstractPersistenceManager openActiveInternal()
      Open the active manager.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Returns:
      the active manager
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
    • openBackupInternal

      protected abstract AbstractPersistenceManager openBackupInternal()
      Open the backup manager.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Returns:
      the backup manager
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
    • openEventsInternal

      protected abstract AbstractPersistenceManager openEventsInternal()
      Open the events manager.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Returns:
      the events manager
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
    • openSnapshotInternal

      protected abstract AbstractPersistenceManager openSnapshotInternal(File fileSnapshot, String sSnapshot)
      Open the snapshot with the specified identifier.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Parameters:
      fileSnapshot - the directory of the snapshot
      sSnapshot -   the snapshot identifier
      Returns:
      the snapshot
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
    • createSnapshotInternal

      protected abstract AbstractPersistenceManager createSnapshotInternal(File fileSnapshot, String sSnapshot, com.oracle.coherence.persistence.PersistenceManager<ReadBuffer> manager)
      Create a snapshot with the specified identifier.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Parameters:
      fileSnapshot - the directory of the snapshot
      sSnapshot -  the snapshot identifier
      manager - the optional manager to create a snapshot of; if null, an empty snapshot will be created
      Returns:
      the snapshot
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
      IllegalArgumentException - if the specified manager is incompatible with this environment
    • removeSnapshotInternal

      protected boolean removeSnapshotInternal(File fileSnapshot, String sSnapshot)
      Remove the snapshot with the specified identifier.

      Note: this method is guaranteed to only be called by a thread that holds a monitor on this environment.

      Parameters:
      fileSnapshot - the directory of the snapshot
      sSnapshot -   the snapshot identifier
      Returns:
      true if the snapshot was successfully deleted, false otherwise
      Throws:
      com.oracle.coherence.persistence.PersistenceException - if a general persistence error occurs
    • createHiddenSnapshotDirectory

      protected Path createHiddenSnapshotDirectory(String sPrefix)
      Return a Path to a hidden directory within the snapshot directory that does not exist.
      Parameters:
      sPrefix - a prefix for the directory name
      Returns:
      a Path to a hidden directory within the snapshot directory that does not exist
    • toString

      public String toString()
      Return a human readable description of this AbstractPersistenceManager.
      Overrides:
      toString in class Object
      Returns:
      a human readable description
    • 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