From fe858f5b8c261e991c80554bc80d28c1009df1eb Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 07 Feb 2012 23:09:46 +0000
Subject: [PATCH] Minor code cleanup.

---
 opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java |   45 ++++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
index c7a6829..4b11b85 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPConnectionFactoryImpl.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2011 ForgeRock AS
+ *      Portions copyright 2011-2012 ForgeRock AS
  */
 
 package com.forgerock.opendj.ldap;
@@ -63,18 +63,18 @@
 {
 
   @SuppressWarnings("rawtypes")
-  private final class FutureResultImpl implements
+  private final class ConnectionCompletionHandler implements
       CompletionHandler<org.glassfish.grizzly.Connection>
   {
-    private final FutureResultTransformer<Result, Connection> futureStartTLSResult;
-    private final RecursiveFutureResult<LDAPConnection, ExtendedResult> futureConnectionResult;
+    private final FutureResultTransformer<Result, Connection> startTLSFutureResult;
+    private final RecursiveFutureResult<LDAPConnection, ExtendedResult> connectionFutureResult;
     private LDAPConnection connection;
 
 
 
-    private FutureResultImpl(final ResultHandler<? super Connection> handler)
+    private ConnectionCompletionHandler(final ResultHandler<? super Connection> handler)
     {
-      this.futureStartTLSResult = new FutureResultTransformer<Result, Connection>(
+      this.startTLSFutureResult = new FutureResultTransformer<Result, Connection>(
           handler)
       {
 
@@ -108,8 +108,8 @@
 
       };
 
-      this.futureConnectionResult = new RecursiveFutureResult<LDAPConnection, ExtendedResult>(
-          futureStartTLSResult)
+      this.connectionFutureResult = new RecursiveFutureResult<LDAPConnection, ExtendedResult>(
+          startTLSFutureResult)
       {
 
         @Override
@@ -122,6 +122,7 @@
 
           if (options.getSSLContext() != null && options.useStartTLS())
           {
+            // Chain StartTLS extended request.
             final StartTLSExtendedRequest startTLS = Requests
                 .newStartTLSExtendedRequest(options.getSSLContext());
             startTLS.addEnabledCipherSuite(options.getEnabledCipherSuites()
@@ -130,9 +131,9 @@
                 new String[options.getEnabledProtocols().size()]));
             return connection.extendedRequestAsync(startTLS, null, handler);
           }
-
-          if (options.getSSLContext() != null)
+          else if (options.getSSLContext() != null)
           {
+            // Install SSL/TLS layer.
             try
             {
               connection.startTLS(options.getSSLContext(),
@@ -164,14 +165,18 @@
                   ioe.getMessage(), ioe);
             }
           }
-          handler.handleResult(null);
-          return new CompletedFutureResult<ExtendedResult>(
-              (ExtendedResult) null);
+          else
+          {
+            // Plain connection.
+            handler.handleResult(null);
+            return new CompletedFutureResult<ExtendedResult>(
+                (ExtendedResult) null);
+          }
         }
 
       };
 
-      futureStartTLSResult.setFutureResult(futureConnectionResult);
+      startTLSFutureResult.setFutureResult(connectionFutureResult);
     }
 
 
@@ -193,7 +198,7 @@
     @Override
     public void completed(final org.glassfish.grizzly.Connection connection)
     {
-      futureConnectionResult.handleResult(adaptConnection(connection));
+      connectionFutureResult.handleResult(adaptConnection(connection));
     }
 
 
@@ -204,7 +209,7 @@
     @Override
     public void failed(final Throwable throwable)
     {
-      futureConnectionResult
+      connectionFutureResult
           .handleErrorResult(adaptConnectionException(throwable));
     }
 
@@ -282,13 +287,11 @@
   public FutureResult<Connection> getConnectionAsync(
       final ResultHandler<? super Connection> handler)
   {
-    final FutureResultImpl future = new FutureResultImpl(handler);
-
+    final ConnectionCompletionHandler ch = new ConnectionCompletionHandler(handler);
     try
     {
-      future.futureConnectionResult.setFutureResult(transport.connect(
-          socketAddress, future));
-      return future.futureStartTLSResult;
+      ch.connectionFutureResult.setFutureResult(transport.connect(socketAddress, ch));
+      return ch.startTLSFutureResult;
     }
     catch (final IOException e)
     {

--
Gitblit v1.10.0