From c7077670daca3b689ed75e4bf71dad0483af8473 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 19 Aug 2013 13:27:40 +0000
Subject: [PATCH] Avoided possible costly thread leaks in ReplicationServerDomain.

---
 opends/src/server/org/opends/server/replication/server/ServerHandler.java |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ServerHandler.java b/opends/src/server/org/opends/server/replication/server/ServerHandler.java
index 339ce80..18a0593 100644
--- a/opends/src/server/org/opends/server/replication/server/ServerHandler.java
+++ b/opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -155,12 +155,12 @@
 
   // window
   private int rcvWindow;
-  private int rcvWindowSizeHalf;
+  private final int rcvWindowSizeHalf;
 
   /**
    * The size of the receiving window.
    */
-  protected int maxRcvWindow;
+  protected final int maxRcvWindow;
   /**
    * Semaphore that the writer uses to control the flow to the remote server.
    */
@@ -288,7 +288,7 @@
    *
    * @throws IOException when the session becomes unavailable.
    */
-  public synchronized void decAndCheckWindow() throws IOException
+  private synchronized void decAndCheckWindow() throws IOException
   {
     rcvWindow--;
     checkWindow();
@@ -318,8 +318,7 @@
    * and monitoring system.
    * @throws DirectoryException When an exception is raised.
    */
-  protected void finalizeStart()
-  throws DirectoryException
+  protected void finalizeStart() throws DirectoryException
   {
     // FIXME:ECL We should refactor so that a SH always have a session
     if (session != null)
@@ -906,11 +905,10 @@
   /**
    * Process the reception of a WindowProbeMsg message.
    *
-   * @param  windowProbeMsg The message to process.
-   *
-   * @throws IOException    When the session becomes unavailable.
+   * @throws IOException
+   *           When the session becomes unavailable.
    */
-  public void process(WindowProbeMsg windowProbeMsg) throws IOException
+  public void replyToWindowProbe() throws IOException
   {
     if (rcvWindow > 0)
     {
@@ -1250,6 +1248,7 @@
    */
   public void put(UpdateMsg update) throws IOException
   {
+    decAndCheckWindow();
     if (replicationServerDomain!=null)
       replicationServerDomain.put(update, this);
   }
@@ -1262,4 +1261,18 @@
     if (replicationServerDomain!=null)
       replicationServerDomain.stopServer(this, false);
   }
+
+  /**
+   * Creates a ReplServerStartMsg for the current ServerHandler.
+   *
+   * @return a new ReplServerStartMsg for the current ServerHandler.
+   */
+  protected ReplServerStartMsg createReplServerStartMsg()
+  {
+    return new ReplServerStartMsg(getReplicationServerId(),
+        getReplicationServerURL(), getBaseDN(), maxRcvWindow,
+        replicationServerDomain.getDbServerState(), localGenerationId,
+        sslEncryption, getLocalGroupId(),
+        replicationServer.getDegradedStatusThreshold());
+  }
 }

--
Gitblit v1.10.0