mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
03.39.2015 e4c1b15c2f636d0ec0c9baf0d5190d5a80174eab
Code cleanup
3 files modified
144 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/ChangelogBackend.java 66 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/controls/ExternalChangelogRequestControl.java 70 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/common/MultiDomainServerState.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/ChangelogBackend.java
@@ -271,14 +271,12 @@
    return (ChangelogBackend) DirectoryServer.getBackend(CHANGELOG_BASE_DN);
  }
  /** {@inheritDoc} */
  @Override
  public void configureBackend(final Configuration config, ServerContext serverContext) throws ConfigException
  {
    throw new UnsupportedOperationException("The changelog backend is not configurable");
  }
  /** {@inheritDoc} */
  @Override
  public void openBackend() throws InitializationException
  {
@@ -295,7 +293,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void closeBackend()
  {
@@ -309,21 +306,18 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public DN[] getBaseDNs()
  {
    return baseDNs;
  }
  /** {@inheritDoc} */
  @Override
  public boolean isIndexed(final AttributeType attributeType, final IndexType indexType)
  {
    return true;
  }
  /** {@inheritDoc} */
  @Override
  public Entry getEntry(final DN entryDN) throws DirectoryException
  {
@@ -335,7 +329,6 @@
    throw new RuntimeException("Not implemented");
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult hasSubordinates(final DN entryDN) throws DirectoryException
  {
@@ -360,16 +353,11 @@
      {
        final ReplicationDomainDB replicationDomainDB = getChangelogDB().getReplicationDomainDB();
        CursorOptions options = new CursorOptions(GREATER_THAN_OR_EQUAL_TO_KEY, ON_MATCHING_KEY);
        final MultiDomainDBCursor cursor = replicationDomainDB.getCursorFrom(
            new MultiDomainServerState(), options, getExcludedBaseDNs());
        try
        try (final MultiDomainDBCursor cursor =
            replicationDomainDB.getCursorFrom(new MultiDomainServerState(), options, getExcludedBaseDNs()))
        {
          baseEntryHasSubordinates = cursor.next();
        }
        finally
        {
          close(cursor);
        }
      }
      catch (ChangelogException e)
      {
@@ -380,14 +368,12 @@
    return baseEntryHasSubordinates;
  }
  /** {@inheritDoc} */
  @Override
  public long getNumberOfEntriesInBaseDN(final DN baseDN) throws DirectoryException
  {
    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, ERR_NUM_SUBORDINATES_NOT_SUPPORTED.get());
  }
  /** {@inheritDoc} */
  @Override
  public long getNumberOfChildren(final DN parentDN) throws DirectoryException
  {
@@ -491,7 +477,6 @@
    return false;
  }
  /** {@inheritDoc} */
  @Override
  public void addEntry(Entry entry, AddOperation addOperation)
      throws DirectoryException, CanceledOperationException
@@ -500,7 +485,6 @@
        ERR_BACKEND_ADD_NOT_SUPPORTED.get(String.valueOf(entry.getName()), getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
      throws DirectoryException, CanceledOperationException
@@ -509,7 +493,6 @@
        ERR_BACKEND_DELETE_NOT_SUPPORTED.get(String.valueOf(entryDN), getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void replaceEntry(Entry oldEntry, Entry newEntry,
      ModifyOperation modifyOperation) throws DirectoryException,
@@ -519,7 +502,6 @@
        ERR_BACKEND_MODIFY_NOT_SUPPORTED.get(String.valueOf(newEntry.getName()), getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void renameEntry(DN currentDN, Entry entry,
      ModifyDNOperation modifyDNOperation) throws DirectoryException,
@@ -585,28 +567,24 @@
    return null;
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getSupportedControls()
  {
    return supportedControls;
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getSupportedFeatures()
  {
    return Collections.emptySet();
  }
  /** {@inheritDoc} */
  @Override
  public boolean supports(BackendOperation backendOperation)
  {
    return false;
  }
  /** {@inheritDoc} */
  @Override
  public void exportLDIF(final LDIFExportConfig exportConfig)
      throws DirectoryException
@@ -615,7 +593,6 @@
        ERR_BACKEND_IMPORT_AND_EXPORT_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public LDIFImportResult importLDIF(LDIFImportConfig importConfig, ServerContext serverContext)
      throws DirectoryException
@@ -624,7 +601,6 @@
        ERR_BACKEND_IMPORT_AND_EXPORT_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void createBackup(BackupConfig backupConfig) throws DirectoryException
  {
@@ -632,7 +608,6 @@
        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void removeBackup(BackupDirectory backupDirectory, String backupID) throws DirectoryException
  {
@@ -640,7 +615,6 @@
          ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void restoreBackup(RestoreConfig restoreConfig) throws DirectoryException
  {
@@ -648,7 +622,6 @@
          ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public long getEntryCount()
  {
@@ -844,9 +817,7 @@
           && filter.getAttributeType().getPrimaryName().equalsIgnoreCase(primaryName);
  }
  /**
   * Search the changelog when a cookie control is provided.
   */
  /** Search the changelog when a cookie control is provided. */
  private void initialSearchFromCookie(final CookieEntrySender entrySender)
      throws DirectoryException, ChangelogException
  {
@@ -855,15 +826,12 @@
      return;
    }
    ECLMultiDomainDBCursor replicaUpdatesCursor = null;
    try
    {
      final ReplicationDomainDB replicationDomainDB = getChangelogDB().getReplicationDomainDB();
      CursorOptions options = new CursorOptions(GREATER_THAN_OR_EQUAL_TO_KEY, AFTER_MATCHING_KEY);
      final MultiDomainDBCursor cursor = replicationDomainDB.getCursorFrom(
          entrySender.cookie, options, entrySender.excludedBaseDNs);
      replicaUpdatesCursor = new ECLMultiDomainDBCursor(domainPredicate, cursor);
    try (final MultiDomainDBCursor cursor =
        replicationDomainDB.getCursorFrom(entrySender.cookie, options, entrySender.excludedBaseDNs);
        ECLMultiDomainDBCursor replicaUpdatesCursor = new ECLMultiDomainDBCursor(domainPredicate, cursor))
    {
      if (sendCookieEntriesFromCursor(entrySender, replicaUpdatesCursor))
      {
        entrySender.transitioningToPersistentSearchPhase();
@@ -873,7 +841,6 @@
    finally
    {
      entrySender.finalizeInitialSearch();
      StaticUtils.close(replicaUpdatesCursor);
    }
  }
@@ -912,7 +879,6 @@
    return false;
  }
  /** {@inheritDoc} */
  @Override
  public void registerPersistentSearch(PersistentSearch pSearch) throws DirectoryException
  {
@@ -1003,9 +969,7 @@
    }
  }
  /**
   * Search the changelog using change number(s).
   */
  /** Search the changelog using change number(s). */
  private void initialSearchFromChangeNumber(final ChangeNumberEntrySender entrySender)
      throws ChangelogException, DirectoryException
  {
@@ -1014,11 +978,9 @@
      return;
    }
    DBCursor<ChangeNumberIndexRecord> cnIndexDBCursor = null;
    final AtomicReference<MultiDomainDBCursor> replicaUpdatesCursor = new AtomicReference<>();
    try
    try (DBCursor<ChangeNumberIndexRecord> cnIndexDBCursor = getCNIndexDBCursor(entrySender.lowestChangeNumber))
    {
      cnIndexDBCursor = getCNIndexDBCursor(entrySender.lowestChangeNumber);
      final MultiDomainServerState cookie = new MultiDomainServerState();
      if (sendChangeNumberEntriesFromCursors(entrySender, cnIndexDBCursor, replicaUpdatesCursor, cookie))
@@ -1030,7 +992,7 @@
    finally
    {
      entrySender.finalizeInitialSearch();
      StaticUtils.close(cnIndexDBCursor, replicaUpdatesCursor.get());
      StaticUtils.close(replicaUpdatesCursor.get());
    }
  }
@@ -1194,9 +1156,7 @@
    return cnIndexDB.getCursorFrom(changeNumberToUse);
  }
  /**
   * Creates a changelog entry.
   */
  /** Creates a changelog entry. */
  private static Entry createEntryFromMsg(final DN baseDN, final long changeNumber, final String cookie,
      final UpdateMsg msg) throws DirectoryException
  {
@@ -1557,9 +1517,7 @@
    }
  }
  /**
   * Describes the current search phase.
   */
  /** Describes the current search phase. */
  private enum SearchPhase
  {
    /**
opendj-server-legacy/src/main/java/org/opends/server/controls/ExternalChangelogRequestControl.java
@@ -36,84 +36,74 @@
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.opends.server.replication.common.MultiDomainServerState;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.replication.common.MultiDomainServerState;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
import org.forgerock.opendj.ldap.ResultCode;
/**
 * This class implements the control used to browse the external changelog.
 */
/** This class implements the control used to browse the external changelog. */
public class ExternalChangelogRequestControl
       extends Control
{
  private MultiDomainServerState cookie;
  /**
   * ControlDecoder implementation to decode this control from a ByteString.
   */
  /** ControlDecoder implementation to decode this control from a ByteString. */
  private static final class Decoder
      implements ControlDecoder<ExternalChangelogRequestControl>
  {
    /** {@inheritDoc} */
    public ExternalChangelogRequestControl decode(boolean isCritical,
        ByteString value)
    throws DirectoryException
    @Override
    public ExternalChangelogRequestControl decode(boolean isCritical, ByteString value) throws DirectoryException
    {
      MultiDomainServerState mdss;
      return new ExternalChangelogRequestControl(isCritical, decodeCookie(value));
    }
    private MultiDomainServerState decodeCookie(ByteString value) throws DirectoryException
    {
      if (value == null)
      {
        mdss = new MultiDomainServerState();
      } else {
        return new MultiDomainServerState();
      }
      ASN1Reader reader = ASN1.getReader(value);
      String mdssValue = null;
      try
      {
        mdssValue = reader.readOctetStringAsString();
        mdss = new MultiDomainServerState(mdssValue);
        return new MultiDomainServerState(mdssValue);
      }
      catch (Exception e)
      {
        try
        {
          mdssValue = value.toString();
          mdss = new MultiDomainServerState(mdssValue);
          return new MultiDomainServerState(mdssValue);
        }
        catch (Exception e2)
        {
          LocalizableMessage message =
            ERR_CANNOT_DECODE_CONTROL_VALUE.get(
                getOID() + " x=" + value.toHexString() + " v="
                + mdssValue , getExceptionMessage(e));
          LocalizableMessage message = ERR_CANNOT_DECODE_CONTROL_VALUE.get(
              getOID() + " x=" + value.toHexString() + " v=" + mdssValue, getExceptionMessage(e));
          throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message, e);
        }
      }
      }
      return new ExternalChangelogRequestControl(isCritical, mdss);
    }
    @Override
    public String getOID()
    {
      return OID_ECL_COOKIE_EXCHANGE_CONTROL;
    }
  }
  /**
   * The Control Decoder that can be used to decode this control.
   */
  public static final ControlDecoder<ExternalChangelogRequestControl> DECODER =
    new Decoder();
  /** The Control Decoder that can be used to decode this control. */
  public static final ControlDecoder<ExternalChangelogRequestControl> DECODER = new Decoder();
  /**
   * Create a new external change log request control to contain the cookie.
   * @param isCritical Specifies whether the control is critical.
   * @param cookie Specifies the cookie value.
   */
  public ExternalChangelogRequestControl(boolean isCritical,
      MultiDomainServerState cookie)
  public ExternalChangelogRequestControl(boolean isCritical, MultiDomainServerState cookie)
  {
    super(OID_ECL_COOKIE_EXCHANGE_CONTROL, isCritical);
    this.cookie = cookie;
@@ -128,10 +118,7 @@
    return this.cookie;
  }
  /**
   * Dump a string representation of this object to the provided bufer.
   * @param buffer The provided buffer.
   */
  @Override
  public void toString(StringBuilder buffer)
  {
    buffer.append("ExternalChangelogRequestControl(cookie=");
@@ -139,20 +126,11 @@
    buffer.append(")");
  }
  /**
   * Writes this control's value to an ASN.1 writer. The value
   * (if any) must be written as an ASN1OctetString.
   *
   * @param writer The ASN.1 writer to use.
   * @throws IOException If a problem occurs while writing to the
   *                     stream.
   */
  protected void writeValue(ASN1Writer writer)
      throws IOException
  @Override
  protected void writeValue(ASN1Writer writer) throws IOException
  {
    writer.writeStartSequence(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    writer.writeOctetString(this.cookie.toString());
    writer.writeEndSequence();
  }
}
opendj-server-legacy/src/main/java/org/opends/server/replication/common/MultiDomainServerState.java
@@ -54,14 +54,10 @@
 */
public class MultiDomainServerState implements Iterable<DN>
{
  /**
   * The list of (domain service id, ServerState).
   */
  /** The list of (domain service id, ServerState). */
  private final ConcurrentMap<DN, ServerState> list;
  /**
   * Creates a new empty object.
   */
  /** Creates a new empty object. */
  public MultiDomainServerState()
  {
    list = new ConcurrentSkipListMap<>();