From 19abb998c9b5d5dca4f7376faced7f89cf85163d Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 29 Aug 2013 21:01:42 +0000
Subject: [PATCH] Partial fix for OPENDJ-1112: LoadBalancing connection factories need better diagnostic messages

---
 opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithm.java |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithm.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithm.java
index a868df4..2a4aaed 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithm.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithm.java
@@ -162,6 +162,9 @@
         }
 
         private void notifyOffline(final ErrorResultException error) {
+            // Save the error in case the load-balancer is exhausted.
+            lastFailure = error;
+
             if (isOperational.getAndSet(false)) {
                 // Transition from online to offline.
                 if (DEBUG_LOG.isLoggable(Level.WARNING)) {
@@ -225,6 +228,14 @@
     private final List<MonitoredConnectionFactory> monitoredFactories;
     private final ReferenceCountedObject<ScheduledExecutorService>.Reference scheduler;
     private final Object stateLock = new Object();
+
+    /**
+     * The last connection failure which caused a connection factory to be
+     * marked offline. This is used in order to help diagnose problems when the
+     * load-balancer has exhausted all of its factories.
+     */
+    private volatile ErrorResultException lastFailure = null;
+
     /**
      * Guarded by stateLock.
      */
@@ -335,6 +346,6 @@
          * timeout period.
          */
         throw newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR,
-                "No operational connection factories available");
+                "No operational connection factories available", lastFailure);
     }
 }

--
Gitblit v1.10.0