From 32034d853f3a284424ccfa87b6de210f1ca814e1 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 29 Nov 2011 00:31:21 +0000
Subject: [PATCH] Fix OPENDJ-43 (Synchronous Connection decorator implementations should not use AsynchronousConnections) and OPENDJ-328 (Make it easier to implement connection decorators).

---
 opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java |   52 ++++++++++++++++++++++------------------------------
 1 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java b/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
index 0ee2525..1637257 100644
--- a/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
+++ b/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
+ *      Portions copyright 2011 ForgeRock AS.
  */
 
 package com.forgerock.opendj.ldap.tools;
@@ -458,14 +459,12 @@
   abstract class WorkerThread extends Thread
   {
     private int count;
-
-    private final AsynchronousConnection connection;
-
+    private final Connection connection;
     private final ConnectionFactory connectionFactory;
 
 
 
-    WorkerThread(final AsynchronousConnection connection,
+    WorkerThread(final Connection connection,
         final ConnectionFactory connectionFactory)
     {
       super("Worker Thread");
@@ -475,9 +474,8 @@
 
 
 
-    public abstract FutureResult<?> performOperation(
-        AsynchronousConnection connection, DataSource[] dataSources,
-        long startTime);
+    public abstract FutureResult<?> performOperation(Connection connection,
+        DataSource[] dataSources, long startTime);
 
 
 
@@ -485,10 +483,10 @@
     public void run()
     {
       FutureResult<?> future;
-      AsynchronousConnection connection;
+      Connection connection;
 
-      final double targetTimeInMS =
-        (1000.0 / (targetThroughput / (double) (numThreads * numConnections)));
+      final double targetTimeInMS = (1000.0 / (targetThroughput /
+          (double) (numThreads * numConnections)));
       double sleepTimeInMS = 0;
       long start;
       while (!stopRequested && !(maxIterations > 0 && count >= maxIterations))
@@ -497,8 +495,7 @@
         {
           try
           {
-            connection = connectionFactory.getAsynchronousConnection(null)
-                .get();
+            connection = connectionFactory.getConnectionAsync(null).get();
           }
           catch (final InterruptedException e)
           {
@@ -520,14 +517,12 @@
         else
         {
           connection = this.connection;
-          if (!noRebind
-              && connection instanceof AuthenticatedAsynchronousConnection)
+          if (!noRebind && connection instanceof AuthenticatedConnection)
           {
-            final AuthenticatedAsynchronousConnection ac =
-              (AuthenticatedAsynchronousConnection) connection;
+            final AuthenticatedConnection ac = (AuthenticatedConnection) connection;
             try
             {
-              ac.rebind(null).get();
+              ac.rebindAsync(null).get();
             }
             catch (final InterruptedException e)
             {
@@ -869,10 +864,9 @@
       throws ArgumentException
   {
     this.app = app;
-    numThreadsArgument = new IntegerArgument("numThreads", 't',
-        "numThreads", false, false, true,
-        LocalizableMessage.raw("{numThreads}"), 1, null, true, 1,
-        false, 0,
+    numThreadsArgument = new IntegerArgument("numThreads", 't', "numThreads",
+        false, false, true, LocalizableMessage.raw("{numThreads}"), 1, null,
+        true, 1, false, 0,
         LocalizableMessage.raw("Number of worker threads per connection"));
     numThreadsArgument.setPropertyName("numThreads");
     if (!alwaysSingleThreaded)
@@ -1003,8 +997,8 @@
   {
     numConnections = numConnectionsArgument.getIntValue();
     numThreads = numThreadsArgument.getIntValue();
-    maxIterations = maxIterationsArgument.getIntValue()
-        / numConnections / numThreads;
+    maxIterations = maxIterationsArgument.getIntValue() / numConnections
+        / numThreads;
     statsInterval = statsIntervalArgument.getIntValue() * 1000;
     targetThroughput = targetThroughputArgument.getIntValue();
 
@@ -1042,8 +1036,7 @@
 
 
 
-  abstract WorkerThread newWorkerThread(
-      final AsynchronousConnection connection,
+  abstract WorkerThread newWorkerThread(final Connection connection,
       final ConnectionFactory connectionFactory);
 
 
@@ -1055,17 +1048,16 @@
   final int run(final ConnectionFactory connectionFactory)
   {
     final List<Thread> threads = new ArrayList<Thread>();
-    final List<AsynchronousConnection> connections =
-      new ArrayList<AsynchronousConnection>();
+    final List<Connection> connections = new ArrayList<Connection>();
 
-    AsynchronousConnection connection = null;
+    Connection connection = null;
     try
     {
       for (int i = 0; i < numConnections; i++)
       {
         if (keepConnectionsOpen.isPresent() || noRebindArgument.isPresent())
         {
-          connection = connectionFactory.getAsynchronousConnection(null).get();
+          connection = connectionFactory.getConnectionAsync(null).get();
           connection.addConnectionEventListener(this);
           connections.add(connection);
         }
@@ -1098,7 +1090,7 @@
     }
     finally
     {
-      for (final AsynchronousConnection c : connections)
+      for (final Connection c : connections)
       {
         c.close();
       }

--
Gitblit v1.10.0