From b1d02ff4ce3ae2b9446c222d10d9e8a136afbd63 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 06 Dec 2010 08:09:03 +0000
Subject: [PATCH] Bring in OpenDS commit from Matthew Swift. Update to latest Grizzly. Refactor default transport factory implementation so that it does not conflict with transports used by other Grizzly based services (e.g HTTP).

---
 opendj-sdk/sdk/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactory.java                                 |  170 +++++++++++++++++
 opendj-sdk/sdk/src/com/sun/opends/sdk/tools/SearchRate.java                                                     |    6 
 opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransport.java                                      |   80 ++++++++
 opendj-sdk/sdk/lib/grizzly.jar                                                                                  |    0 
 opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java                                       |    3 
 opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferReaderTestCase.java                |    8 
 opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java |   21 +
 opendj-sdk/sdk/src/com/sun/opends/sdk/tools/ModRate.java                                                        |    6 
 /dev/null                                                                                                       |  207 --------------------
 opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferReader.java                                                |    4 
 opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferWriterTestCase.java                |    3 
 opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransportTestCase.java      |   19 +
 opendj-sdk/sdk/src/com/sun/opends/sdk/tools/AuthRate.java                                                       |    9 
 opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java                                                |    3 
 opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferWriter.java                                                |   10 
 15 files changed, 289 insertions(+), 260 deletions(-)

diff --git a/opendj-sdk/sdk/lib/grizzly.jar b/opendj-sdk/sdk/lib/grizzly.jar
index ab8e441..f384221 100644
--- a/opendj-sdk/sdk/lib/grizzly.jar
+++ b/opendj-sdk/sdk/lib/grizzly.jar
Binary files differ
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferReader.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferReader.java
index 78ff32d..55d3c98 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferReader.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferReader.java
@@ -46,7 +46,7 @@
 import org.opends.sdk.asn1.AbstractASN1Reader;
 
 import org.glassfish.grizzly.Buffer;
-import org.glassfish.grizzly.memory.ByteBuffersBuffer;
+import org.glassfish.grizzly.memory.BuffersBuffer;
 import org.glassfish.grizzly.memory.CompositeBuffer;
 import com.sun.opends.sdk.util.StaticUtils;
 
@@ -232,7 +232,7 @@
     this.readLimiter = new RootSequenceLimiter();
     this.stringBuffer = new byte[MAX_STRING_BUFFER_SIZE];
     this.maxElementSize = maxElementSize;
-    this.buffer = ByteBuffersBuffer.create();
+    this.buffer = BuffersBuffer.create();
   }
 
 
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferWriter.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferWriter.java
index 2f3e8e5..a5b7ab8 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferWriter.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/ASN1BufferWriter.java
@@ -155,15 +155,6 @@
         visible = newByteBuffer.put(visible);
       }
     }
-
-
-
-    @Override
-    public ByteBufferWrapper flip()
-    {
-      usable = false;
-      return super.flip();
-    }
   }
 
 
@@ -697,6 +688,7 @@
 
   Buffer getBuffer()
   {
+    outBuffer.usable = false;
     return outBuffer.flip();
   }
 
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/GlobalTransportFactory.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/GlobalTransportFactory.java
deleted file mode 100644
index a4d92bc..0000000
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/GlobalTransportFactory.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2010 Sun Microsystems, Inc.
- */
-
-package com.sun.opends.sdk.ldap;
-
-
-
-import java.io.IOException;
-
-import org.glassfish.grizzly.TransportFactory;
-import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
-import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
-import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
-
-import com.sun.opends.sdk.util.StaticUtils;
-
-
-
-/**
- * A static Grizzly transport that can be used by default globally in the SDK.
- */
-public final class GlobalTransportFactory extends TransportFactory
-{
-  private static boolean isInitialized = false;
-
-
-
-  /**
-   * Returns the global Grizzly transport factory.
-   *
-   * @return The global Grizzly transport factory.
-   */
-  public static synchronized TransportFactory getInstance()
-  {
-    if (!isInitialized)
-    {
-      TransportFactory.setInstance(new GlobalTransportFactory());
-      isInitialized = true;
-    }
-    return TransportFactory.getInstance();
-  }
-
-
-
-  private int selectors;
-
-  private int linger = -1;
-
-  private boolean tcpNoDelay = true;
-
-  private boolean reuseAddress = true;
-
-  private TCPNIOTransport globalTCPNIOTransport = null;
-
-
-
-  private GlobalTransportFactory()
-  {
-    // Prevent instantiation.
-  }
-
-
-
-  /**
-   * Close the {@link org.glassfish.grizzly.TransportFactory} and release all
-   * resources.
-   */
-  @Override
-  public synchronized void close()
-  {
-    if (globalTCPNIOTransport != null)
-    {
-      try
-      {
-        globalTCPNIOTransport.stop();
-      }
-      catch (final IOException e)
-      {
-        StaticUtils.DEBUG_LOG
-            .warning("Error shutting down Grizzly TCP NIO transport: " + e);
-      }
-    }
-    super.close();
-  }
-
-
-
-  /**
-   * Create instance of TCP {@link org.glassfish.grizzly.Transport}.
-   *
-   * @return instance of TCP {@link org.glassfish.grizzly.Transport}.
-   */
-  @Override
-  public synchronized TCPNIOTransport createTCPTransport()
-  {
-    if (globalTCPNIOTransport == null)
-    {
-      globalTCPNIOTransport = setupTransport(new TCPNIOTransport());
-      globalTCPNIOTransport.setSelectorRunnersCount(selectors);
-      globalTCPNIOTransport.setLinger(linger);
-      globalTCPNIOTransport.setTcpNoDelay(tcpNoDelay);
-      globalTCPNIOTransport.setReuseAddress(reuseAddress);
-
-      try
-      {
-        globalTCPNIOTransport.start();
-      }
-      catch (final IOException e)
-      {
-        throw new RuntimeException(
-            "Unable to create default connection factory provider", e);
-      }
-    }
-    return globalTCPNIOTransport;
-  }
-
-
-
-  /**
-   * Creating an UDP transport is unsupported with this factory. A
-   * {@code UnsupportedOperationException} will be thrown when this method is
-   * called.
-   *
-   * @return This method will always throw {@code UnsupportedOperationException}
-   *         .
-   */
-  @Override
-  public UDPNIOTransport createUDPTransport()
-  {
-    throw new UnsupportedOperationException();
-  }
-
-
-
-  @Override
-  public void initialize()
-  {
-    final int cpus = Runtime.getRuntime().availableProcessors();
-    int threads = Math.max(5, (cpus / 2) - 1);
-    selectors = Math.max(2, cpus / 8);
-
-    final String threadsStr = System
-        .getProperty("org.opends.sdk.ldap.transport.threads");
-    if (threadsStr != null)
-    {
-      threads = Integer.parseInt(threadsStr);
-    }
-    final String selectorsStr = System
-        .getProperty("org.opends.sdk.ldap.transport.selectors");
-    if (threadsStr != null)
-    {
-      selectors = Integer.parseInt(selectorsStr);
-    }
-
-    ThreadPoolConfig.DEFAULT.setCorePoolSize(threads);
-    ThreadPoolConfig.DEFAULT.setMaxPoolSize(threads);
-    ThreadPoolConfig.DEFAULT.setPoolName("OpenDS SDK Worker(Grizzly)");
-
-    final String lingerStr = System
-        .getProperty("org.opends.sdk.ldap.transport.linger");
-    if (lingerStr != null)
-    {
-      linger = Integer.parseInt(lingerStr);
-    }
-
-    final String tcpNoDelayStr = System
-        .getProperty("org.opends.sdk.ldap.transport.tcpNoDelay");
-    if (tcpNoDelayStr != null)
-    {
-      tcpNoDelay = Integer.parseInt(tcpNoDelayStr) != 0;
-    }
-
-    final String reuseAddressStr = System
-        .getProperty("org.opends.sdk.ldap.transport.reuseAddress");
-    if (reuseAddressStr != null)
-    {
-      reuseAddress = Integer.parseInt(reuseAddressStr) != 0;
-    }
-
-    super.initialize();
-  }
-
-}
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java
index fc08a15..699a24a 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java
@@ -255,8 +255,7 @@
   {
     if (options.getTCPNIOTransport() == null)
     {
-      this.transport = GlobalTransportFactory.getInstance()
-          .createTCPTransport();
+      this.transport = LDAPDefaultTCPNIOTransport.getInstance();
     }
     else
     {
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransport.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransport.java
new file mode 100644
index 0000000..5a6502c
--- /dev/null
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransport.java
@@ -0,0 +1,80 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2010 Sun Microsystems, Inc.
+ */
+
+package com.sun.opends.sdk.ldap;
+
+
+
+import java.io.IOException;
+
+import org.glassfish.grizzly.TransportFactory;
+import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
+
+
+
+/**
+ * The default TCPNIOTransport which all LDAPConnectionFactories and
+ * LDAPListeners will use unless otherwise specified in their options.
+ */
+final class LDAPDefaultTCPNIOTransport
+{
+  private static final TCPNIOTransport DEFAULT_TRANSPORT = TransportFactory
+      .getInstance().createTCPTransport();
+
+  static
+  {
+    try
+    {
+      DEFAULT_TRANSPORT.start();
+    }
+    catch (final IOException e)
+    {
+      throw new RuntimeException(e);
+    }
+  }
+
+
+
+  /**
+   * Returns the default TCPNIOTransport which all LDAPConnectionFactories and
+   * LDAPListeners will use unless otherwise specified in their options.
+   *
+   * @return The default TCPNIOTransport.
+   */
+  public static TCPNIOTransport getInstance()
+  {
+    return DEFAULT_TRANSPORT;
+  }
+
+
+
+  private LDAPDefaultTCPNIOTransport()
+  {
+    // Prevent instantiation.
+  }
+
+}
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java
index 67833c4..abbfea1 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java
@@ -85,8 +85,7 @@
   {
     if (options.getTCPNIOTransport() == null)
     {
-      this.transport = GlobalTransportFactory.getInstance()
-          .createTCPTransport();
+      this.transport = LDAPDefaultTCPNIOTransport.getInstance();
     }
     else
     {
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/AuthRate.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/AuthRate.java
index d5c4fca..e8b8f99 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/AuthRate.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/AuthRate.java
@@ -28,6 +28,8 @@
 package com.sun.opends.sdk.tools;
 
 import com.sun.opends.sdk.util.RecursiveFutureResult;
+
+import org.glassfish.grizzly.TransportFactory;
 import org.opends.sdk.*;
 import org.opends.sdk.requests.*;
 import org.opends.sdk.responses.BindResult;
@@ -601,12 +603,9 @@
 
     try
     {
-      if(System.getProperty("org.opends.sdk.ldap.transport.linger") == null)
-      {
-        System.setProperty("org.opends.sdk.ldap.transport.linger", "0");
-      }
+      TransportFactory.setInstance(new PerfToolTCPNIOTransportFactory());
       connectionFactoryProvider =
-          new ConnectionFactoryProvider(argParser, this);
+        new ConnectionFactoryProvider(argParser, this);
       runner = new BindPerformanceRunner(argParser, this);
 
       propertiesFileArgument = new StringArgument("propertiesFilePath", null,
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/ModRate.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/ModRate.java
index 48134c9..360f490 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/ModRate.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/ModRate.java
@@ -36,6 +36,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.glassfish.grizzly.TransportFactory;
 import org.opends.sdk.*;
 import org.opends.sdk.requests.ModifyRequest;
 import org.opends.sdk.requests.Requests;
@@ -328,10 +329,7 @@
 
     try
     {
-      if(System.getProperty("org.opends.sdk.ldap.transport.linger") == null)
-      {
-        System.setProperty("org.opends.sdk.ldap.transport.linger", "0");
-      }
+      TransportFactory.setInstance(new PerfToolTCPNIOTransportFactory());
       connectionFactoryProvider =
           new ConnectionFactoryProvider(argParser, this);
       runner = new ModifyPerformanceRunner(argParser, this);
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactory.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactory.java
new file mode 100644
index 0000000..1f6a1ec
--- /dev/null
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactory.java
@@ -0,0 +1,170 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2010 Sun Microsystems, Inc.
+ */
+
+package com.sun.opends.sdk.tools;
+
+
+
+import org.glassfish.grizzly.Grizzly;
+import org.glassfish.grizzly.memory.HeapMemoryManager;
+import org.glassfish.grizzly.nio.DefaultNIOTransportFactory;
+import org.glassfish.grizzly.nio.DefaultSelectionKeyHandler;
+import org.glassfish.grizzly.nio.DefaultSelectorHandler;
+import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorPool;
+import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
+import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
+import org.glassfish.grizzly.threadpool.AbstractThreadPool;
+import org.glassfish.grizzly.threadpool.GrizzlyExecutorService;
+import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
+
+
+
+/**
+ * The TCPNIOTransportFactory which performance tools will use.
+ */
+final class PerfToolTCPNIOTransportFactory extends DefaultNIOTransportFactory
+{
+  private int selectors;
+
+  private int linger = 0;
+
+  private boolean tcpNoDelay = true;
+
+  private boolean reuseAddress = true;
+
+  private TCPNIOTransport singletonTransport = null;
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public synchronized TCPNIOTransport createTCPTransport()
+  {
+    if (singletonTransport == null)
+    {
+      singletonTransport = super.createTCPTransport();
+
+      singletonTransport.setSelectorRunnersCount(selectors);
+      singletonTransport.setLinger(linger);
+      singletonTransport.setTcpNoDelay(tcpNoDelay);
+      singletonTransport.setReuseAddress(reuseAddress);
+    }
+
+    return singletonTransport;
+  }
+
+
+
+  /**
+   * Creating an UDP transport is unsupported with this factory. A
+   * {@code UnsupportedOperationException} will be thrown when this method is
+   * called.
+   *
+   * @return This method will always throw {@code UnsupportedOperationException}
+   *         .
+   */
+  @Override
+  public UDPNIOTransport createUDPTransport()
+  {
+    throw new UnsupportedOperationException();
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void initialize()
+  {
+    final int cpus = Runtime.getRuntime().availableProcessors();
+    int threads = Math.max(5, (cpus / 2) - 1);
+    selectors = Math.max(2, cpus / 8);
+
+    final String threadsStr = System
+        .getProperty("org.opends.sdk.ldap.transport.threads");
+    if (threadsStr != null)
+    {
+      threads = Integer.parseInt(threadsStr);
+    }
+    final String selectorsStr = System
+        .getProperty("org.opends.sdk.ldap.transport.selectors");
+    if (threadsStr != null)
+    {
+      selectors = Integer.parseInt(selectorsStr);
+    }
+
+    final String lingerStr = System
+        .getProperty("org.opends.sdk.ldap.transport.linger");
+    if (lingerStr != null)
+    {
+      linger = Integer.parseInt(lingerStr);
+    }
+
+    final String tcpNoDelayStr = System
+        .getProperty("org.opends.sdk.ldap.transport.tcpNoDelay");
+    if (tcpNoDelayStr != null)
+    {
+      tcpNoDelay = Integer.parseInt(tcpNoDelayStr) != 0;
+    }
+
+    final String reuseAddressStr = System
+        .getProperty("org.opends.sdk.ldap.transport.reuseAddress");
+    if (reuseAddressStr != null)
+    {
+      reuseAddress = Integer.parseInt(reuseAddressStr) != 0;
+    }
+
+    // Copied from TransportFactory.
+    defaultAttributeBuilder = Grizzly.DEFAULT_ATTRIBUTE_BUILDER;
+    defaultMemoryManager = new HeapMemoryManager();
+    defaultWorkerThreadPool = GrizzlyExecutorService
+        .createInstance(ThreadPoolConfig.defaultConfig()
+            .setMemoryManager(defaultMemoryManager).setCorePoolSize(threads)
+            .setMaxPoolSize(threads).setPoolName("OpenDS SDK Worker(Grizzly)"));
+
+    // Copied from NIOTransportFactory.
+    defaultSelectorHandler = new DefaultSelectorHandler();
+    defaultSelectionKeyHandler = new DefaultSelectionKeyHandler();
+
+    /*
+     * By default TemporarySelector pool size should be equal to the number of
+     * processing threads
+     */
+    int selectorPoolSize = TemporarySelectorPool.DEFAULT_SELECTORS_COUNT;
+    if (defaultWorkerThreadPool instanceof AbstractThreadPool)
+    {
+      selectorPoolSize = Math.min(
+          ((AbstractThreadPool) defaultWorkerThreadPool).getConfig()
+              .getMaxPoolSize(), selectorPoolSize);
+    }
+    defaultTemporarySelectorPool = new TemporarySelectorPool(selectorPoolSize);
+  }
+
+}
diff --git a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/SearchRate.java b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/SearchRate.java
index 30613fe..332f510 100644
--- a/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/SearchRate.java
+++ b/opendj-sdk/sdk/src/com/sun/opends/sdk/tools/SearchRate.java
@@ -40,6 +40,7 @@
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.glassfish.grizzly.TransportFactory;
 import org.opends.sdk.*;
 import org.opends.sdk.requests.Requests;
 import org.opends.sdk.requests.SearchRequest;
@@ -383,10 +384,7 @@
 
     try
     {
-      if(System.getProperty("org.opends.sdk.ldap.transport.linger") == null)
-      {
-        System.setProperty("org.opends.sdk.ldap.transport.linger", "0");
-      }
+      TransportFactory.setInstance(new PerfToolTCPNIOTransportFactory());
       connectionFactoryProvider =
           new ConnectionFactoryProvider(argParser, this);
       runner = new SearchPerformanceRunner(argParser, this);
diff --git a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferReaderTestCase.java b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferReaderTestCase.java
index eac55aa..68bfa1a 100644
--- a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferReaderTestCase.java
+++ b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferReaderTestCase.java
@@ -36,7 +36,6 @@
 import org.opends.sdk.asn1.ASN1ReaderTestCase;
 
 import org.glassfish.grizzly.memory.ByteBufferWrapper;
-import org.glassfish.grizzly.memory.DefaultMemoryManager;
 
 
 
@@ -45,16 +44,11 @@
  */
 public class ASN1BufferReaderTestCase extends ASN1ReaderTestCase
 {
-  public final static DefaultMemoryManager memoryManager = new DefaultMemoryManager();
-
-
-
   @Override
   protected ASN1Reader getReader(final byte[] b, final int maxElementSize)
       throws IOException
   {
-    final ByteBufferWrapper buffer = new ByteBufferWrapper(memoryManager,
-        ByteBuffer.wrap(b));
+    final ByteBufferWrapper buffer = new ByteBufferWrapper(ByteBuffer.wrap(b));
     final ASN1BufferReader reader = new ASN1BufferReader(maxElementSize);
     reader.appendBytesRead(buffer);
     return reader;
diff --git a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferWriterTestCase.java b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferWriterTestCase.java
index cc1255f..f1d4cf2 100644
--- a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferWriterTestCase.java
+++ b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/ASN1BufferWriterTestCase.java
@@ -67,8 +67,7 @@
   protected ASN1Reader getReader(final byte[] encodedBytes)
       throws DecodeException, IOException
   {
-    final ByteBufferWrapper buffer = new ByteBufferWrapper(
-        ASN1BufferReaderTestCase.memoryManager, ByteBuffer.wrap(encodedBytes));
+    final ByteBufferWrapper buffer = new ByteBufferWrapper(ByteBuffer.wrap(encodedBytes));
     final ASN1BufferReader reader = new ASN1BufferReader(0);
     reader.appendBytesRead(buffer);
     return reader;
diff --git a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransportTestCase.java
similarity index 82%
rename from opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java
rename to opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransportTestCase.java
index 598cb69..b7d5227 100644
--- a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java
+++ b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransportTestCase.java
@@ -34,24 +34,27 @@
 import java.net.Socket;
 import java.util.Random;
 
-import org.testng.annotations.Test;
-
-import org.glassfish.grizzly.TransportFactory;
 import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
+import org.testng.annotations.Test;
 
 
 
 /**
- * Tests Global Transport Factory class.
+ * Tests LDAPDefaultTCPNIOTransport class.
  */
-public class GlobalTransportFactoryTestCase extends LDAPTestCase
+public class LDAPDefaultTCPNIOTransportTestCase extends LDAPTestCase
 {
+  /**
+   * Tests the default transport.
+   *
+   * @throws Exception
+   *           If an unexpected error occurred.
+   */
   @Test()
-  public void testGlobalTransport() throws Exception
+  public void testGetInstance() throws Exception
   {
     // Create a transport.
-    final TransportFactory instance = GlobalTransportFactory.getInstance();
-    final TCPNIOTransport transport = instance.createTCPTransport();
+    final TCPNIOTransport transport = LDAPDefaultTCPNIOTransport.getInstance();
     final Random r = new Random();
     int port = r.nextInt(10000);
     if (port < 1000)
diff --git a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java
similarity index 77%
copy from opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java
copy to opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java
index 598cb69..a008ccd 100644
--- a/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java
+++ b/opendj-sdk/sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java
@@ -25,7 +25,7 @@
  *      Copyright 2010 Sun Microsystems, Inc.
  */
 
-package com.sun.opends.sdk.ldap;
+package com.sun.opends.sdk.tools;
 
 
 
@@ -34,24 +34,29 @@
 import java.net.Socket;
 import java.util.Random;
 
-import org.testng.annotations.Test;
-
 import org.glassfish.grizzly.TransportFactory;
 import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
+import org.testng.annotations.Test;
 
 
 
 /**
- * Tests Global Transport Factory class.
+ * Tests PerfToolTCPNIOTransportFactoryTestCase class.
  */
-public class GlobalTransportFactoryTestCase extends LDAPTestCase
+public class PerfToolTCPNIOTransportFactoryTestCase extends ToolsTestCase
 {
+  /**
+   * Tests the transport factory.
+   *
+   * @throws Exception
+   *           If an unexpected error occurred.
+   */
   @Test()
-  public void testGlobalTransport() throws Exception
+  public void testGetInstance() throws Exception
   {
     // Create a transport.
-    final TransportFactory instance = GlobalTransportFactory.getInstance();
-    final TCPNIOTransport transport = instance.createTCPTransport();
+    final TransportFactory factory = new PerfToolTCPNIOTransportFactory();
+    final TCPNIOTransport transport = factory.createTCPTransport();
     final Random r = new Random();
     int port = r.nextInt(10000);
     if (port < 1000)

--
Gitblit v1.10.0