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

Ludovic Poitou
22.52.2010 97491bcdb796a35879477018ea768c1be2c989e4
Sync commit by matthew_swift
Expose Grizzly transport configuration in LDAPOptions and LDAPListenerOptions in order to allow better customization of transport.

Fix a couple of bugs in AuthRate where the -I flag wasn't working very well in bind-only mode (no search).

Avoid displaying help twice when --help option is provided to CLI commands.

Only display error message in CLIs when args are bad, otherwise help information causes the error message to get "lost".

Split request handling part of ServerConnection API out into a super-interface call RequestHandler.

2 files deleted
1 files added
15 files modified
1056 ■■■■■ changed files
sdk/src/com/sun/opends/sdk/ldap/GrizzlyLDAPListenerOptions.java 116 ●●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/ldap/GrizzlyLDAPOptions.java 116 ●●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java 12 ●●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java 12 ●●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/messages/messages.properties 2 ●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java 82 ●●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/AuthRate.java 59 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/LDAPCompare.java 16 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/LDAPModify.java 16 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/LDAPPasswordModify.java 16 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/LDAPSearch.java 16 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/ModRate.java 16 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/tools/SearchRate.java 16 ●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/LDAPListenerOptions.java 48 ●●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/LDAPOptions.java 50 ●●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/RequestHandler.java 245 ●●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/ServerConnection.java 215 ●●●●● patch | view | raw | blame | history
sdk/tests/unit-tests-testng/src/org/opends/sdk/LDAPServer.java 3 ●●●● patch | view | raw | blame | history
sdk/src/com/sun/opends/sdk/ldap/GrizzlyLDAPListenerOptions.java
File was deleted
sdk/src/com/sun/opends/sdk/ldap/GrizzlyLDAPOptions.java
File was deleted
sdk/src/com/sun/opends/sdk/ldap/LDAPConnectionFactoryImpl.java
@@ -253,17 +253,15 @@
  public LDAPConnectionFactoryImpl(final SocketAddress address,
      final LDAPOptions options)
  {
    TCPNIOTransport tmpTransport = null;
    if (options instanceof GrizzlyLDAPOptions)
    if (options.getTCPNIOTransport() == null)
    {
      tmpTransport = ((GrizzlyLDAPOptions) options).getTCPNIOTransport();
      this.transport = GlobalTransportFactory.getInstance()
          .createTCPTransport();
    }
    if (tmpTransport == null)
    else
    {
      tmpTransport = GlobalTransportFactory.getInstance().createTCPTransport();
      this.transport = options.getTCPNIOTransport();
    }
    this.transport = tmpTransport;
    this.socketAddress = address;
    this.options = new LDAPOptions(options);
    this.clientFilter = new LDAPClientFilter(new LDAPReader(
sdk/src/com/sun/opends/sdk/ldap/LDAPListenerImpl.java
@@ -83,17 +83,15 @@
      final ServerConnectionFactory<LDAPClientContext, Integer> factory,
      final LDAPListenerOptions options) throws IOException
  {
    TCPNIOTransport tmpTransport = null;
    if (options instanceof GrizzlyLDAPListenerOptions)
    if (options.getTCPNIOTransport() == null)
    {
      tmpTransport = ((GrizzlyLDAPListenerOptions) options)
          .getTCPNIOTransport();
      this.transport = GlobalTransportFactory.getInstance()
          .createTCPTransport();
    }
    if (tmpTransport == null)
    else
    {
      tmpTransport = GlobalTransportFactory.getInstance().createTCPTransport();
      this.transport = options.getTCPNIOTransport();
    }
    this.transport = tmpTransport;
    this.connectionFactory = factory;
    this.defaultFilterChain = new DefaultFilterChain();
    this.defaultFilterChain.add(new TransportFilter());
sdk/src/com/sun/opends/sdk/messages/messages.properties
@@ -3041,7 +3041,7 @@
 be started because it is already running
INFO_SUBCMDPARSER_OPTIONS={options}
INFO_SUBCMDPARSER_SUBCMD_AND_OPTIONS={subcommand} {options}
INFO_SUBCMDPARSER_WHERE_OPTIONS_INCLUDE=\        where {options} include:
INFO_SUBCMDPARSER_WHERE_OPTIONS_INCLUDE=Where {options} include:
INFO_EMAIL_TOOL_DESCRIPTION=Send an e-mail message via SMTP
INFO_EMAIL_HOST_DESCRIPTION=The address of the SMTP server to use to send \
 the message
sdk/src/com/sun/opends/sdk/tools/ArgumentParser.java
@@ -84,13 +84,11 @@
  private final ArrayList<String> trailingArguments;
  // Indicates whether this parser will allow additional unnamed
  // arguments at
  // the end of the list.
  // arguments at the end of the list.
  private final boolean allowsTrailingArguments;
  // Indicates whether long arguments should be treated in a
  // case-sensitive
  // manner.
  // case-sensitive manner.
  private final boolean longArgumentsCaseSensitive;
  // Indicates whether the usage or version information has been
@@ -127,18 +125,15 @@
  private OutputStream usageOutputStream;
  // The fully-qualified name of the Java class that should be invoked
  // to launch
  // the program with which this argument parser is associated.
  // to launch the program with which this argument parser is associated.
  private final String mainClassName;
  // A human-readable description for the tool, which will be included
  // when
  // displaying usage information.
  // when displaying usage information.
  private final LocalizableMessage toolDescription;
  // The display name that will be used for the trailing arguments in
  // the usage
  // information.
  // the usage information.
  private final String trailingArgsDisplayName;
  // The raw set of command-line arguments that were provided.
@@ -855,6 +850,7 @@
      }
    }
    buffer.append(EOL);
    buffer.append(EOL);
    buffer.append(INFO_SUBCMDPARSER_WHERE_OPTIONS_INCLUDE.get());
    buffer.append(EOL);
    buffer.append(EOL);
@@ -1021,17 +1017,14 @@
      if (arg.equals("--"))
      {
        // This is a special indicator that we have reached the end of
        // the named
        // arguments and that everything that follows after this should
        // be
        // considered trailing arguments.
        // the named arguments and that everything that follows after this
        // should be considered trailing arguments.
        inTrailingArgs = true;
      }
      else if (arg.startsWith("--"))
      {
        // This indicates that we are using the long name to reference
        // the
        // argument. It may be in any of the following forms:
        // the argument. It may be in any of the following forms:
        // --name
        // --name value
        // --name=value
@@ -1088,8 +1081,7 @@
          else if (argName.equals(OPTION_LONG_PRODUCT_VERSION))
          {
            // "--version" will always be interpreted as requesting
            // version
            // information.
            // version information.
            usageOrVersionDisplayed = true;
            versionPresent = true;
            try
@@ -1116,8 +1108,7 @@
          a.setPresent(true);
          // If this is the usage argument, then immediately stop and
          // print
          // usage information.
          // print usage information.
          if ((usageArgument != null)
              && usageArgument.getName().equals(a.getName()))
          {
@@ -1134,8 +1125,7 @@
        }
        // See if the argument takes a value. If so, then make sure one
        // was
        // provided. If not, then make sure none was provided.
        // was provided. If not, then make sure none was provided.
        if (a.needsValue())
        {
          if (argValue == null)
@@ -1182,8 +1172,7 @@
      else if (arg.startsWith("-"))
      {
        // This indicates that we are using the 1-character name to
        // reference
        // the argument. It may be in any of the following forms:
        // reference the argument. It may be in any of the following forms:
        // -n
        // -nvalue
        // -n value
@@ -1228,8 +1217,7 @@
          {
            // "-V" will always be interpreted as requesting
            // version information except if it's already defined (e.g
            // in
            // ldap tools).
            // in ldap tools).
            usageOrVersionDisplayed = true;
            versionPresent = true;
            try
@@ -1255,8 +1243,7 @@
          a.setPresent(true);
          // If this is the usage argument, then immediately stop and
          // print
          // usage information.
          // print usage information.
          if ((usageArgument != null)
              && usageArgument.getName().equals(a.getName()))
          {
@@ -1273,8 +1260,7 @@
        }
        // See if the argument takes a value. If so, then make sure one
        // was
        // provided. If not, then make sure none was provided.
        // was provided. If not, then make sure none was provided.
        if (a.needsValue())
        {
          if (argValue == null)
@@ -1313,15 +1299,11 @@
        {
          if (argValue != null)
          {
            // If we've gotten here, then it means that we're in a
            // scenario like
            // If we've gotten here, then it means that we're in a scenario like
            // "-abc" where "a" is a valid argument that doesn't take a
            // value.
            // However, this could still be valid if all remaining
            // characters in
            // the value are also valid argument characters that don't
            // take
            // values.
            // value. However, this could still be valid if all remaining
            // characters in the value are also valid argument characters that
            // don't take values.
            final int valueLength = argValue.length();
            for (int j = 0; j < valueLength; j++)
            {
@@ -1337,8 +1319,7 @@
              else if (b.needsValue())
              {
                // This means we're in a scenario like "-abc" where b is
                // a
                // valid argument that takes a value. We don't support
                // a valid argument that takes a value. We don't support
                // that.
                final LocalizableMessage message = ERR_ARGPARSER_CANT_MIX_ARGS_WITH_VALUES
                    .get(String.valueOf(argCharacter), argValue, String
@@ -1350,8 +1331,7 @@
                b.setPresent(true);
                // If this is the usage argument, then immediately stop
                // and
                // print usage information.
                // and print usage information.
                if ((usageArgument != null)
                    && usageArgument.getName().equals(b.getName()))
                {
@@ -1373,16 +1353,14 @@
      else if (allowsTrailingArguments)
      {
        // It doesn't start with a dash, so it must be a trailing
        // argument if
        // that is acceptable.
        // argument if that is acceptable.
        inTrailingArgs = true;
        trailingArguments.add(arg);
      }
      else
      {
        // It doesn't start with a dash and we don't allow trailing
        // arguments,
        // so this is illegal.
        // arguments, so this is illegal.
        final LocalizableMessage message = ERR_ARGPARSER_DISALLOWED_TRAILING_ARGUMENT
            .get(arg);
        throw new ArgumentException(message);
@@ -1390,8 +1368,7 @@
    }
    // If we allow trailing arguments and there is a minimum number,
    // then make
    // sure at least that many were provided.
    // then make sure at least that many were provided.
    if (allowsTrailingArguments && (minTrailingArguments > 0))
    {
      if (trailingArguments.size() < minTrailingArguments)
@@ -1410,10 +1387,8 @@
    }
    // Iterate through all of the arguments. For any that were not
    // provided on
    // the command line, see if there is an alternate default that can
    // be used.
    // For cases where there is not, see that argument is required.
    // provided on the command line, see if there is an alternate default that
    // can be used. For cases where there is not, see that argument is required.
    for (final Argument a : argumentList)
    {
      if (!a.isPresent())
@@ -1453,8 +1428,7 @@
        }
        // If there is still no value and the argument is required, then
        // that's
        // a problem.
        // that's a problem.
        if ((!a.hasValue()) && a.isRequired())
        {
          final LocalizableMessage message = ERR_ARGPARSER_NO_VALUE_FOR_REQUIRED_ARG
sdk/src/com/sun/opends/sdk/tools/AuthRate.java
@@ -65,10 +65,11 @@
      private BindStatsThread()
      private BindStatsThread(boolean extraFieldRequired)
      {
        super(new String[] { "bind time %" });
        extraColumn = new String[1];
        super(extraFieldRequired ? new String[] { "bind time %" }
            : new String[0]);
        extraColumn = new String[extraFieldRequired ? 1 : 0];
      }
@@ -77,9 +78,12 @@
      String[] getAdditionalColumns()
      {
        invalidCredRecentCount.set(0);
        final long searchWaitTime = searchWaitRecentTime.getAndSet(0);
        extraColumn[0] = String.format("%.1f",
            ((float)(waitTime - searchWaitTime) / waitTime) * 100.0);
        if (extraColumn.length != 0)
        {
          final long searchWaitTime = searchWaitRecentTime.getAndSet(0);
          extraColumn[0] = String.format("%.1f",
              ((float) (waitTime - searchWaitTime) / waitTime) * 100.0);
        }
        return extraColumn;
      }
    }
@@ -183,7 +187,7 @@
        else
        {
          return performBind(connection, data,
              new UpdateStatsResultHandler<BindResult>(startTime));
              new BindUpdateStatsResultHandler(startTime));
        }
      }
@@ -383,11 +387,7 @@
    @Override
    StatsThread newStatsThread()
    {
      if(filter != null && baseDN != null)
      {
        return new BindStatsThread();
      }
      return new StatsThread(new String[0]);
      return new BindStatsThread(filter != null && baseDN != null);
    }
@@ -400,7 +400,7 @@
    }
  }
  /**
   * The main method for SearchRate tool.
   * The main method for AuthRate tool.
   *
   * @param args
   *          The command-line arguments provided to this program.
@@ -408,7 +408,7 @@
  public static void main(final String[] args)
  {
    final int retCode = mainSearchRate(args, System.in, System.out, System.err);
    final int retCode = mainAuthRate(args, System.in, System.out, System.err);
    System.exit(filterExitCode(retCode));
  }
@@ -416,23 +416,23 @@
  /**
   * Parses the provided command-line arguments and uses that information to run
   * the ldapsearch tool.
   * the tool.
   *
   * @param args
   *          The command-line arguments provided to this program.
   * @return The error code.
   */
  static int mainSearchRate(final String[] args)
  static int mainAuthRate(final String[] args)
  {
    return mainSearchRate(args, System.in, System.out, System.err);
    return mainAuthRate(args, System.in, System.out, System.err);
  }
  /**
   * Parses the provided command-line arguments and uses that information to run
   * the ldapsearch tool.
   * the tool.
   *
   * @param args
   *          The command-line arguments provided to this program.
@@ -448,7 +448,7 @@
   * @return The error code.
   */
  static int mainSearchRate(final String[] args, final InputStream inStream,
  static int mainAuthRate(final String[] args, final InputStream inStream,
      final OutputStream outStream, final OutputStream errStream)
  {
@@ -654,6 +654,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getConnectionFactory();
      runner.validate();
@@ -670,26 +678,19 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    final List<String> attributes = new LinkedList<String>();
    final ArrayList<String> filterAndAttributeStrings = argParser
        .getTrailingArguments();
    if (filterAndAttributeStrings.size() > 0)
    {
      // the list of trailing arguments should be structured as follow:
      // the first trailing argument is
      // considered the filter, the other as attributes.
      // the first trailing argument is considered the filter, the other as
      // attributes.
      runner.filter = filterAndAttributeStrings.remove(0);
      // The rest are attributes
      for (final String s : filterAndAttributeStrings)
      {
sdk/src/com/sun/opends/sdk/tools/LDAPCompare.java
@@ -381,6 +381,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
    }
@@ -389,17 +397,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    try
    {
      final int versionNumber = version.getIntValue();
sdk/src/com/sun/opends/sdk/tools/LDAPModify.java
@@ -599,6 +599,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
    }
@@ -607,17 +615,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    try
    {
      final int versionNumber = version.getIntValue();
sdk/src/com/sun/opends/sdk/tools/LDAPPasswordModify.java
@@ -321,6 +321,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
    }
@@ -329,17 +337,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    final PasswordModifyExtendedRequest request = Requests
        .newPasswordModifyExtendedRequest();
    try
sdk/src/com/sun/opends/sdk/tools/LDAPSearch.java
@@ -609,6 +609,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
    }
@@ -617,17 +625,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    final List<Filter> filters = new LinkedList<Filter>();
    final List<String> attributes = new LinkedList<String>();
    final ArrayList<String> filterAndAttributeStrings = argParser
sdk/src/com/sun/opends/sdk/tools/ModRate.java
@@ -374,6 +374,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
      runner.validate();
@@ -383,17 +391,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    runner.modStrings = argParser.getTrailingArguments().toArray(
        new String[argParser.getTrailingArguments().size()]);
    runner.baseDN = baseDN.getValue();
sdk/src/com/sun/opends/sdk/tools/SearchRate.java
@@ -447,6 +447,14 @@
    try
    {
      argParser.parseArguments(args);
      // If we should just display usage or version information,
      // then print it and exit.
      if (argParser.usageOrVersionDisplayed())
      {
        return 0;
      }
      connectionFactory =
          connectionFactoryProvider.getAuthenticatedConnectionFactory();
      runner.validate();
@@ -456,17 +464,9 @@
      final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae
          .getMessage());
      println(message);
      println(argParser.getUsageMessage());
      return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue();
    }
    // If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed())
    {
      return 0;
    }
    final List<String> attributes = new LinkedList<String>();
    final ArrayList<String> filterAndAttributeStrings = argParser
        .getTrailingArguments();
sdk/src/org/opends/sdk/LDAPListenerOptions.java
@@ -31,6 +31,8 @@
import javax.net.ssl.SSLContext;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import com.sun.opends.sdk.util.Validator;
@@ -38,7 +40,7 @@
/**
 * Common options for LDAP listeners.
 */
public class LDAPListenerOptions
public final class LDAPListenerOptions
{
  private SSLContext sslContext;
@@ -47,6 +49,8 @@
  private int backlog;
  private TCPNIOTransport transport;
  /**
@@ -58,6 +62,7 @@
    this.sslContext = null;
    this.backlog = 0;
    this.decodeOptions = new DecodeOptions();
    this.transport = null;
  }
@@ -74,6 +79,7 @@
    this.sslContext = options.sslContext;
    this.backlog = options.backlog;
    this.decodeOptions = new DecodeOptions(options.decodeOptions);
    this.transport = options.transport;
  }
@@ -125,6 +131,24 @@
  /**
   * Returns the Grizzly TCP transport which will be used when initiating
   * connections with the Directory Server. By default this method will return
   * {@code null} indicating that the default transport factory should be
   * used to obtain a TCP transport.
   *
   * @return The Grizzly TCP transport which will be used when initiating
   *         connections with the Directory Server, or {@code null} if the
   *         default transport factory should be used to obtain a TCP
   *         transport.
   */
  public final TCPNIOTransport getTCPNIOTransport()
  {
    return transport;
  }
  /**
   * Sets the maximum queue length for incoming connections requests. If a
   * connection request arrives when the queue is full, the connection is
   * refused. If the backlog is less than {@code 1} then a default value of
@@ -180,4 +204,26 @@
    this.sslContext = sslContext;
    return this;
  }
  /**
   * Sets the Grizzly TCP transport which will be used when initiating
   * connections with the Directory Server. By default this method will return
   * {@code null} indicating that the default transport factory should be
   * used to obtain a TCP transport.
   *
   * @param transport
   *          The Grizzly TCP transport which will be used when initiating
   *          connections with the Directory Server, or {@code null} if the
   *          default transport factory should be used to obtain a TCP
   *          transport.
   * @return A reference to this connection options.
   */
  public final LDAPListenerOptions setTCPNIOTransport(
      final TCPNIOTransport transport)
  {
    this.transport = transport;
    return this;
  }
}
sdk/src/org/opends/sdk/LDAPOptions.java
@@ -29,11 +29,14 @@
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import com.sun.opends.sdk.util.Validator;
@@ -41,7 +44,7 @@
/**
 * Common options for LDAP client connections.
 */
public class LDAPOptions
public final class LDAPOptions
{
  private SSLContext sslContext;
@@ -61,6 +64,8 @@
   */
  private List<String> enabledProtocols = new LinkedList<String>();
  private TCPNIOTransport transport;
  /**
@@ -69,11 +74,11 @@
   */
  public LDAPOptions()
  {
    super();
    this.sslContext = null;
    this.timeoutInMillis = 0;
    this.useStartTLS = false;
    this.decodeOptions = new DecodeOptions();
    this.transport = null;
  }
@@ -93,6 +98,7 @@
    this.decodeOptions = new DecodeOptions(options.decodeOptions);
    this.enabledCipherSuites.addAll(options.getEnabledCipherSuites());
    this.enabledProtocols.addAll(options.getEnabledProtocols());
    this.transport = options.transport;
  }
@@ -130,6 +136,23 @@
  /**
   * Returns the Grizzly TCP transport which will be used when initiating
   * connections with the Directory Server. By default this method will return
   * {@code null} indicating that the default transport factory should be used
   * to obtain a TCP transport.
   *
   * @return The Grizzly TCP transport which will be used when initiating
   *         connections with the Directory Server, or {@code null} if the
   *         default transport factory should be used to obtain a TCP transport.
   */
  public final TCPNIOTransport getTCPNIOTransport()
  {
    return transport;
  }
  /**
   * Returns the operation timeout in the specified unit.
   *
   * @param unit
@@ -186,6 +209,27 @@
  /**
   * Sets the Grizzly TCP transport which will be used when initiating
   * connections with the Directory Server. By default this method will return
   * {@code null} indicating that the default transport factory will be used to
   * obtain a TCP transport.
   *
   * @param transport
   *          The Grizzly TCP transport which will be used when initiating
   *          connections with the Directory Server, or {@code null} if the
   *          default transport factory should be used to obtain a TCP
   *          transport.
   * @return A reference to this LDAP connection options.
   */
  public final LDAPOptions setTCPNIOTransport(final TCPNIOTransport transport)
  {
    this.transport = transport;
    return this;
  }
  /**
   * Sets the operation timeout. If the response is not received from the
   * Directory Server in the timeout period, the operation will be abandoned and
   * an error result returned. A timeout setting of 0 disables timeout limits.
sdk/src/org/opends/sdk/RequestHandler.java
New file
@@ -0,0 +1,245 @@
/*
 * 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 org.opends.sdk;
import org.opends.sdk.requests.*;
import org.opends.sdk.responses.BindResult;
import org.opends.sdk.responses.CompareResult;
import org.opends.sdk.responses.ExtendedResult;
import org.opends.sdk.responses.Result;
/**
 * A handler interface for processing client requests.
 * <p>
 * Implementations must always return results using the provided
 * {@link ResultHandler} unless explicitly permitted.
 * <p>
 * For example, an {@link LDAPListener} does not require {@code RequestHandler}
 * implementations to return results, which may be useful when implementing
 * abandon operation functionality. Conversely, an access logger implemented as
 * a {@code RequestHandler} wrapper will require wrapped {@code RequestHandler}s
 * to always return results, even abandoned results, in order for it to log the
 * result status.
 *
 * @param <C>
 *          The type of request context.
 * @see ServerConnectionFactory
 */
public interface RequestHandler<C>
{
  /**
   * Invoked when an add request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The add request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle add requests.
   */
  void handleAdd(C requestContext, AddRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a bind request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param version
   *          The protocol version included with the bind request.
   * @param request
   *          The bind request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle bind requests.
   */
  void handleBind(C requestContext, int version, BindRequest request,
      ResultHandler<? super BindResult> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a compare request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The compare request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle compare requests.
   */
  void handleCompare(C requestContext, CompareRequest request,
      ResultHandler<? super CompareResult> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a delete request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The delete request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle delete requests.
   */
  void handleDelete(C requestContext, DeleteRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when an extended request is received from a client.
   *
   * @param <R>
   *          The type of result returned by the extended request.
   * @param requestContext
   *          The request context.
   * @param request
   *          The extended request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle extended requests.
   */
  <R extends ExtendedResult> void handleExtendedRequest(C requestContext,
      ExtendedRequest<R> request, ResultHandler<? super R> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a modify request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The modify request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle modify requests.
   */
  void handleModify(C requestContext, ModifyRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a modify DN request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The modify DN request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle modify DN requests.
   */
  void handleModifyDN(C requestContext, ModifyDNRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a search request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The search request.
   * @param resultHandler
   *          The handler which should be used to send back the search results
   *          to the client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this request handler does not handle search requests.
   */
  void handleSearch(C requestContext, SearchRequest request,
      SearchResultHandler resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
}
sdk/src/org/opends/sdk/ServerConnection.java
@@ -29,33 +29,27 @@
import org.opends.sdk.requests.*;
import org.opends.sdk.responses.BindResult;
import org.opends.sdk.responses.CompareResult;
import org.opends.sdk.responses.ExtendedResult;
import org.opends.sdk.responses.Result;
import org.opends.sdk.requests.AbandonRequest;
import org.opends.sdk.requests.UnbindRequest;
/**
 * A handler interface for processing requests from clients.
 * A handler interface for interacting with client connections. A
 * {@code ServerConnection} is associated with a client connection when the
 * {@link ServerConnectionFactory#handleAccept(Object) handleAccept} method is
 * invoked against a {@code ServerConnectionFactory}.
 * <p>
 * Implementations should always return results via the provided
 * {@code RequestHandler} when processing requests unless otherwise indicated by
 * the component passing requests to the {@code ServerConnection}. For example,
 * an {@link LDAPListener} does not require {@code ServerConnection}
 * implementations to return results, which may be useful when implementing
 * abandon operation functionality.
 * <p>
 * Note that {@code ServerConnection}s may be stacked, and that a lower
 * {@code ServerConnection} implementation, such as a logger, may require upper
 * {@code ServerConnection} implementations to always return results.
 * Implementations are responsible for handling connection life-cycle as well as
 * request life-cycle. In particular, a {@code ServerConnection} is responsible
 * for processing abandon and unbind requests, as well as extended operations
 * such as {@code StartTLS} and {@code Cancel} operations.
 *
 * @param <C>
 *          The type of request context.
 * @see ServerConnectionFactory
 */
public interface ServerConnection<C>
public interface ServerConnection<C> extends RequestHandler<C>
{
  /**
@@ -74,77 +68,6 @@
  /**
   * Invoked when an add request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The add request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle add requests.
   */
  void handleAdd(C requestContext, AddRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a bind request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param version
   *          The protocol version included with the bind request.
   * @param request
   *          The bind request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle bind requests.
   */
  void handleBind(C requestContext, int version, BindRequest request,
      ResultHandler<? super BindResult> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a compare request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The compare request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle compare requests.
   */
  void handleCompare(C requestContext, CompareRequest request,
      ResultHandler<? super CompareResult> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when the client closes the connection, possibly using an unbind
   * request.
   *
@@ -183,120 +106,4 @@
   */
  void handleConnectionError(Throwable error);
  /**
   * Invoked when a delete request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The delete request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle delete requests.
   */
  void handleDelete(C requestContext, DeleteRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when an extended request is received from a client.
   *
   * @param <R>
   *          The type of result returned by the extended request.
   * @param requestContext
   *          The request context.
   * @param request
   *          The extended request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle extended requests.
   */
  <R extends ExtendedResult> void handleExtendedRequest(C requestContext,
      ExtendedRequest<R> request, ResultHandler<? super R> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a modify request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The modify request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle modify requests.
   */
  void handleModify(C requestContext, ModifyRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a modify DN request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The modify DN request.
   * @param resultHandler
   *          The handler which should be used to send back the result to the
   *          client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle modify DN requests.
   */
  void handleModifyDN(C requestContext, ModifyDNRequest request,
      ResultHandler<? super Result> resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
  /**
   * Invoked when a search request is received from a client.
   *
   * @param requestContext
   *          The request context.
   * @param request
   *          The search request.
   * @param resultHandler
   *          The handler which should be used to send back the search results
   *          to the client.
   * @param intermediateResponseHandler
   *          The handler which should be used to send back any intermediate
   *          responses to the client.
   * @throws UnsupportedOperationException
   *           If this server connection does not handle search requests.
   */
  void handleSearch(C requestContext, SearchRequest request,
      SearchResultHandler resultHandler,
      IntermediateResponseHandler intermediateResponseHandler)
      throws UnsupportedOperationException;
}
sdk/tests/unit-tests-testng/src/org/opends/sdk/LDAPServer.java
@@ -51,7 +51,6 @@
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import com.sun.opends.sdk.controls.AccountUsabilityRequestControl;
import com.sun.opends.sdk.controls.AccountUsabilityResponseControl;
import com.sun.opends.sdk.ldap.GrizzlyLDAPListenerOptions;
@@ -758,7 +757,7 @@
    transport.setSelectorRunnersCount(2);
    listener = new LDAPListener(port, getInstance(),
        new GrizzlyLDAPListenerOptions().setTCPNIOTransport(transport)
        new LDAPListenerOptions().setTCPNIOTransport(transport)
            .setBacklog(4096));
    transport.start();
    isRunning = true;