From 857c966db460df76c426946b54074d004b04ef4c Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 09 Apr 2013 10:03:04 +0000
Subject: [PATCH] Fix for OPENDJ-856: Make Rest2LDAP close the cached authenticated connection.

---
 opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
index c2d87d2..51a9adb 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Utils.java
@@ -57,10 +57,10 @@
      *            The type of result.
      */
     private static final class AccumulatingResultHandler<V> implements ResultHandler<V> {
+        private ResourceException exception; // Guarded by latch.
         private final ResultHandler<List<V>> handler;
         private final AtomicInteger latch;
         private final List<V> results;
-        private ResourceException exception; // Guarded by latch.
 
         private AccumulatingResultHandler(final int size, final ResultHandler<List<V>> handler) {
             if (size <= 0) {
@@ -88,9 +88,12 @@
         }
 
         private void latch() {
-            // Invoke the handler once all results have been received. Avoid failing-fast
-            // when an error occurs because some in-flight tasks may depend on resources
-            // (e.g. connections) which are automatically closed on completion.
+            /*
+             * Invoke the handler once all results have been received. Avoid
+             * failing-fast when an error occurs because some in-flight tasks
+             * may depend on resources (e.g. connections) which are
+             * automatically closed on completion.
+             */
             if (latch.decrementAndGet() == 0) {
                 if (exception != null) {
                     handler.handleError(exception);
@@ -217,6 +220,19 @@
         return a.getAttributeDescription().withoutOption("binary").toString();
     }
 
+    /**
+     * Stub formatter for i18n strings.
+     *
+     * @param format
+     *            The format string.
+     * @param args
+     *            The string arguments.
+     * @return The formatted string.
+     */
+    static String i18n(final String format, final Object... args) {
+        return String.format(format, args);
+    }
+
     static boolean isJSONPrimitive(final Object value) {
         return value instanceof String || value instanceof Boolean || value instanceof Number;
     }
@@ -322,7 +338,7 @@
             public void handleResult(final M result) {
                 try {
                     handler.handleResult(f.apply(result, null));
-                } catch (Throwable t) {
+                } catch (final Throwable t) {
                     handler.handleError(asResourceException(t));
                 }
             }

--
Gitblit v1.10.0