/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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-2010 Sun Microsystems, Inc.
* Portions copyright 2012-2014 ForgeRock AS.
*/
/**
* This class implements a ServerState that is stored in the backend
* used to store the synchronized data and that is therefore persistent
* across server reboot.
*/
class PersistentServerState
{
private final int serverId;
/**
* The attribute name used to store the state in the backend.
*/
/**
* Create a new PersistentServerState based on an already existing
* ServerState.
*
* @param baseDN The baseDN for which the ServerState is created.
* @param serverId The serverId.
* @param state The serverState.
*/
{
loadState();
}
/**
* Checks that the CSN given as a parameter is in this ServerState.
*
* @param covered The CSN that should be checked.
* @return A boolean indicating if this ServerState contains the CSN
* given in parameter.
*/
{
}
/**
* Update the Server State with a CSN. All operations with smaller CSN and the
* same serverID must be committed before calling this method.
*
* @param csn
* The committed CSN.
* @return a boolean indicating if the update was meaningful.
*/
{
}
/**
* Save this object to persistent storage.
*/
public void save()
{
{
}
}
/**
* 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)
{
}
/*
* In order to make sure that the replication never looses changes,
* the server needs to search all the entries that have been
* updated after the last write of the ServerState.
* Inconsistencies may append after a crash.
*/
}
/**
* Run a search operation to find the base entry
* of the replication domain for which this ServerState was created.
*
* @return The base entry or null if no entry was found;
*/
{
try
{
/*
* Search the database entry that is used to periodically
* save the ServerState
*/
{
return null;
}
return getFirstResult(search);
}
catch (DirectoryException e)
{
// cannot happen
return null;
}
}
/**
* 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;
*/
{
try
{
"(&(objectclass=ds-cfg-replication-domain)"
return getFirstResult(op);
}
catch (DirectoryException e)
{
// can not happen
return null;
}
}
{
{
{
}
}
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 appropriate entry of the database.
*
* @return a boolean indicating if the method was successful.
*/
private boolean updateStateEntry()
{
// Generate a modify operation on the Server State baseDN 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)
{
}
}
}
/**
* 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.
*/
{
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()
{
}
/**
* Empty the ServerState.
* After this call the Server State will be in the same state
* as if it was just created.
*/
void clear()
{
save();
}
/**
* 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
*/
private final void checkAndUpdateServerState()
{
// Retrieves the entries that have changed since the
// maxCsn stored in the serverState
synchronized (this)
{
if (serverStateMaxCSN == null)
{
return;
}
try
{
}
catch (Exception e)
{
return;
}
{
// An error happened trying to search for the updates
// Log an error
return;
}
{
{
{
}
}
}
{
// Update the serverState with the new maxCSN present in the database
}
}
}
/**
* Get the largest CSN seen for a given LDAP server ID.
*
* @param serverId
* The serverId
* @return The largest CSN seen
*/
{
}
/** {@inheritDoc} */
{
return getClass().getSimpleName()
+ " baseDN=" + baseDN
+ " serverId=" + serverId
}
}