From d709a2e4eecc9773af376587c476e33f0ccefce5 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 20 May 2014 15:09: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.

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

diff --git a/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java b/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
index 6b090d9..f509938 100644
--- a/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
+++ b/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
@@ -45,7 +45,7 @@
  * <p>
  * These heartbeat messages are sent by a replica directory server.
  */
-public class CTHeartbeatPublisherThread extends DirectoryThread
+class CTHeartbeatPublisherThread extends DirectoryThread
 {
   /**
    * The tracer object for the debug logger.
@@ -77,8 +77,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;
@@ -180,7 +180,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/opends/src/server/org/opends/server/replication/service/ReplInputStream.java b/opends/src/server/org/opends/server/replication/service/ReplInputStream.java
index 170fbd3..cf41e82 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplInputStream.java
+++ b/opends/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/opends/src/server/org/opends/server/replication/service/ReplOutputStream.java b/opends/src/server/org/opends/server/replication/service/ReplOutputStream.java
index df80815..d94a8da 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplOutputStream.java
+++ b/opends/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/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java b/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
index 5fea64d..251202a 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -163,14 +163,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>
@@ -181,7 +181,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.
@@ -384,17 +384,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).
@@ -410,7 +412,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);
@@ -426,7 +428,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)
@@ -459,7 +461,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();
     }
@@ -478,13 +481,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
      */
@@ -596,26 +624,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;
     }
@@ -626,7 +638,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());
@@ -644,16 +656,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);
     }
 
     /**
@@ -1050,7 +1055,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)
@@ -1554,7 +1559,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)
@@ -1929,7 +1934,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;
@@ -2233,7 +2238,7 @@
   /**
    * Stop the heartbeat monitor thread.
    */
-  synchronized void stopRSHeartBeatMonitoring()
+  private synchronized void stopRSHeartBeatMonitoring()
   {
     if (heartbeatMonitor != null)
     {
@@ -2257,7 +2262,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)
     {
@@ -2332,7 +2337,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);
   }
@@ -2536,7 +2541,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
   {
@@ -2898,7 +2903,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
@@ -3315,7 +3320,7 @@
    *
    * @return true if the server could not connect to any Replication Server.
    */
-  public boolean hasConnectionError()
+  boolean hasConnectionError()
   {
     return connectionError;
   }
@@ -3374,7 +3379,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/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java b/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
index 2ecdcf7..d539630 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
+++ b/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -1141,7 +1141,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;
@@ -1161,19 +1161,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/opends/src/server/org/opends/server/replication/service/ReplicationMonitor.java b/opends/src/server/org/opends/server/replication/service/ReplicationMonitor.java
index ec307b8..7f47879 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplicationMonitor.java
+++ b/opends/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;
   }
@@ -233,7 +233,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)
   {
     AttributeType type = DirectoryServer.getDefaultAttributeType(name);
@@ -249,7 +249,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