RootContainer.java revision bedb386242727f98834c64397487f48d5eb6116c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* Wrapper class for the JE environment. Root container holds all the entry
* containers for each base DN. It also maintains all the openings and closings
* of the entry containers.
*/
public class RootContainer
implements ConfigurationChangeListener<JEBackendCfg>
{
/**
* The JE database environment.
*/
private Environment env;
/**
* The backend configuration.
*/
/**
* The backend to which this entry root container belongs.
*/
/**
* The database environment monitor for this JE environment.
*/
private DatabaseEnvironmentMonitor monitor;
/**
* The base DNs contained in this entryContainer.
*/
/**
* The cached value of the next entry identifier to be assigned.
*/
/**
* Creates a new RootContainer object. Each root container represents a JE
* environment.
*
* @param config The configuration of the JE backend.
* @param backend A reference to the JE back end that is creating this
* root container.
*/
{
}
/**
* Helper method to apply database directory permissions and create a new
* JE environment.
*
* @param backendDirectory The environment home directory for JE.
* @param backendPermission The file permissions for the environment home
* directory.
* @param envConfig The JE environment configuration.
* @throws DatabaseException If an error occurs when creating the environment.
*/
{
// Get the backend database backendDirectory permissions and apply
{
try
{
{
throw new Exception();
}
}
catch(Exception e)
{
// Log an warning that the permissions were not set.
}
}
// Open the database environment
if (debugEnabled())
{
debugInfo("JE (%s) environment opened with the following config: %n%s",
// Get current size of heap in bytes
// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
// Get amount of free memory within the heap in bytes. This size will
// increase
// after garbage collection and decrease as new objects are created.
}
}
/**
* Opens the root container.
*
* @throws DatabaseException If an error occurs when opening the container.
*/
public void open() throws DatabaseException
{
}
/**
* Opens the root container using the configuration parameters provided. Any
* configuration parameters provided will override the parameters in the
* JE configuration object.
*
* @param backendDirectory The environment home directory for JE.
* @param backendPermission he file permissions for the environment home
* directory.
* @param readOnly Open the container in read only mode.
* @param allowCreate Allow creating new entries in the container.
* @param transactional Use transactions on operations.
* @param txnNoSync Use asynchronous transactions.
* @param isLocking Create the environment with locking.
* @param runCheckPointer Start the checkpointer.
* @throws DatabaseException If an error occurs when openinng the container.
*/
boolean readOnly,
boolean allowCreate,
boolean transactional,
boolean txnNoSync,
boolean isLocking,
boolean runCheckPointer) throws DatabaseException
{
{
}
else
{
envConfig = new EnvironmentConfig();
}
}
/**
* Opens the entry container for a base DN. If the entry container does not
* exist for the base DN, it will be created. The entry container will be
* opened with the same mode as the root container. Any entry containers
* opened in a read only root container will also be read only. Any entry
* containers opened in a non transactional root container will also be non
* transactional.
*
* @param baseDN The base DN of the entry container to open.
* @return The opened entry container.
* @throws DatabaseException If an error occurs while opening the entry
* container.
*/
{
//If an entry container for this baseDN is already open we don't allow
//another to be opened.
throw new DatabaseException("Entry container for baseDN " +
{
ec.openReadOnly();
}
{
ec.openNonTransactional(true);
}
else
{
}
return ec;
}
/**
* Opens the entry containers for multiple base DNs.
*
* @param baseDNs The base DNs of the entry containers to open.
* @throws DatabaseException If an error occurs while opening the entry
* container.
*/
{
{
{
}
}
}
/**
* Close the entry container for a base DN.
*
* @param baseDN The base DN of the entry container to close.
* @throws DatabaseException If an error occurs while closing the entry
* container.
*/
{
}
/**
* Close and remove a entry container for a base DN from disk.
*
* @param baseDN The base DN of the entry container to remove.
* @throws DatabaseException If an error occurs while removing the entry
* container.
*/
{
}
/**
* Get the DatabaseEnvironmentMonitor object for JE environment used by this
* root container.
*
* @return The DatabaseEnvironmentMonito object.
*/
{
{
}
return monitor;
}
/**
* Preload the database cache. There is no preload if the configured preload
* time limit is zero.
*/
public void preload()
{
if (timeLimit > 0)
{
// Get a list of all the databases used by the backend.
{
}
// Sort the list in order of priority.
// Preload each database until we reach the time limit or the cache
// is filled.
try
{
// Configure preload of Leaf Nodes (LNs) containing the data values.
preloadConfig.setLoadLNs(true);
{
// Calculate the remaining time.
if (timeRemaining <= 0)
{
break;
}
if(debugEnabled())
{
}
// Stop if the cache is full or the time limit has been exceeded.
{
break;
}
}
// Log an informational message about the size of the cache.
msgID);
}
catch (DatabaseException e)
{
if (debugEnabled())
{
}
}
}
}
/**
* Synchronously invokes the cleaner on the database environment then forces a
* checkpoint to delete the log files that are no longer in use.
*
* @throws DatabaseException If an error occurs while cleaning the database
* environment.
*/
private void cleanDatabase()
throws DatabaseException
{
int msgID;
{
{
}
};
msgID);
int currentCleaned = 0;
int totalCleaned = 0;
{
}
msgID);
if (totalCleaned > 0)
{
}
msgID);
}
/**
* Close the root entryContainer.
*
* @throws DatabaseException If an error occurs while attempting to close
* the entryContainer.
*/
public void close() throws DatabaseException
{
{
}
}
/**
* Return all the entry containers in this root container.
*
* @return The entry containers in this root container.
*/
{
return entryContainers.values();
}
/**
* Returns all the baseDNs this root container stores.
*
* @return The set of DNs this root container stores.
*/
{
return entryContainers.keySet();
}
/**
* Return the entry container for a specific base DN.
*
* @param baseDN The base DN of the entry container to retrive.
* @return The entry container for the base DN.
*/
{
{
{
}
}
return ec;
}
/**
* Get the environment stats of the JE environment used in this root
* container.
*
* @param statsConfig The configuration to use for the EnvironmentStats
* object.
* @return The environment status of the JE environment.
* @throws DatabaseException If an error occurs while retriving the stats
* object.
*/
throws DatabaseException
{
}
/**
* Get the environment config of the JE environment used in this root
* container.
*
* @return The environment config of the JE environment.
* @throws DatabaseException If an error occurs while retriving the
* configuration object.
*/
{
}
/**
* Get the total number of entries in this root container.
*
* @return The number of entries in this root container
* @throws DatabaseException If an error occurs while retriving the entry
* count.
*/
public long getEntryCount() throws DatabaseException
{
long entryCount = 0;
{
}
return entryCount;
}
/**
* Assign the next entry ID.
*
* @return The assigned entry ID.
*/
public EntryID getNextEntryID()
{
}
/**
* Return the lowest entry ID assigned.
*
* @return The lowest entry ID assigned.
*/
public Long getLowestEntryID()
{
return 1L;
}
/**
* Return the highest entry ID assigned.
*
* @return The highest entry ID assigned.
*/
public Long getHighestEntryID()
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
boolean acceptable = true;
// This listener handles only the changes to JE properties.
try
{
}
catch (Exception e)
{
acceptable = false;
}
return acceptable;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
try
{
// Check if any JE non-mutable properties were changed.
{
{
{
adminActionRequired = true;
if (configAttr != null)
{
}
if(debugEnabled())
{
debugInfo("The change to the following property will " +
"take effect when the backend is restarted: " +
}
}
}
}
// This takes care of changes to the JE environment for those
// properties that are mutable at runtime.
if (debugEnabled())
{
}
}
catch (Exception e)
{
messages);
return ccr;
}
messages);
return ccr;
}
}