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

matthew_swift
08.41.2009 9e2b4f600d6887b79b1c7f8657d60b7ba7b6d479
Add Connection.isClosed, improve AsynchronousConnection.isClosed Javadoc, add comments to ConnectionPool and move it to top-level package with other connection factory decorators.
1 files renamed
3 files modified
96 ■■■■■ changed files
sdk/src/org/opends/sdk/AsynchronousConnection.java 14 ●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/Connection.java 30 ●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/ConnectionPool.java 42 ●●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/SynchronousConnection.java 10 ●●●●● patch | view | raw | blame | history
sdk/src/org/opends/sdk/AsynchronousConnection.java
@@ -37,6 +37,7 @@
import org.opends.sdk.responses.Result;
/**
 * An asynchronous connection with a Directory Server over which read
 * and update operations may be performed. See RFC 4511 for the LDAPv3
@@ -268,6 +269,8 @@
   */
  void close(UnbindRequest request, String reason);
  /**
   * Compares an entry in the Directory Server using the provided
   * compare request.
@@ -495,12 +498,15 @@
      throws NullPointerException;
  /**
   * Returns <code>true</code> if the connection is closed for
   * <code>false</code> otherwise.
   * Indicates whether or not this connection has been explicitly closed
   * by calling {@code close}. This method will not return {@code true}
   * if a fatal error has occurred on the connection unless {@code
   * close} has been called.
   *
   * @return <code>true</code> if the connection is closed for
   *         <code>false</code> otherwise.
   * @return {@code true} if this connection has been explicitly closed
   *         by calling {@code close}, or {@code false} otherwise.
   */
  boolean isClosed();
}
sdk/src/org/opends/sdk/Connection.java
@@ -38,7 +38,6 @@
/**
 * A synchronous connection with a Directory Server over which read and
 * update operations may be performed. See RFC 4511 for the LDAPv3
@@ -307,7 +306,8 @@
   * @throws NullPointerException
   *           If {@code request} was {@code null}.
   */
  void close(UnbindRequest request, String reason) throws NullPointerException;
  void close(UnbindRequest request, String reason)
      throws NullPointerException;
@@ -513,19 +513,19 @@
  // /**
  // * Indicates whether or not this connection has been explicitly
  // closed
  // * by calling {@code close}. This method will not return {@code
  // true}
  // * if a fatal error has occurred on the connection unless {@code
  // * close} has been called.
  // *
  // * @return {@code true} if this connection has been explicitly
  // closed
  // * by calling {@code close}, or {@code false} otherwise.
  // */
  // boolean isClosed();
  /**
   * Indicates whether or not this connection has been explicitly closed
   * by calling {@code close}. This method will not return {@code true}
   * if a fatal error has occurred on the connection unless {@code
   * close} has been called.
   *
   * @return {@code true} if this connection has been explicitly closed
   *         by calling {@code close}, or {@code false} otherwise.
   */
  boolean isClosed();
  //
  //
  //
sdk/src/org/opends/sdk/ConnectionPool.java
File was renamed from sdk/src/org/opends/sdk/ldap/ConnectionPool.java
@@ -25,7 +25,7 @@
 *      Copyright 2009 Sun Microsystems, Inc.
 */
package org.opends.sdk.ldap;
package org.opends.sdk;
import java.util.Stack;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -44,19 +44,21 @@
import com.sun.opends.sdk.util.StaticUtils;
/**
 * Created by IntelliJ IDEA. User: digitalperk Date: Nov 25, 2009 Time: 11:12:29
 * AM To change this template use File | Settings | File Templates.
 * A simple connection pool implementation.
 */
public class ConnectionPool
    extends AbstractConnectionFactory<AsynchronousConnection> {
  private final ConnectionFactory<?> connectionFactory;
  private volatile int numConnections;
  private final int poolSize;
  // FIXME: should use a better collection than this - CLQ?
  private final Stack<AsynchronousConnection> pool;
  private final ConcurrentLinkedQueue<PendingConnectionFuture<?>> pendingFutures;
  private final Object lock = new Object();
  private class PooledConnectionWapper
  private final class PooledConnectionWapper
      implements AsynchronousConnection, ConnectionEventListener {
    private AsynchronousConnection connection;
@@ -244,6 +246,11 @@
        pool.remove(this);
        numConnections--;
        connection.removeConnectionEventListener(this);
        // FIXME: should still close the connection, but we need to be
        // careful that users of the pooled connection get a sensible
        // error if they continue to use it (i.e. not an NPE or ISE).
        if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE))
        {
          StaticUtils.DEBUG_LOG.finest(String
@@ -255,11 +262,11 @@
    }
  }
  public class CompletedConnectionFuture
  private static final class CompletedConnectionFuture
      implements ConnectionFuture<AsynchronousConnection> {
    private final PooledConnectionWapper connection;
    public CompletedConnectionFuture(PooledConnectionWapper connection) {
    private CompletedConnectionFuture(PooledConnectionWapper connection) {
      this.connection = connection;
    }
@@ -286,7 +293,7 @@
    }
  }
  public class PendingConnectionFuture<P>
  private final class PendingConnectionFuture<P>
      implements ConnectionFuture<AsynchronousConnection> {
    private volatile boolean isCancelled;
    private volatile PooledConnectionWapper connection;
@@ -296,12 +303,7 @@
    private final P p;
    private final CountDownLatch latch = new CountDownLatch(1);
    public PendingConnectionFuture() {
      this.handler = null;
      this.p = null;
    }
    public PendingConnectionFuture(
    private PendingConnectionFuture(
        P p,
        ConnectionResultHandler<? super AsynchronousConnection, P> handler) {
      this.handler = handler;
@@ -355,6 +357,18 @@
    }
  }
  /**
   * Creates a new connection pool which will maintain {@code poolSize}
   * connections created using the provided connection factory.
   *
   * @param connectionFactory
   *          The connection factory to use for creating new
   *          connections.
   * @param poolSize
   *          The maximum size of the connection pool.
   */
  public ConnectionPool(ConnectionFactory<?> connectionFactory, int poolSize) {
    this.connectionFactory = connectionFactory;
    this.poolSize = poolSize;
@@ -362,7 +376,7 @@
    this.pendingFutures = new ConcurrentLinkedQueue<PendingConnectionFuture<?>>();
  }
  private class WrapConnectionResultHandler
  private final class WrapConnectionResultHandler
      implements ConnectionResultHandler<AsynchronousConnection, Void> {
    private final PendingConnectionFuture<?> future;
sdk/src/org/opends/sdk/SynchronousConnection.java
@@ -260,4 +260,14 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  public boolean isClosed()
  {
    return connection.isClosed();
  }
}