From 057a5631ed5dea85a26c26ada109338029a8c20f Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 11 Jan 2012 22:47:25 +0000
Subject: [PATCH] Fix OPENDJ-401: Replication fails with Java 7.

---
 opends/src/server/org/opends/server/replication/service/ReplicationBroker.java |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

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 6e254d8..b0be403 100644
--- a/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011 ForgeRock AS
+ *      Portions Copyright 2011-2012 ForgeRock AS
  */
 package org.opends.server.replication.service;
 
@@ -953,7 +953,23 @@
                 connectionError = false;
                 if (sendWindow != null)
                 {
-                  sendWindow.release(Integer.MAX_VALUE);
+                  /*
+                   * Fix (hack) for OPENDJ-401: we want to ensure that no
+                   * threads holding this semaphore will get blocked when they
+                   * acquire it. However, we also need to make sure that we
+                   * don't overflow the semaphore by releasing too many permits.
+                   */
+                  final int MAX_PERMITS = (Integer.MAX_VALUE >>> 2);
+                  if (sendWindow.availablePermits() < MAX_PERMITS)
+                  {
+                    /*
+                     * At least 2^29 acquisitions would need to occur for this
+                     * to be insufficient. In addition, at least 2^30 releases
+                     * would need to occur for this to potentially overflow.
+                     * Hopefully this is unlikely to happen.
+                     */
+                    sendWindow.release(MAX_PERMITS);
+                  }
                 }
                 sendWindow = new Semaphore(maxSendWindow);
                 rcvWindow = maxRcvWindow;

--
Gitblit v1.10.0