| | |
| | | // FIXME: should use a better collection than this - CLQ? |
| | | private final Stack<AsynchronousConnection> pool; |
| | | |
| | | private final ConcurrentLinkedQueue<PendingConnectionFuture> pendingFutures; |
| | | private final ConcurrentLinkedQueue<PendingResultFuture> pendingFutures; |
| | | |
| | | private final Object lock = new Object(); |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<Result> add(AddRequest request, |
| | | public FutureResult<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<BindResult> bind(BindRequest request, |
| | | public FutureResult<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | } |
| | | |
| | | // See if there waiters pending |
| | | PendingConnectionFuture future = pendingFutures.poll(); |
| | | PendingResultFuture future = pendingFutures.poll(); |
| | | if (future != null) |
| | | { |
| | | PooledConnectionWapper pooledConnection = new PooledConnectionWapper( |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<CompareResult> compare(CompareRequest request, |
| | | public FutureResult<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<Result> delete(DeleteRequest request, |
| | | public FutureResult<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public <R extends Result> ResultFuture<R> extendedRequest( |
| | | public <R extends Result> FutureResult<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<Result> modify(ModifyRequest request, |
| | | public FutureResult<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | public FutureResult<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | |
| | | |
| | | |
| | | |
| | | public ResultFuture<Result> search(SearchRequest request, |
| | | public FutureResult<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResulthandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | public FutureResult<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | public FutureResult<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ResultFuture<RootDSE> readRootDSE( |
| | | public FutureResult<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | public FutureResult<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ResultFuture<Schema> readSchema(DN name, |
| | | public FutureResult<Schema> readSchema(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | private static final class CompletedConnectionFuture implements |
| | | ConnectionFuture<AsynchronousConnection> |
| | | private static final class CompletedResultFuture implements |
| | | FutureResult<AsynchronousConnection> |
| | | { |
| | | private final PooledConnectionWapper connection; |
| | | |
| | | |
| | | |
| | | private CompletedConnectionFuture(PooledConnectionWapper connection) |
| | | private CompletedResultFuture(PooledConnectionWapper connection) |
| | | { |
| | | this.connection = connection; |
| | | } |
| | |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | public int getRequestID() |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private final class PendingConnectionFuture implements |
| | | ConnectionFuture<AsynchronousConnection> |
| | | private final class PendingResultFuture implements |
| | | FutureResult<AsynchronousConnection> |
| | | { |
| | | private volatile boolean isCancelled; |
| | | |
| | |
| | | |
| | | private volatile ErrorResultException err; |
| | | |
| | | private final ConnectionResultHandler<? super AsynchronousConnection> handler; |
| | | private final ResultHandler<? super AsynchronousConnection> handler; |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | |
| | | |
| | | private PendingConnectionFuture( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | private PendingResultFuture( |
| | | ResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | this.handler = handler; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public int getRequestID() |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | |
| | | |
| | | private void connection(PooledConnectionWapper connection) |
| | | { |
| | | this.connection = connection; |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(connection); |
| | | handler.handleResult(connection); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | this.err = e; |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(e); |
| | | handler.handleErrorResult(e); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | this.connectionFactory = connectionFactory; |
| | | this.poolSize = poolSize; |
| | | this.pool = new Stack<AsynchronousConnection>(); |
| | | this.pendingFutures = new ConcurrentLinkedQueue<PendingConnectionFuture>(); |
| | | this.pendingFutures = new ConcurrentLinkedQueue<PendingResultFuture>(); |
| | | } |
| | | |
| | | |
| | | |
| | | private final class WrapConnectionResultHandler implements |
| | | ConnectionResultHandler<AsynchronousConnection> |
| | | private final class WrapResultHandler implements |
| | | ResultHandler<AsynchronousConnection> |
| | | { |
| | | private final PendingConnectionFuture future; |
| | | private final PendingResultFuture future; |
| | | |
| | | |
| | | |
| | | private WrapConnectionResultHandler(PendingConnectionFuture future) |
| | | private WrapResultHandler(PendingResultFuture future) |
| | | { |
| | | this.future = future; |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleConnection(AsynchronousConnection connection) |
| | | public void handleResult(AsynchronousConnection connection) |
| | | { |
| | | PooledConnectionWapper pooledConnection = new PooledConnectionWapper( |
| | | connection); |
| | |
| | | |
| | | |
| | | |
| | | public void handleConnectionError(ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | future.error(error); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | public FutureResult<AsynchronousConnection> getAsynchronousConnection( |
| | | ResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | synchronized (lock) |
| | | { |
| | |
| | | conn); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(pooledConnection); |
| | | handler.handleResult(pooledConnection); |
| | | } |
| | | return new CompletedConnectionFuture(pooledConnection); |
| | | return new CompletedResultFuture(pooledConnection); |
| | | } |
| | | |
| | | PendingConnectionFuture pendingFuture = new PendingConnectionFuture( |
| | | PendingResultFuture pendingFuture = new PendingResultFuture( |
| | | handler); |
| | | // Pool was empty. Maybe a new connection if pool size is not |
| | | // reached |
| | | if (numConnections < poolSize) |
| | | { |
| | | numConnections++; |
| | | WrapConnectionResultHandler wrapHandler = new WrapConnectionResultHandler( |
| | | WrapResultHandler wrapHandler = new WrapResultHandler( |
| | | pendingFuture); |
| | | connectionFactory.getAsynchronousConnection(wrapHandler); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) |