mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
06.09.2010 85e2fdac288ffab3b99f3de09953be5226194ac8
sdk/lib/grizzly.jar
Binary files differ
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();
  }
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();
  }
sdk/src/com/sun/opends/sdk/ldap/GlobalTransportFactory.java
File was deleted
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
    {
sdk/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransport.java
New file
@@ -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.
  }
}
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
    {
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,
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);
sdk/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactory.java
New file
@@ -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);
  }
}
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);
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;
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;
sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/LDAPDefaultTCPNIOTransportTestCase.java
File was renamed from sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.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)
sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java
copy from sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.java copy to sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/tools/PerfToolTCPNIOTransportFactoryTestCase.java
File was copied from sdk/tests/unit-tests-testng/src/com/sun/opends/sdk/ldap/GlobalTransportFactoryTestCase.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)