From ad636a8035cc19f5a412b6b97b3f95ba37d0fe9a Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 30 Aug 2013 14:25:48 +0000
Subject: [PATCH] Back-port fix for OPENDJ-1112: LoadBalancing connection factories need better diagnostic messages

---
 opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/RoundRobinLoadBalancingAlgorithm.java |   73 +++++++++++++++++++++++++++++++++---
 1 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/RoundRobinLoadBalancingAlgorithm.java b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/RoundRobinLoadBalancingAlgorithm.java
index 2726a89..236f070 100644
--- a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/RoundRobinLoadBalancingAlgorithm.java
+++ b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/RoundRobinLoadBalancingAlgorithm.java
@@ -22,6 +22,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
+ *      Portions copyright 2013 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldap;
@@ -55,7 +56,6 @@
  */
 public final class RoundRobinLoadBalancingAlgorithm extends AbstractLoadBalancingAlgorithm {
     private final int maxIndex;
-
     private final AtomicInteger nextIndex = new AtomicInteger(-1);
 
     /**
@@ -66,7 +66,70 @@
      *            The ordered collection of connection factories.
      */
     public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories) {
-        super(factories);
+        this(factories, null, 1, TimeUnit.SECONDS, null);
+    }
+
+    /**
+     * Creates a new round robin load balancing algorithm which will monitor
+     * offline connection factories every 1 second using the default scheduler.
+     *
+     * @param factories
+     *            The ordered collection of connection factories.
+     * @param listener
+     *            The event listener which should be notified whenever a
+     *            connection factory changes state from online to offline or
+     *            vice-versa.
+     */
+    public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories,
+            final LoadBalancerEventListener listener) {
+        this(factories, listener, 1, TimeUnit.SECONDS, null);
+    }
+
+    /**
+     * Creates a new round robin load balancing algorithm which will monitor
+     * offline connection factories using the specified frequency using the
+     * default scheduler.
+     *
+     * @param factories
+     *            The connection factories.
+     * @param listener
+     *            The event listener which should be notified whenever a
+     *            connection factory changes state from online to offline or
+     *            vice-versa.
+     * @param interval
+     *            The interval between attempts to poll offline factories.
+     * @param unit
+     *            The time unit for the interval between attempts to poll
+     *            offline factories.
+     */
+    public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories,
+            final LoadBalancerEventListener listener, final long interval, final TimeUnit unit) {
+        this(factories, null, interval, unit, null);
+    }
+
+    /**
+     * Creates a new round robin load balancing algorithm which will monitor
+     * offline connection factories using the specified frequency and scheduler.
+     *
+     * @param factories
+     *            The connection factories.
+     * @param listener
+     *            The event listener which should be notified whenever a
+     *            connection factory changes state from online to offline or
+     *            vice-versa.
+     * @param interval
+     *            The interval between attempts to poll offline factories.
+     * @param unit
+     *            The time unit for the interval between attempts to poll
+     *            offline factories.
+     * @param scheduler
+     *            The scheduler which should for periodically monitoring dead
+     *            connection factories to see if they are usable again.
+     */
+    public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories,
+            final LoadBalancerEventListener listener, final long interval, final TimeUnit unit,
+            final ScheduledExecutorService scheduler) {
+        super(factories, listener, interval, unit, scheduler);
         this.maxIndex = factories.size();
     }
 
@@ -85,8 +148,7 @@
      */
     public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories,
             final long interval, final TimeUnit unit) {
-        super(factories, interval, unit);
-        this.maxIndex = factories.size();
+        this(factories, null, interval, unit, null);
     }
 
     /**
@@ -106,8 +168,7 @@
      */
     public RoundRobinLoadBalancingAlgorithm(final Collection<ConnectionFactory> factories,
             final long interval, final TimeUnit unit, final ScheduledExecutorService scheduler) {
-        super(factories, interval, unit, scheduler);
-        this.maxIndex = factories.size();
+        this(factories, null, interval, unit, scheduler);
     }
 
     /**

--
Gitblit v1.10.0