From bdcbee41067e1f439a8ebe7fd0a9dd01799b593a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 11 Jul 2014 09:17:59 +0000
Subject: [PATCH] Code cleanups.
---
opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java | 72 ++++++++++++++++++-----------------
1 files changed, 37 insertions(+), 35 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java b/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
index d02614d..e7ed2a1 100644
--- a/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
+++ b/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
@@ -27,7 +27,7 @@
package org.opends.server.replication.plugin;
import java.util.ArrayList;
-import java.util.LinkedHashSet;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -57,7 +57,7 @@
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
- private final DN baseDn;
+ private final DN baseDN;
private final int serverId;
private final ServerState state;
@@ -70,13 +70,13 @@
* Create a new PersistentServerState based on an already existing
* ServerState.
*
- * @param baseDn The baseDN for which the ServerState is created.
+ * @param baseDN The baseDN for which the ServerState is created.
* @param serverId The serverId.
* @param state The serverState.
*/
- PersistentServerState(DN baseDn, int serverId, ServerState state)
+ PersistentServerState(DN baseDN, int serverId, ServerState state)
{
- this.baseDn = baseDn;
+ this.baseDN = baseDN;
this.serverId = serverId;
this.state = state;
loadState();
@@ -114,7 +114,7 @@
{
if (!state.isSaved())
{
- state.setSaved(updateStateEntry() == ResultCode.SUCCESS);
+ state.setSaved(updateStateEntry());
}
}
@@ -164,16 +164,15 @@
* Search the database entry that is used to periodically
* save the ServerState
*/
- LinkedHashSet<String> attributes = new LinkedHashSet<String>(1);
- attributes.add(REPLICATION_STATE);
final InternalSearchOperation search = getRootConnection().processSearch(
- baseDn, SearchScope.BASE_OBJECT, DereferenceAliasesPolicy.NEVER,
- 0, 0, false, filter, attributes);
- if (((search.getResultCode() != ResultCode.SUCCESS)) &&
- ((search.getResultCode() != ResultCode.NO_SUCH_OBJECT)))
+ baseDN, SearchScope.BASE_OBJECT, DereferenceAliasesPolicy.NEVER,
+ 0, 0, false, filter, Collections.singleton(REPLICATION_STATE));
+ final ResultCode resultCode = search.getResultCode();
+ if (resultCode != ResultCode.SUCCESS
+ && resultCode != ResultCode.NO_SUCH_OBJECT)
{
logger.error(ERR_ERROR_SEARCHING_RUV, search.getResultCode().getName(), search,
- search.getErrorMessage(), baseDn);
+ search.getErrorMessage(), baseDN);
return null;
}
return getFirstResult(search);
@@ -197,15 +196,13 @@
{
SearchFilter filter = SearchFilter.createFilterFromString(
"(&(objectclass=ds-cfg-replication-domain)"
- + "(ds-cfg-base-dn=" + baseDn + "))");
+ + "(ds-cfg-base-dn=" + baseDN + "))");
- LinkedHashSet<String> attributes = new LinkedHashSet<String>(1);
- attributes.add(REPLICATION_STATE);
final InternalSearchOperation op = getRootConnection().processSearch(
DN.valueOf("cn=config"),
SearchScope.SUBORDINATES,
DereferenceAliasesPolicy.NEVER,
- 1, 0, false, filter, attributes);
+ 1, 0, false, filter, Collections.singleton(REPLICATION_STATE));
return getFirstResult(op);
}
catch (DirectoryException e)
@@ -238,12 +235,10 @@
{
AttributeType synchronizationStateType =
DirectoryServer.getAttributeType(REPLICATION_STATE);
- List<Attribute> attrs =
- resultEntry.getAttribute(synchronizationStateType);
+ List<Attribute> attrs = resultEntry.getAttribute(synchronizationStateType);
if (attrs != null)
{
- Attribute attr = attrs.get(0);
- for (ByteString value : attr)
+ for (ByteString value : attrs.get(0))
{
update(new CSN(value.toString()));
}
@@ -254,12 +249,12 @@
* Save the current values of this PersistentState object
* in the appropriate entry of the database.
*
- * @return a ResultCode indicating if the method was successful.
+ * @return a boolean indicating if the method was successful.
*/
- private ResultCode updateStateEntry()
+ private boolean updateStateEntry()
{
// Generate a modify operation on the Server State baseDN Entry.
- ResultCode result = runUpdateStateEntry(baseDn);
+ ResultCode result = runUpdateStateEntry(baseDN);
if (result == ResultCode.NO_SUCH_OBJECT)
{
// The base entry does not exist yet in the database or has been deleted,
@@ -267,11 +262,10 @@
SearchResultEntry configEntry = searchConfigEntry();
if (configEntry != null)
{
- DN configDN = configEntry.getName();
- result = runUpdateStateEntry(configDN);
+ result = runUpdateStateEntry(configEntry.getName());
}
}
- return result;
+ return result == ResultCode.SUCCESS;
}
/**
@@ -287,14 +281,12 @@
ArrayList<ByteString> values = state.toASN1ArrayList();
LDAPAttribute attr = new LDAPAttribute(REPLICATION_STATE, values);
- LDAPModification mod = new LDAPModification(ModificationType.REPLACE, attr);
- ArrayList<RawModification> mods = new ArrayList<RawModification>(1);
- mods.add(mod);
+ RawModification mod = new LDAPModification(ModificationType.REPLACE, attr);
ModifyOperationBasis op = new ModifyOperationBasis(getRootConnection(),
nextOperationID(), nextMessageID(), null,
ByteString.valueOf(serverStateEntryDN.toString()),
- mods);
+ Collections.singletonList(mod));
op.setInternalOperation(true);
op.setSynchronizationOperation(true);
op.setDontSynchronize(true);
@@ -302,7 +294,7 @@
if (op.getResultCode() != ResultCode.SUCCESS)
{
logger.error(DEBUG_ERROR_UPDATING_RUV,
- op.getResultCode().getName(), op, op.getErrorMessage(), baseDn);
+ op.getResultCode().getName(), op, op.getErrorMessage(), baseDN);
}
return op.getResultCode();
}
@@ -357,7 +349,7 @@
InternalSearchOperation op;
try
{
- op = LDAPReplicationDomain.searchForChangedEntries(baseDn,
+ op = LDAPReplicationDomain.searchForChangedEntries(baseDN,
serverStateMaxCSN, null);
}
catch (Exception e)
@@ -369,7 +361,7 @@
{
// An error happened trying to search for the updates
// Log an error
- logger.error(ERR_CANNOT_RECOVER_CHANGES, baseDn.toNormalizedString());
+ logger.error(ERR_CANNOT_RECOVER_CHANGES, baseDN.toNormalizedString());
return;
}
@@ -394,7 +386,7 @@
{
// Update the serverState with the new maxCsn present in the database
update(dbMaxCSN);
- logger.info(NOTE_SERVER_STATE_RECOVERY, baseDn.toNormalizedString(), dbMaxCSN);
+ logger.info(NOTE_SERVER_STATE_RECOVERY, baseDN.toNormalizedString(), dbMaxCSN);
}
}
}
@@ -410,4 +402,14 @@
{
return state.getCSN(serverId);
}
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName()
+ + " baseDN=" + baseDN
+ + " serverId=" + serverId
+ + " " + REPLICATION_STATE + "=" + state;
+ }
}
--
Gitblit v1.10.0