From a415256cc798baf286d618a2c9ddd427c26a518d Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 14 Dec 2009 13:21:39 +0000
Subject: [PATCH] Remove optional P parameter from result handlers as it is hardly ever needed in practice and just pollutes the APIs.

---
 sdk/src/com/sun/opends/sdk/ldap/AbstractResultFutureImpl.java |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/sdk/src/com/sun/opends/sdk/ldap/AbstractResultFutureImpl.java b/sdk/src/com/sun/opends/sdk/ldap/AbstractResultFutureImpl.java
index 7cb7dc1..66dc52f 100644
--- a/sdk/src/com/sun/opends/sdk/ldap/AbstractResultFutureImpl.java
+++ b/sdk/src/com/sun/opends/sdk/ldap/AbstractResultFutureImpl.java
@@ -47,23 +47,23 @@
 /**
  * Abstract result future implementation.
  */
-public abstract class AbstractResultFutureImpl<R extends Result, P> implements
-    ResultFuture<R>, Runnable
+public abstract class AbstractResultFutureImpl<R extends Result>
+    implements ResultFuture<R>, Runnable
 {
   private final LDAPConnection connection;
 
-  private final ResultHandler<? super R, P> handler;
+  private final ResultHandler<? super R> handler;
 
   private final ExecutorService handlerExecutor;
 
   private final int messageID;
 
+  // Use a semaphore instead of a lock because semaphores can be
+  // released by different thread to acquirer.
   private final Semaphore invokerLock;
 
   private final CountDownLatch latch = new CountDownLatch(1);
 
-  private final P p;
-
   private volatile boolean isCancelled = false;
 
   private volatile R result = null;
@@ -71,12 +71,11 @@
 
 
   AbstractResultFutureImpl(int messageID,
-      ResultHandler<? super R, P> handler, P p,
-      LDAPConnection connection, ExecutorService handlerExecutor)
+      ResultHandler<? super R> handler, LDAPConnection connection,
+      ExecutorService handlerExecutor)
   {
     this.messageID = messageID;
     this.handler = handler;
-    this.p = p;
     this.connection = connection;
     this.handlerExecutor = handlerExecutor;
     if (handlerExecutor == null)
@@ -155,17 +154,17 @@
     if (result.getResultCode().isExceptional())
     {
       ErrorResultException e = ErrorResultException.wrap(result);
-      handler.handleErrorResult(p, e);
+      handler.handleErrorResult(e);
     }
     else
     {
-      handler.handleResult(p, result);
+      handler.handleResult(result);
     }
   }
 
 
 
-  synchronized void handleErrorResult(Result result)
+  final void handleErrorResult(Result result)
   {
     R errorResult = newErrorResult(result.getResultCode(), result
         .getDiagnosticMessage(), result.getCause());
@@ -179,7 +178,7 @@
 
 
 
-  void handleResult(R result)
+  final void handleResult(R result)
   {
     if (!isDone())
     {
@@ -194,7 +193,7 @@
 
 
 
-  protected void invokeHandler(final Runnable runnable)
+  final void invokeHandler(final Runnable runnable)
   {
     try
     {
@@ -238,6 +237,9 @@
             "Invoke thread interrupted: %s", StaticUtils
                 .getExceptionMessage(e)));
       }
+
+      // Reset interrupt status.
+      Thread.currentThread().interrupt();
     }
   }
 
@@ -247,8 +249,8 @@
   {
     if (isCancelled())
     {
-      throw ErrorResultException.wrap(
-          Responses.newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED));
+      throw ErrorResultException.wrap(Responses
+          .newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED));
     }
     else if (result.getResultCode().isExceptional())
     {

--
Gitblit v1.10.0