Class DatabaseFactory.EnvironmentHolder
- All Implemented Interfaces:
Runnable
- Enclosing class:
DatabaseFactory
The Environment and Databases will be automatically flushed upon JVM shutdown or GC of the associated DatabaseFactory. For temporary Environments, the data will also be deleted. These operations are accomplished by registering this class as a JVM shutdown hook.
This logic is maintained externally from DatabaseFactory to allow for the Factory to be GC'd. If the Factory acted as the shutdown hook then it would never be GC'd as the Runtime would always hold a reference to it via the registered shutdown hook.
- Author:
- mf 2005.10.04
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Directory based lock. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Prefix for temporary environment names.static final String
Prefix for all Berkeley DB JE configuration settings.protected Collection
Databases to close prior to deleting the Environment.protected File
Environment directory.Lock held on the directory associated with the Environment.protected File
Configuration setting for parent directory.protected com.sleepycat.je.Environment
Berkeley DB Environment for managing Databases.protected com.sleepycat.je.EnvironmentConfig
Berkeley DB Environment Configuration.protected boolean
Flag indicating if this is a temporary environment.protected Thread
Shutdown hook for closing environment.protected XmlElement
Configuration.static final String
Another prefix for Berkeley DB JE configuration settings.static final String
Default directory name for berkeley db environments.static final String
Prefix for temporary file names. -
Constructor Summary
ConstructorDescriptionEnvironmentHolder
(BerkeleyDBBinaryStoreManager bdbManager) Construct a EnvironmentHolder for a given Berkeley DB Environment. -
Method Summary
Modifier and TypeMethodDescriptionvoid
closeEnvironment
(boolean fDeregister) Close an Environment.protected File
compute the system's temp directory.protected void
configure
(BerkeleyDBBinaryStoreManager bdbManager) Configure the new Environment.protected void
Create a persistent Environment.protected void
Create a temporary Environment.void
forgetDatabase
(com.sleepycat.je.Database db) Remove a database handle from the cleanup list.protected String
Generate a potentially unique Environment name.Get the Environment Directory.Get the DirectoryLock held on a temporary Environment.Get the Parent Directory.com.sleepycat.je.EnvironmentConfig
Get the Environment Configuration.com.sleepycat.je.Environment
Get underlying Berkeley DB Environment.Get the registered Databases.Get the XML Configuration.boolean
Return true if this is a temporary environment.void
run()
Shutdown hook runnable method.toString()
Return a human readable description of the EnvironmentHolder.void
trackDatabase
(com.sleepycat.je.Database db) Add a database handle to the tracking list.
-
Field Details
-
SUB_DIR_NAME
Default directory name for berkeley db environments. -
ENVIRONMENT_NAME_PREFIX
Prefix for temporary environment names.- See Also:
-
TEMP_FILE_NAME_PREFIX
Prefix for temporary file names.- See Also:
-
JE_PROPERTY_PREFIX
Prefix for all Berkeley DB JE configuration settings.- See Also:
-
SLEEPYCAT_JE_PROPERTY_PREFIX
Another prefix for Berkeley DB JE configuration settings.- See Also:
-
m_xmlConfig
Configuration. -
m_dirParent
Configuration setting for parent directory. -
m_dirEnv
Environment directory. -
m_envConfig
protected com.sleepycat.je.EnvironmentConfig m_envConfigBerkeley DB Environment Configuration. -
m_env
protected com.sleepycat.je.Environment m_envBerkeley DB Environment for managing Databases. -
m_colRegisteredDbs
Databases to close prior to deleting the Environment. -
m_dirLock
Lock held on the directory associated with the Environment. -
m_fTemporary
protected boolean m_fTemporaryFlag indicating if this is a temporary environment. -
m_threadShutdownHook
Shutdown hook for closing environment.
-
-
Constructor Details
-
EnvironmentHolder
public EnvironmentHolder(BerkeleyDBBinaryStoreManager bdbManager) throws com.sleepycat.je.DatabaseException Construct a EnvironmentHolder for a given Berkeley DB Environment.Berkeley DB Environments are bound to a single directory. Java File locking is used to ensure that only one JVM uses the Environment. The new environment will be created in a unique sub directory of the specified parent directory.
- Parameters:
bdbManager
- the BinaryStoreManager to create an environment for- Throws:
com.sleepycat.je.DatabaseException
- if the Berkeley DB Environment could not be created
-
-
Method Details
-
toString
Return a human readable description of the EnvironmentHolder. -
forgetDatabase
public void forgetDatabase(com.sleepycat.je.Database db) Remove a database handle from the cleanup list.Databases which are closed externally may be removed from tracking.
- Parameters:
db
- the Database to remove from list
-
run
public void run()Shutdown hook runnable method.This is responsible for cleaning up the databases and associated directories when the JVM exits.
-
closeEnvironment
public void closeEnvironment(boolean fDeregister) Close an Environment.This includes closing the environment and databases, and if temporary deleting the associated files.
- Parameters:
fDeregister
- indicates if the shutdown hook should be deregistered
-
trackDatabase
public void trackDatabase(com.sleepycat.je.Database db) Add a database handle to the tracking list.Databases for the environment must be tracked so that they may be closed prior to closing the environment.
- Parameters:
db
- the Database to add to the list
-
configure
Configure the new Environment.- Parameters:
bdbManager
- the BinaryStoreManager to create an environment for
-
computeTmpDir
compute the system's temp directory.- Returns:
- the system temp directory, or
null
if it could not be determined
-
createTemporaryEnvironment
protected void createTemporaryEnvironment() throws com.sleepycat.je.DatabaseExceptionCreate a temporary Environment.- Throws:
com.sleepycat.je.DatabaseException
- if environment creation fails
-
createPersistentEnvironment
protected void createPersistentEnvironment() throws com.sleepycat.je.DatabaseExceptionCreate a persistent Environment.- Throws:
com.sleepycat.je.DatabaseException
- if environment creation fails
-
generateEnvironmentName
Generate a potentially unique Environment name.- Returns:
- an environment name
-
getEnvironment
public com.sleepycat.je.Environment getEnvironment() throws com.sleepycat.je.DatabaseExceptionGet underlying Berkeley DB Environment.- Returns:
- the Berkeley DB Environment held by this EnvironmentHolder
- Throws:
com.sleepycat.je.DatabaseException
-
getXmlConfig
Get the XML Configuration.- Returns:
- the XML Configuration for this Environments.
-
getDirParent
Get the Parent Directory.- Returns:
- the Environment's parent directory
-
getDirEnv
Get the Environment Directory.- Returns:
- the Environment's directory
-
getEnvConfig
public com.sleepycat.je.EnvironmentConfig getEnvConfig()Get the Environment Configuration.- Returns:
- the Environment's configuration
-
getRegisteredDbs
Get the registered Databases.- Returns:
- a collection of open Databases from this Environment
-
getDirLock
Get the DirectoryLock held on a temporary Environment.- Returns:
- the DirectoryLock held on the temporary Environment
-
isTemporary
public boolean isTemporary()Return true if this is a temporary environment.- Returns:
- true if this is a temporary environment
-