PersistentServerState.java revision a395dd575518d9e5280fc5d5d5ef47c61b174647
/*
* 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
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* This class implements a ServerState that is stored on the backends
* used to store the synchronized data and that is therefore persistent
* accross server reboot.
*/
public class PersistentServerState extends ServerState
{
private boolean savedStatus = true;
private InternalClientConnection conn =
private ASN1OctetString asn1BaseDn;
/**
* The attribute name used to store the state in the backend.
*/
/**
* create a new ServerState.
* @param baseDn The baseDN for which the ServerState is created
*/
{
loadState();
}
/**
* {@inheritDoc}
*/
{
savedStatus = false;
return super.update(changeNumber);
}
/**
* Save this object to persistent storage.
*/
public void save()
{
if (savedStatus)
return;
savedStatus = true;
{
savedStatus = false;
}
}
/**
* Load the ServerState from the backing entry in database to memory.
*/
public void loadState()
{
// try to load the state from the base entry.
if (stateEntry == null)
{
// The base entry does not exist yet
// in the database or was deleted. Try to read the ServerState
// from the configuration instead.
}
if (stateEntry != null)
{
}
/*
* TODO : The ServerState is saved to the database periodically,
* therefore in case of crash it is possible that is does not contain
* the latest changes that have been processed and saved to the
* database.
* In order to make sure that we don't loose them, search all the entries
* that have been updated after this entry.
* This is done by using the HistoricalCsnOrderingMatchingRule
* and an ordering index for historical attribute
*/
}
/**
* Run a search operation to find the base entry
* of the replication domain for which this ServerState was created.
*
* @return Thebasen Entry or null if no entry was found;
*/
private SearchResultEntry searchBaseEntry()
{
try
{
} catch (LDAPException e)
{
// can not happen
return null;
}
/*
* Search the database entry that is used to periodically
* save the ServerState
*/
{
return null;
}
{
/*
* Read the serverState from the REPLICATION_STATE attribute
*/
{
}
}
return stateEntry;
}
/**
* Run a search operation to find the entry with the configuration
* of the replication domain for which this ServerState was created.
*
* @return The configuration Entry or null if no entry was found;
*/
private SearchResultEntry searchConfigEntry()
{
try
{
"(&(objectclass=ds-cfg-replication-domain)"
{
/*
* Read the serverState from the REPLICATION_STATE attribute
*/
if (!resultEntries.isEmpty())
{
return resultEntry;
}
}
return null;
} catch (DirectoryException e)
{
// can not happen
return null;
}
}
/**
* Update this ServerState from the provided entry.
*
* @param resultEntry The entry that should be used to update this
* ServerState.
*/
{
{
{
}
}
}
/**
* Save the current values of this PersistentState object
* in the appropiate entry of the database.
*
* @return a ResultCode indicating if the method was successfull.
*/
private ResultCode updateStateEntry()
{
/*
* Generate a modify operation on the Server State baseD Entry.
*/
{
// The base entry does not exist yet in the database or
// has been deleted, save the state to the config entry instead.
if (configEntry != null)
{
}
}
return result;
}
/**
* Run a modify operation to update the entry whose DN is given as
* a parameter with the serverState information.
*
* @param serverStateEntryDN The DN of the entry to be updated.
*
* @return A ResultCode indicating if the operation was successful.
*/
{
mods);
op.setInternalOperation(true);
op.setSynchronizationOperation(true);
op.setDontSynchronize(true);
{
}
return op.getResultCode();
}
/**
* Empty the ServerState.
* After this call the Server State will be in the same state
* as if it was just created.
*/
public void clearInMemory()
{
super.clear();
this.savedStatus = false;
}
/**
* Empty the ServerState.
* After this call the Server State will be in the same state
* as if it was just created.
*/
public void clear()
{
save();
}
}