From 3c939842a2ec3dd32091a7c5e1e53a642b0f40ac Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 02 Aug 2016 12:23:50 +0000
Subject: [PATCH] Code cleanup, implemented toString()

---
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java           |    8 ++
 opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java                         |    6 ++
 opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java                |   10 +++
 opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java |  117 +++++++++++---------------------------
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java             |    6 ++
 5 files changed, 63 insertions(+), 84 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
index c0d4835..adb0f16 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
@@ -1950,4 +1950,10 @@
       }
     }
   }
+
+  @Override
+  public String toString()
+  {
+    return getClass().getSimpleName() + "(" + connectionWrapper + ")";
+  }
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
index c3d5fd2..78b3c86 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCacheFilter.java
@@ -117,4 +117,14 @@
   {
     return baseDNs.isEmpty();
   }
+
+  @Override
+  public String toString()
+  {
+    return getClass().getSimpleName() + "("
+        + "baseDNs=" + baseDNs
+        + ", searchMonitoringInformation=" + searchMonitoringInformation
+        + ", searchBaseDNInformation=" + searchBaseDNInformation
+        + ")";
+  }
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
index c28d00f..6ced998 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
@@ -391,4 +391,10 @@
     StaticUtils.close(connectionFactory, connection);
     StaticUtils.close(ldapContext);
   }
+
+  @Override
+  public String toString()
+  {
+    return getClass().getSimpleName() + "(" + getLdapUrl() + ")";
+  }
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
index 5509e03..89a7466 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/PreferredConnection.java
@@ -72,7 +72,7 @@
   @Override
   public int hashCode()
   {
-    return (type+ldapUrl.toLowerCase()).hashCode();
+    return (type + ldapUrl.toLowerCase()).hashCode();
   }
 
   @Override
@@ -91,6 +91,12 @@
     return false;
   }
 
+  @Override
+  public String toString()
+  {
+    return type + ": " + ldapUrl;
+  }
+
   /**
    * Commodity method that returns a PreferredConnection object with the
    * information on a given connection.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java
index 0e4f4de..2799aa6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/service/ReplicationBroker.java
@@ -80,12 +80,9 @@
 import static org.opends.server.replication.server.ReplicationServer.*;
 import static org.opends.server.util.StaticUtils.*;
 
-/**
- * The broker for Multi-master Replication.
- */
+/** The broker for Multi-master Replication. */
 public class ReplicationBroker
 {
-
   /**
    * Immutable class containing information about whether the broker is
    * connected to an RS and data associated to this connected RS.
@@ -142,7 +139,6 @@
       return session != null;
     }
 
-    /** {@inheritDoc} */
     @Override
     public String toString()
     {
@@ -166,8 +162,8 @@
           .append(")");
       }
     }
-
   }
+
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
   private volatile boolean shutdown;
   private final Object startStopLock = new Object();
@@ -216,14 +212,9 @@
    */
   private volatile boolean connectionError;
   private final Object connectPhaseLock = new Object();
-  /**
-   * The thread that publishes messages to the RS containing the current
-   * change time of this DS.
-   */
+  /** The thread that publishes messages to the RS containing the current change time of this DS. */
   private CTHeartbeatPublisherThread ctHeartbeatPublisherThread;
-  /*
-   * Properties for the last topology info received from the network.
-   */
+  /* Properties for the last topology info received from the network. */
   /** Contains the last known state of the replication topology. */
   private final AtomicReference<Topology> topology = new AtomicReference<>(new Topology());
   @GuardedBy("this")
@@ -284,9 +275,7 @@
     registerReplicationMonitor();
   }
 
-  /**
-   * Start the ReplicationBroker.
-   */
+  /** Start the ReplicationBroker. */
   public void start()
   {
     synchronized (startStopLock)
@@ -398,17 +387,15 @@
     private final short protocolVersion;
     private final DN baseDN;
     private final int windowSize;
-    // @NotNull
+    /** @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;
-    // @NotNull
+    /** @NotNull */
     private Set<Integer> connectedDSs;
-    /**
-     * Is this RS locally configured? (the RS is recognized as a usable server).
-     */
+    /** Is this RS locally configured? (the RS is recognized as a usable server). */
     private boolean locallyConfigured = true;
 
     /**
@@ -767,10 +754,7 @@
      */
     domain.toNotConnectedStatus();
 
-    /*
-    Stop any existing heartbeat monitor and changeTime publisher
-    from a previous session.
-    */
+    /* Stop any existing heartbeat monitor and changeTime publisher from a previous session. */
     stopRSHeartBeatMonitoring();
     stopChangeTimeHeartBeatPublishing();
     mustRunBestServerCheckingAlgorithm = 0;
@@ -1063,8 +1047,6 @@
     }
   }
 
-
-
   /**
    * Connect to the provided server performing the first phase handshake (start
    * messages exchange) and return the reply message from the replication
@@ -1378,7 +1360,6 @@
       return NOTE_UNKNOWN_RS.get(rsServerId, localServerId);
     }
 
-    /** {@inheritDoc} */
     @Override
     public String toString()
     {
@@ -1390,9 +1371,7 @@
     }
   }
 
-  /**
-   * Evaluation local to one filter.
-   */
+  /** Evaluation local to one filter. */
   private static class LocalEvaluation
   {
     private final Map<Integer, ReplicationServerInfo> accepted = new HashMap<>();
@@ -1436,7 +1415,6 @@
     {
       return !accepted.isEmpty();
     }
-
   }
 
   /**
@@ -1514,9 +1492,7 @@
       return evals;
     }
 
-    /**
-     * Now apply the choice based on the weight to the best servers list
-     */
+    /* Now apply the choice based on the weight to the best servers list */
     if (firstConnection)
     {
       // We are not connected to a server yet
@@ -2125,9 +2101,7 @@
     return idx != -1 && idx < overloadingDSsNumber;
   }
 
-  /**
-   * Start the heartbeat monitor thread.
-   */
+  /** Start the heartbeat monitor thread. */
   private void startRSHeartBeatMonitoring(ConnectedRS rs)
   {
     final long heartbeatInterval = config.getHeartbeatInterval();
@@ -2139,9 +2113,7 @@
     }
   }
 
-  /**
-   * Stop the heartbeat monitor thread.
-   */
+  /** Stop the heartbeat monitor thread. */
   private synchronized void stopRSHeartBeatMonitoring()
   {
     if (heartbeatMonitor != null)
@@ -2449,19 +2421,19 @@
     while (!shutdown)
     {
       ConnectedRS rs = connectedRS.get();
-      if (reconnectOnFailure && !rs.isConnected())
+      if (!rs.isConnected())
       {
-        // infinite try to reconnect
-        reStart(null, true);
-        continue;
-      }
-
-      // Save session information for later in case we need it for log messages
-      // after the session has been closed and/or failed.
-      if (rs.session == null)
-      {
-        // Must be shutting down.
-        break;
+        if (reconnectOnFailure)
+        {
+          // infinite try to reconnect
+          reStart(null, true);
+          continue;
+        }
+        else
+        {
+          // Must be shutting down.
+          break;
+        }
       }
 
       final int serverId = getServerId();
@@ -2619,7 +2591,7 @@
           reStart(rs.session, true);
         }
       }
-    } // while !shutdown
+    }
     return null;
   }
 
@@ -2824,11 +2796,7 @@
   public short getProtocolVersion()
   {
     final Session session = connectedRS.get().session;
-    if (session != null)
-    {
-      return session.getProtocolVersion();
-    }
-    return ProtocolVersion.getCurrentVersion();
+    return session != null ? session.getProtocolVersion() : ProtocolVersion.getCurrentVersion();
   }
 
   /**
@@ -2939,16 +2907,10 @@
     return newTopo;
   }
 
-  /**
-   * Contains the last known state of the replication topology.
-   */
+  /** Contains the last known state of the replication topology. */
   static final class Topology
   {
-
-    /**
-     * The RS's serverId that this DS was connected to when this topology state
-     * was computed.
-     */
+    /** The RS's serverId that this DS was connected to when this topology state was computed. */
     private final int rsServerId;
     /**
      * Info for other DSs.
@@ -3130,7 +3092,6 @@
       rsInfo.setLocallyConfigured(false);
     }
 
-    /** {@inheritDoc} */
     @Override
     public boolean equals(Object obj)
     {
@@ -3178,7 +3139,6 @@
       return true;
     }
 
-    /** {@inheritDoc} */
     @Override
     public int hashCode()
     {
@@ -3191,7 +3151,6 @@
       return result;
     }
 
-    /** {@inheritDoc} */
     @Override
     public String toString()
     {
@@ -3213,9 +3172,7 @@
     return connectionError;
   }
 
-  /**
-   * Starts publishing to the RS the current timestamp used in this server.
-   */
+  /** Starts publishing to the RS the current timestamp used in this server. */
   private void startChangeTimeHeartBeatPublishing(ConnectedRS rs)
   {
     // Start a CSN heartbeat thread.
@@ -3230,18 +3187,13 @@
           threadName, rs.session, changeTimeHeartbeatInterval, getServerId());
       ctHeartbeatPublisherThread.start();
     }
-    else
+    else if (logger.isTraceEnabled())
     {
-      if (logger.isTraceEnabled())
-      {
-        debugInfo("is not configured to send CSN heartbeat interval");
-      }
+      debugInfo("is not configured to send CSN heartbeat interval");
     }
   }
 
-  /**
-   * Stops publishing to the RS the current timestamp used in this server.
-   */
+  /** Stops publishing to the RS the current timestamp used in this server. */
   private synchronized void stopChangeTimeHeartBeatPublishing()
   {
     if (ctHeartbeatPublisherThread != null)
@@ -3300,7 +3252,7 @@
   private ConnectedRS setConnectedRS(final ConnectedRS newRS)
   {
     final ConnectedRS oldRS = connectedRS.getAndSet(newRS);
-    if (!oldRS.equals(newRS) && oldRS.session != null)
+    if (!oldRS.equals(newRS) && oldRS.isConnected())
     {
       // monitor name is changing, deregister before registering again
       deregisterReplicationMonitor();
@@ -3337,7 +3289,6 @@
     }
   }
 
-  /** {@inheritDoc} */
   @Override
   public String toString()
   {

--
Gitblit v1.10.0