From 5523ffc54f2a488452b35dd02a39ccfa51100d4d Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 06 Jun 2014 13:19:56 +0000
Subject: [PATCH] Code cleanup. Used UCDetector and AutoRefactor Eclipse plugins to: * reduce visibility of class members, * add final keywords to fields, * convert comments to javadocs, * etc.

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplOutputStream.java           |   27 ++----
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationBroker.java          |  105 +++++++++++++------------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java         |    8 +-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java |    8 +-
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplInputStream.java            |   32 ++++----
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java          |    8 +-
 6 files changed, 94 insertions(+), 94 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
index f3f74c5..4186a42 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
@@ -42,7 +42,7 @@
  * <p>
  * These heartbeat messages are sent by a replica directory server.
  */
-public class CTHeartbeatPublisherThread extends DirectoryThread
+class CTHeartbeatPublisherThread extends DirectoryThread
 {
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
@@ -71,8 +71,8 @@
    *                          (in milliseconds).
    * @param serverId The serverId of the sender domain.
    */
-  public CTHeartbeatPublisherThread(String threadName, Session session,
-                  long heartbeatInterval, int serverId)
+  CTHeartbeatPublisherThread(String threadName, Session session,
+      long heartbeatInterval, int serverId)
   {
     super(threadName);
     this.session = session;
@@ -171,7 +171,7 @@
    * Call this method to stop the thread.
    * This method is blocking until the thread has stopped.
    */
-  public void shutdown()
+  void shutdown()
   {
     synchronized (shutdownLock)
     {
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplInputStream.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplInputStream.java
index 170fbd3..cf41e82 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplInputStream.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplInputStream.java
@@ -22,31 +22,26 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2013 ForgeRock AS.
+ *      Portions Copyright 2013-2014 ForgeRock AS.
  */
 package org.opends.server.replication.service;
 
-
-
 import java.io.IOException;
 import java.io.InputStream;
 
-
 /**
  * This class creates an input stream that can be used to read entries generated
  * by SynchroLDIF as if they were being read from another source like a file.
  */
-public class ReplInputStream
-extends InputStream
+class ReplInputStream extends InputStream
 {
-  // Indicates whether this input stream has been closed.
+  /** Indicates whether this input stream has been closed. */
   private boolean closed;
 
-  // The domain associated to this import.
-  ReplicationDomain domain;
+  /** The domain associated to this import. */
+  private final ReplicationDomain domain;
 
   private byte[] bytes;
-
   private int index;
 
   /**
@@ -55,7 +50,7 @@
    *
    * @param domain The replication domain
    */
-  public ReplInputStream(ReplicationDomain domain)
+  ReplInputStream(ReplicationDomain domain)
   {
     this.domain = domain;
     closed      = false;
@@ -64,6 +59,7 @@
   /**
    * Closes this input stream so that no more data may be read from it.
    */
+  @Override
   public void close()
   {
     closed      = true;
@@ -84,11 +80,13 @@
    * @throws  IOException  If a problem has occurred while generating data for
    *                       use by this input stream.
    */
-  public int read(byte[] b, int off, int len)
-  throws IOException
+  @Override
+  public int read(byte[] b, int off, int len) throws IOException
   {
     if (closed)
+    {
       return -1;
+    }
 
     int receivedLength;
     int copiedLength;
@@ -128,7 +126,9 @@
     index += copiedLength;
 
     if (index == bytes.length)
+    {
       bytes = null;
+    }
 
     return copiedLength;
   }
@@ -142,8 +142,8 @@
    * @throws  IOException  If a problem has occurred while generating data for
    *                       use by this input stream.
    */
-  public int read()
-          throws IOException
+  @Override
+  public int read() throws IOException
   {
     if (closed) {
       return -1;
@@ -155,6 +155,6 @@
       throw new IOException();
     }
 
-    return ((int)b[0]);
+    return b[0];
   }
 }
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplOutputStream.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplOutputStream.java
index df80815..d94a8da 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplOutputStream.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplOutputStream.java
@@ -22,10 +22,10 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Portions Copyright 2014 ForgeRock AS.
  */
 package org.opends.server.replication.service;
 
-
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -33,15 +33,13 @@
  * This class creates an output stream that can be used to export entries
  * to a synchronization domain.
  */
-public class ReplOutputStream
-       extends OutputStream
+class ReplOutputStream extends OutputStream
 {
-  // The synchronization domain on which the export is done
-  ReplicationDomain domain;
+  /** The synchronization domain on which the export is done */
+  private final ReplicationDomain domain;
 
-  // The current number of entries exported
-  private long numExportedEntries;
-  String entryBuffer = "";
+  /** The current number of entries exported */
+  private final long numExportedEntries = 0;
 
   /**
    * Creates a new ReplLDIFOutputStream related to a replication
@@ -49,23 +47,20 @@
    *
    * @param domain The replication domain
    */
-  public ReplOutputStream(ReplicationDomain domain)
+  ReplOutputStream(ReplicationDomain domain)
   {
     this.domain = domain;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
+  @Override
   public void write(int i) throws IOException
   {
     throw new IOException("Invalid call");
   }
 
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
+  @Override
   public void write(byte b[], int off, int len) throws IOException
   {
     domain.exportLDIFEntry(b, off, len);
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationBroker.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationBroker.java
index d9e6fca..c6b4149 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -156,14 +156,14 @@
   /**
    * String reported under CSN=monitor when there is no connected RS.
    */
-  public static final String NO_CONNECTED_SERVER = "Not connected";
+  static final String NO_CONNECTED_SERVER = "Not connected";
   private final ServerState state;
   private Semaphore sendWindow;
   private int maxSendWindow;
   private int rcvWindow = 100;
   private int halfRcvWindow = rcvWindow / 2;
   private int timeout = 0;
-  private ReplSessionSecurity replSessionSecurity;
+  private final ReplSessionSecurity replSessionSecurity;
   /**
    * The RS this DS is currently connected to.
    * <p>
@@ -174,7 +174,7 @@
   private final AtomicReference<ConnectedRS> connectedRS =
       new AtomicReference<ConnectedRS>(ConnectedRS.noConnectedRS());
   /** Our replication domain. */
-  private ReplicationDomain domain;
+  private final ReplicationDomain domain;
   /**
    * This object is used as a conditional event to be notified about
    * the reception of monitor information from the Replication Server.
@@ -377,17 +377,19 @@
    * updated with a info coming from received topology messages or monitoring
    * messages.
    */
-  public static class ReplicationServerInfo
+  static class ReplicationServerInfo
   {
     private RSInfo rsInfo;
-    private short protocolVersion;
-    private DN baseDN;
-    private int windowSize;
-    private ServerState serverState;
-    private boolean sslEncryption;
+    private final short protocolVersion;
+    private final DN baseDN;
+    private final int windowSize;
+    // @NotNull
+    private final ServerState serverState;
+    private final boolean sslEncryption;
     private final int degradedStatusThreshold;
     /** Keeps the 0 value if created with a ReplServerStartMsg. */
     private int connectedDSNumber = 0;
+    // @NotNull
     private Set<Integer> connectedDSs;
     /**
      * Is this RS locally configured? (the RS is recognized as a usable server).
@@ -403,7 +405,7 @@
      * @throws IllegalArgumentException If the passed message has an unexpected
      *                                  type.
      */
-    public static ReplicationServerInfo newInstance(
+    private static ReplicationServerInfo newInstance(
       ReplicationMsg msg, String newServerURL) throws IllegalArgumentException
     {
       final ReplicationServerInfo rsInfo = newInstance(msg);
@@ -419,7 +421,7 @@
      * @throws IllegalArgumentException If the passed message has an unexpected
      *                                  type.
      */
-    public static ReplicationServerInfo newInstance(ReplicationMsg msg)
+    static ReplicationServerInfo newInstance(ReplicationMsg msg)
         throws IllegalArgumentException
     {
       if (msg instanceof ReplServerStartMsg)
@@ -452,7 +454,8 @@
           msg.getGenerationId(), msg.getGroupId(), 1);
       this.baseDN = msg.getBaseDN();
       this.windowSize = msg.getWindowSize();
-      this.serverState = msg.getServerState();
+      final ServerState ss = msg.getServerState();
+      this.serverState = ss != null ? ss : new ServerState();
       this.sslEncryption = msg.getSSLEncryption();
       this.degradedStatusThreshold = msg.getDegradedStatusThreshold();
     }
@@ -471,13 +474,38 @@
       this.protocolVersion = msg.getVersion();
       this.baseDN = msg.getBaseDN();
       this.windowSize = msg.getWindowSize();
-      this.serverState = msg.getServerState();
+      final ServerState ss = msg.getServerState();
+      this.serverState = ss != null ? ss : new ServerState();
       this.sslEncryption = msg.getSSLEncryption();
       this.degradedStatusThreshold = msg.getDegradedStatusThreshold();
       this.connectedDSNumber = msg.getConnectedDSNumber();
     }
 
     /**
+     * Constructs a new replication server info with the passed RSInfo internal
+     * values and the passed connected DSs.
+     *
+     * @param rsInfo
+     *          The RSinfo to use for the update
+     * @param connectedDSs
+     *          The new connected DSs
+     */
+    ReplicationServerInfo(RSInfo rsInfo, Set<Integer> connectedDSs)
+    {
+      this.rsInfo =
+          new RSInfo(rsInfo.getId(), rsInfo.getServerUrl(), rsInfo
+              .getGenerationId(), rsInfo.getGroupId(), rsInfo.getWeight());
+      this.protocolVersion = 0;
+      this.baseDN = null;
+      this.windowSize = 0;
+      this.connectedDSs = connectedDSs;
+      this.connectedDSNumber = connectedDSs.size();
+      this.sslEncryption = false;
+      this.degradedStatusThreshold = -1;
+      this.serverState = new ServerState();
+    }
+
+    /**
      * Get the server state.
      * @return The server state
      */
@@ -589,26 +617,10 @@
     }
 
     /**
-     * Constructs a new replication server info with the passed RSInfo
-     * internal values and the passed connected DSs.
-     * @param rsInfo The RSinfo to use for the update
-     * @param connectedDSs The new connected DSs
-     */
-    public ReplicationServerInfo(RSInfo rsInfo, Set<Integer> connectedDSs)
-    {
-      this.rsInfo = new RSInfo(rsInfo.getId(), rsInfo.getServerUrl(),
-          rsInfo.getGenerationId(), rsInfo.getGroupId(), rsInfo.getWeight());
-      this.connectedDSs = connectedDSs;
-      this.connectedDSNumber = connectedDSs.size();
-      this.degradedStatusThreshold = -1;
-      this.serverState = new ServerState();
-    }
-
-    /**
      * Converts the object to a RSInfo object.
      * @return The RSInfo object matching this object.
      */
-    public RSInfo toRSInfo()
+    RSInfo toRSInfo()
     {
       return rsInfo;
     }
@@ -619,7 +631,7 @@
      * @param rsInfo The RSinfo to use for the update
      * @param connectedDSs The new connected DSs
      */
-    public void update(RSInfo rsInfo, Set<Integer> connectedDSs)
+    private void update(RSInfo rsInfo, Set<Integer> connectedDSs)
     {
       this.rsInfo = new RSInfo(this.rsInfo.getId(), this.rsInfo.getServerUrl(),
           rsInfo.getGenerationId(), rsInfo.getGroupId(), rsInfo.getWeight());
@@ -637,16 +649,9 @@
      * Updates replication server info with the passed server state.
      * @param serverState The ServerState to use for the update
      */
-    public void update(ServerState serverState)
+    private void update(ServerState serverState)
     {
-      if (this.serverState != null)
-      {
-        this.serverState.update(serverState);
-      }
-      else
-      {
-        this.serverState = serverState;
-      }
+      this.serverState.update(serverState);
     }
 
     /**
@@ -1037,7 +1042,7 @@
    * @param dsGenId The local generation id
    * @return The initial status
    */
-  public ServerStatus computeInitialServerStatus(long rsGenId,
+  private ServerStatus computeInitialServerStatus(long rsGenId,
     ServerState rsState, int degradedStatusThreshold, long dsGenId)
   {
     if (rsGenId == -1)
@@ -1537,7 +1542,7 @@
    * disconnect (so the best replication server is another one than the current
    * one). Null can only be returned when firstConnection is false.
    */
-  public static RSEvaluations computeBestReplicationServer(
+  static RSEvaluations computeBestReplicationServer(
       boolean firstConnection, int rsServerId, ServerState myState,
       Map<Integer, ReplicationServerInfo> rsInfos, int localServerId,
       byte groupId, long generationId)
@@ -1912,7 +1917,7 @@
    *        when it is not connected to a replication server
    *        (currentRsServerId = -1)
    */
-  public static void computeBestServerForWeight(RSEvaluations evals,
+  static void computeBestServerForWeight(RSEvaluations evals,
       int currentRsServerId, int localServerId)
   {
     final Map<Integer, ReplicationServerInfo> bestServers = evals.bestRSs;
@@ -2216,7 +2221,7 @@
   /**
    * Stop the heartbeat monitor thread.
    */
-  synchronized void stopRSHeartBeatMonitoring()
+  private synchronized void stopRSHeartBeatMonitoring()
   {
     if (heartbeatMonitor != null)
     {
@@ -2240,7 +2245,7 @@
    * @param failingSession the socket which failed
    * @param infiniteTry the socket which failed
    */
-  public void reStart(Session failingSession, boolean infiniteTry)
+  private void reStart(Session failingSession, boolean infiniteTry)
   {
     if (failingSession != null)
     {
@@ -2312,7 +2317,7 @@
    * @param retryOnFailure Whether reconnect should automatically be done.
    * @return               Whether publish succeeded.
    */
-  public boolean publish(ReplicationMsg msg, boolean retryOnFailure)
+  boolean publish(ReplicationMsg msg, boolean retryOnFailure)
   {
     return publish(msg, false, retryOnFailure);
   }
@@ -2516,7 +2521,7 @@
    * @throws SocketTimeoutException if the timeout set by setSoTimeout
    *         has expired
    */
-  public ReplicationMsg receive(boolean reconnectToTheBestRS,
+  ReplicationMsg receive(boolean reconnectToTheBestRS,
       boolean reconnectOnFailure, boolean returnOnTopoChange)
     throws SocketTimeoutException
   {
@@ -2873,7 +2878,7 @@
    * @return                    A boolean indicating if the changes
    *                            requires to restart the service.
    */
-  public boolean changeConfig(ReplicationDomainCfg newConfig)
+  boolean changeConfig(ReplicationDomainCfg newConfig)
   {
     // These parameters needs to be renegotiated with the ReplicationServer
     // so if they have changed, that requires restarting the session with
@@ -3287,7 +3292,7 @@
    *
    * @return true if the server could not connect to any Replication Server.
    */
-  public boolean hasConnectionError()
+  boolean hasConnectionError()
   {
     return connectionError;
   }
@@ -3346,7 +3351,7 @@
    * Returns whether the broker is shutting down.
    * @return whether the broker is shutting down.
    */
-  public boolean shuttingDown()
+  boolean shuttingDown()
   {
     return shutdown;
   }
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java
index fca3586..de653f3 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -1129,7 +1129,7 @@
     private DirectoryException exception;
 
     /** Whether the context is related to an import or an export. */
-    private boolean importInProgress;
+    private final boolean importInProgress;
 
     /** Current counter of messages exchanged during the initialization. */
     private int msgCnt = 0;
@@ -1149,19 +1149,19 @@
      * Start time of the initialization process. ErrorMsg timestamped before
      * this startTime will be ignored.
      */
-    private long startTime;
+    private final long startTime;
 
     /**
      * List for replicas (DS) connected to the topology when initialization
      * started.
      */
-    private Set<Integer> startList = new HashSet<Integer>(0);
+    private final Set<Integer> startList = new HashSet<Integer>(0);
 
     /**
      * List for replicas (DS) with a failure (disconnected from the topology)
      * since the initialization started.
      */
-    private Set<Integer> failureList = new HashSet<Integer>(0);
+    private final Set<Integer> failureList = new HashSet<Integer>(0);
 
     /**
      * Flow control during initialization: for each remote server, counter of
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java
index 05d6db4..cc588a8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/service/ReplicationMonitor.java
@@ -42,13 +42,13 @@
  */
 public class ReplicationMonitor extends MonitorProvider<MonitorProviderCfg>
 {
-  private ReplicationDomain domain;
+  private final ReplicationDomain domain;
 
   /**
    * Create a new replication monitor.
    * @param domain the plugin which created the monitor
    */
-  public ReplicationMonitor(ReplicationDomain domain)
+  ReplicationMonitor(ReplicationDomain domain)
   {
     this.domain = domain;
   }
@@ -231,7 +231,7 @@
    * @param name the name of the attribute to add.
    * @param value The integer value of he attribute to add.
    */
-  public static void addMonitorData(List<Attribute> attributes, String name,
+  private static void addMonitorData(List<Attribute> attributes, String name,
       long value)
   {
     addMonitorData(attributes, name, String.valueOf(value));
@@ -245,7 +245,7 @@
    * @param name the name of the attribute to add.
    * @param value The String value of he attribute to add.
    */
-  public static void addMonitorData(List<Attribute> attributes, String name,
+  private static void addMonitorData(List<Attribute> attributes, String name,
       String value)
   {
     AttributeType type = DirectoryServer.getDefaultAttributeType(name);

--
Gitblit v1.10.0