Remove optional P parameter from result handlers as it is hardly ever needed in practice and just pollutes the APIs.
| | |
| | | /** |
| | | * Abstract result future implementation. |
| | | */ |
| | | public abstract class AbstractResultFutureImpl<R extends Result, P> implements |
| | | ResultFuture<R>, Runnable |
| | | public abstract class AbstractResultFutureImpl<R extends Result> |
| | | implements ResultFuture<R>, Runnable |
| | | { |
| | | private final LDAPConnection connection; |
| | | |
| | | private final ResultHandler<? super R, P> handler; |
| | | private final ResultHandler<? super R> handler; |
| | | |
| | | private final ExecutorService handlerExecutor; |
| | | |
| | | private final int messageID; |
| | | |
| | | // Use a semaphore instead of a lock because semaphores can be |
| | | // released by different thread to acquirer. |
| | | private final Semaphore invokerLock; |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | private final P p; |
| | | |
| | | private volatile boolean isCancelled = false; |
| | | |
| | | private volatile R result = null; |
| | |
| | | |
| | | |
| | | AbstractResultFutureImpl(int messageID, |
| | | ResultHandler<? super R, P> handler, P p, |
| | | LDAPConnection connection, ExecutorService handlerExecutor) |
| | | ResultHandler<? super R> handler, LDAPConnection connection, |
| | | ExecutorService handlerExecutor) |
| | | { |
| | | this.messageID = messageID; |
| | | this.handler = handler; |
| | | this.p = p; |
| | | this.connection = connection; |
| | | this.handlerExecutor = handlerExecutor; |
| | | if (handlerExecutor == null) |
| | |
| | | if (result.getResultCode().isExceptional()) |
| | | { |
| | | ErrorResultException e = ErrorResultException.wrap(result); |
| | | handler.handleErrorResult(p, e); |
| | | handler.handleErrorResult(e); |
| | | } |
| | | else |
| | | { |
| | | handler.handleResult(p, result); |
| | | handler.handleResult(result); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | synchronized void handleErrorResult(Result result) |
| | | final void handleErrorResult(Result result) |
| | | { |
| | | R errorResult = newErrorResult(result.getResultCode(), result |
| | | .getDiagnosticMessage(), result.getCause()); |
| | |
| | | |
| | | |
| | | |
| | | void handleResult(R result) |
| | | final void handleResult(R result) |
| | | { |
| | | if (!isDone()) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | protected void invokeHandler(final Runnable runnable) |
| | | final void invokeHandler(final Runnable runnable) |
| | | { |
| | | try |
| | | { |
| | |
| | | "Invoke thread interrupted: %s", StaticUtils |
| | | .getExceptionMessage(e))); |
| | | } |
| | | |
| | | // Reset interrupt status. |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | if (isCancelled()) |
| | | { |
| | | throw ErrorResultException.wrap( |
| | | Responses.newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED)); |
| | | throw ErrorResultException.wrap(Responses |
| | | .newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED)); |
| | | } |
| | | else if (result.getResultCode().isExceptional()) |
| | | { |
| | |
| | | /** |
| | | * Bind result future implementation. |
| | | */ |
| | | public final class BindResultFutureImpl<P> extends |
| | | AbstractResultFutureImpl<BindResult, P> implements |
| | | public final class BindResultFutureImpl extends |
| | | AbstractResultFutureImpl<BindResult> implements |
| | | ResultFuture<BindResult> |
| | | { |
| | | private final BindRequest request; |
| | |
| | | |
| | | |
| | | BindResultFutureImpl(int messageID, BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p, |
| | | ResultHandler<? super BindResult> handler, |
| | | LDAPConnection connection, ExecutorService handlerExecutor) |
| | | { |
| | | super(messageID, handler, p, connection, handlerExecutor); |
| | | super(messageID, handler, connection, handlerExecutor); |
| | | this.request = request; |
| | | } |
| | | |
| | |
| | | /** |
| | | * Compare result future implementation. |
| | | */ |
| | | public final class CompareResultFutureImpl<P> extends |
| | | AbstractResultFutureImpl<CompareResult, P> implements |
| | | public final class CompareResultFutureImpl extends |
| | | AbstractResultFutureImpl<CompareResult> implements |
| | | ResultFuture<CompareResult> |
| | | { |
| | | private final CompareRequest request; |
| | |
| | | |
| | | |
| | | CompareResultFutureImpl(int messageID, CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p, |
| | | ResultHandler<? super CompareResult> handler, |
| | | LDAPConnection connection, ExecutorService handlerExecutor) |
| | | { |
| | | super(messageID, handler, p, connection, handlerExecutor); |
| | | super(messageID, handler, connection, handlerExecutor); |
| | | this.request = request; |
| | | } |
| | | |
| | |
| | | /** |
| | | * Extended result future implementation. |
| | | */ |
| | | public final class ExtendedResultFutureImpl<R extends Result, P> extends |
| | | AbstractResultFutureImpl<R, P> implements ResultFuture<R> |
| | | public final class ExtendedResultFutureImpl<R extends Result> extends |
| | | AbstractResultFutureImpl<R> implements ResultFuture<R> |
| | | { |
| | | private final ExtendedRequest<R> request; |
| | | |
| | | |
| | | |
| | | ExtendedResultFutureImpl(int messageID, ExtendedRequest<R> request, |
| | | ResultHandler<? super R, P> handler, P p, |
| | | ResultHandler<? super R> handler, |
| | | LDAPConnection connection, ExecutorService handlerExecutor) |
| | | { |
| | | super(messageID, handler, p, connection, handlerExecutor); |
| | | super(messageID, handler, connection, handlerExecutor); |
| | | this.request = request; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void handleAddResult(int messageID, Result result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof ResultFutureImpl<?>) |
| | | if (pendingRequest instanceof ResultFutureImpl) |
| | | { |
| | | ResultFutureImpl<?> future = (ResultFutureImpl<?>) pendingRequest; |
| | | ResultFutureImpl future = (ResultFutureImpl) pendingRequest; |
| | | if (future.getRequest() instanceof AddRequest) |
| | | { |
| | | future.handleResult(result); |
| | |
| | | @Override |
| | | public void handleBindResult(int messageID, BindResult result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof BindResultFutureImpl<?>) |
| | | if (pendingRequest instanceof BindResultFutureImpl) |
| | | { |
| | | BindResultFutureImpl<?> future = ((BindResultFutureImpl<?>) pendingRequest); |
| | | BindResultFutureImpl future = ((BindResultFutureImpl) pendingRequest); |
| | | BindRequest request = future.getRequest(); |
| | | |
| | | if (request instanceof SASLBindRequest<?>) |
| | |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | Result errorResult = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "An error occurred during SASL authentication").setCause(e); |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR) |
| | | .setDiagnosticMessage( |
| | | "An error occurred during SASL authentication") |
| | | .setCause(e); |
| | | future.handleErrorResult(errorResult); |
| | | return; |
| | | } |
| | |
| | | { |
| | | pendingRequests.remove(messageID); |
| | | |
| | | // FIXME: what other sort of IOExceptions can be thrown? |
| | | // FIXME: what other sort of IOExceptions can be |
| | | // thrown? |
| | | // FIXME: Is this the best result code? |
| | | Result errorResult = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_ENCODING_ERROR).setCause(e); |
| | | ResultCode.CLIENT_SIDE_ENCODING_ERROR) |
| | | .setCause(e); |
| | | connectionErrorOccurred(errorResult); |
| | | future.handleErrorResult(errorResult); |
| | | } |
| | |
| | | @Override |
| | | public void handleCompareResult(int messageID, CompareResult result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof CompareResultFutureImpl<?>) |
| | | if (pendingRequest instanceof CompareResultFutureImpl) |
| | | { |
| | | CompareResultFutureImpl<?> future = (CompareResultFutureImpl<?>) pendingRequest; |
| | | CompareResultFutureImpl future = (CompareResultFutureImpl) pendingRequest; |
| | | future.handleResult(result); |
| | | } |
| | | else |
| | |
| | | @Override |
| | | public void handleDeleteResult(int messageID, Result result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof ResultFutureImpl<?>) |
| | | if (pendingRequest instanceof ResultFutureImpl) |
| | | { |
| | | ResultFutureImpl<?> future = (ResultFutureImpl<?>) pendingRequest; |
| | | ResultFutureImpl future = (ResultFutureImpl) pendingRequest; |
| | | if (future.getRequest() instanceof DeleteRequest) |
| | | { |
| | | future.handleResult(result); |
| | |
| | | public void handleException(Throwable throwable) |
| | | { |
| | | Result errorResult; |
| | | if(throwable instanceof EOFException) |
| | | if (throwable instanceof EOFException) |
| | | { |
| | | // FIXME: Is this the best result code? |
| | | errorResult = Responses.newResult( |
| | |
| | | OID_NOTICE_OF_DISCONNECTION)) |
| | | { |
| | | |
| | | Result errorResult = Responses.newResult(result.getResultCode()) |
| | | .setDiagnosticMessage(result.getDiagnosticMessage()); |
| | | Result errorResult = Responses.newResult( |
| | | result.getResultCode()).setDiagnosticMessage( |
| | | result.getDiagnosticMessage()); |
| | | close(null, true, errorResult); |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | |
| | | if (pendingRequest instanceof ExtendedResultFutureImpl<?, ?>) |
| | | if (pendingRequest instanceof ExtendedResultFutureImpl<?>) |
| | | { |
| | | ExtendedResultFutureImpl<?, ?> extendedFuture = ((ExtendedResultFutureImpl<?, ?>) pendingRequest); |
| | | ExtendedResultFutureImpl<?> extendedFuture = ((ExtendedResultFutureImpl<?>) pendingRequest); |
| | | try |
| | | { |
| | | handleExtendedResult0(extendedFuture, result); |
| | |
| | | catch (DecodeException de) |
| | | { |
| | | // FIXME: should the connection be closed as well? |
| | | Result errorResult = Responses.newResult(ResultCode.CLIENT_SIDE_DECODING_ERROR) |
| | | Result errorResult = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_DECODING_ERROR) |
| | | .setDiagnosticMessage(de.getLocalizedMessage()).setCause( |
| | | de); |
| | | extendedFuture.handleErrorResult(errorResult); |
| | |
| | | public void handleIntermediateResponse(int messageID, |
| | | GenericIntermediateResponse response) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | |
| | | @Override |
| | | public void handleModifyDNResult(int messageID, Result result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof ResultFutureImpl<?>) |
| | | if (pendingRequest instanceof ResultFutureImpl) |
| | | { |
| | | ResultFutureImpl<?> future = (ResultFutureImpl<?>) pendingRequest; |
| | | ResultFutureImpl future = (ResultFutureImpl) pendingRequest; |
| | | if (future.getRequest() instanceof ModifyDNRequest) |
| | | { |
| | | future.handleResult(result); |
| | |
| | | @Override |
| | | public void handleModifyResult(int messageID, Result result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof ResultFutureImpl<?>) |
| | | if (pendingRequest instanceof ResultFutureImpl) |
| | | { |
| | | ResultFutureImpl<?> future = (ResultFutureImpl<?>) pendingRequest; |
| | | ResultFutureImpl future = (ResultFutureImpl) pendingRequest; |
| | | if (future.getRequest() instanceof ModifyRequest) |
| | | { |
| | | future.handleResult(result); |
| | |
| | | @Override |
| | | public void handleSearchResult(int messageID, Result result) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof SearchResultFutureImpl<?>) |
| | | if (pendingRequest instanceof SearchResultFutureImpl) |
| | | { |
| | | ((SearchResultFutureImpl<?>) pendingRequest) |
| | | ((SearchResultFutureImpl) pendingRequest) |
| | | .handleResult(result); |
| | | } |
| | | else |
| | |
| | | public void handleSearchResultEntry(int messageID, |
| | | SearchResultEntry entry) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .get(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof SearchResultFutureImpl<?>) |
| | | if (pendingRequest instanceof SearchResultFutureImpl) |
| | | { |
| | | ((SearchResultFutureImpl<?>) pendingRequest) |
| | | ((SearchResultFutureImpl) pendingRequest) |
| | | .handleSearchResultEntry(entry); |
| | | } |
| | | else |
| | |
| | | public void handleSearchResultReference(int messageID, |
| | | SearchResultReference reference) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .get(messageID); |
| | | if (pendingRequest != null) |
| | | { |
| | | if (pendingRequest instanceof SearchResultFutureImpl<?>) |
| | | if (pendingRequest instanceof SearchResultFutureImpl) |
| | | { |
| | | ((SearchResultFutureImpl<?>) pendingRequest) |
| | | ((SearchResultFutureImpl) pendingRequest) |
| | | .handleSearchResultReference(reference); |
| | | } |
| | | else |
| | |
| | | |
| | | private boolean isClosed = false; |
| | | |
| | | private final List<ConnectionEventListener> listeners = |
| | | new CopyOnWriteArrayList<ConnectionEventListener>(); |
| | | private final List<ConnectionEventListener> listeners = new CopyOnWriteArrayList<ConnectionEventListener>(); |
| | | |
| | | private final AtomicInteger nextMsgID = new AtomicInteger(1); |
| | | |
| | | private volatile int pendingBindOrStartTLS = -1; |
| | | |
| | | private final ConcurrentHashMap<Integer, AbstractResultFutureImpl<?, ?>> pendingRequests = new ConcurrentHashMap<Integer, AbstractResultFutureImpl<?, ?>>(); |
| | | private final ConcurrentHashMap<Integer, AbstractResultFutureImpl<?>> pendingRequests = new ConcurrentHashMap<Integer, AbstractResultFutureImpl<?>>(); |
| | | |
| | | private final InetSocketAddress serverAddress; |
| | | |
| | |
| | | */ |
| | | public void abandon(AbandonRequest request) |
| | | { |
| | | AbstractResultFutureImpl<?, ?> pendingRequest = pendingRequests |
| | | AbstractResultFutureImpl<?> pendingRequest = pendingRequests |
| | | .remove(request.getMessageID()); |
| | | if (pendingRequest != null) |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | ResultFutureImpl<P> future = new ResultFutureImpl<P>(messageID, |
| | | request, handler, p, this, connFactory.getHandlerInvokers()); |
| | | ResultFutureImpl future = new ResultFutureImpl(messageID, request, |
| | | handler, this, connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | public ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | BindResultFutureImpl<P> future = new BindResultFutureImpl<P>( |
| | | messageID, request, handler, p, this, connFactory |
| | | .getHandlerInvokers()); |
| | | BindResultFutureImpl future = new BindResultFutureImpl(messageID, |
| | | request, handler, this, connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newBindResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newBindResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | if (!pendingRequests.isEmpty()) |
| | | { |
| | | future |
| | | .handleResult(Responses.newBindResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("There are other operations pending on this connection")); |
| | | future.handleResult(Responses.newBindResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "There are other operations pending on this connection")); |
| | | return future; |
| | | } |
| | | |
| | |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | Result errorResult = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "An error occurred during SASL authentication").setCause(e); |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR) |
| | | .setDiagnosticMessage( |
| | | "An error occurred during SASL authentication") |
| | | .setCause(e); |
| | | future.handleErrorResult(errorResult); |
| | | return future; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void close(UnbindRequest request, String reason) |
| | | throws NullPointerException { |
| | | throws NullPointerException |
| | | { |
| | | // FIXME: I18N need to internationalize this message. |
| | | Validator.ensureNotNull(request); |
| | | |
| | | close(request, false, |
| | | Responses.newResult(ResultCode.CLIENT_SIDE_USER_CANCELLED) |
| | | .setDiagnosticMessage("Connection closed by client" + |
| | | (reason != null ? ": " + reason : ""))); |
| | | close(request, false, Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_USER_CANCELLED).setDiagnosticMessage( |
| | | "Connection closed by client" |
| | | + (reason != null ? ": " + reason : ""))); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<CompareResult> compare( |
| | | CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p) |
| | | public ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | CompareResultFutureImpl<P> future = new CompareResultFutureImpl<P>( |
| | | messageID, request, handler, p, this, connFactory |
| | | CompareResultFutureImpl future = new CompareResultFutureImpl( |
| | | messageID, request, handler, this, connFactory |
| | | .getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newCompareResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newCompareResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | ResultFutureImpl<P> future = new ResultFutureImpl<P>(messageID, |
| | | request, handler, p, this, connFactory.getHandlerInvokers()); |
| | | ResultFutureImpl future = new ResultFutureImpl(messageID, request, |
| | | handler, this, connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <R extends Result, P> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R, P> handler, |
| | | P p) |
| | | public <R extends Result> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | ExtendedResultFutureImpl<R, P> future = new ExtendedResultFutureImpl<R, P>( |
| | | messageID, request, handler, p, this, connFactory |
| | | ExtendedResultFutureImpl<R> future = new ExtendedResultFutureImpl<R>( |
| | | messageID, request, handler, this, connFactory |
| | | .getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | ResultFutureImpl<P> future = new ResultFutureImpl<P>(messageID, |
| | | request, handler, p, this, connFactory.getHandlerInvokers()); |
| | | ResultFutureImpl future = new ResultFutureImpl(messageID, request, |
| | | handler, this, connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | ResultFutureImpl<P> future = new ResultFutureImpl<P>(messageID, |
| | | request, handler, p, this, connFactory.getHandlerInvokers()); |
| | | ResultFutureImpl future = new ResultFutureImpl(messageID, request, |
| | | handler, this, connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResulthandler, P p) |
| | | public ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResulthandler) |
| | | { |
| | | int messageID = nextMsgID.getAndIncrement(); |
| | | SearchResultFutureImpl<P> future = new SearchResultFutureImpl<P>( |
| | | messageID, request, resultHandler, searchResulthandler, p, |
| | | this, connFactory.getHandlerInvokers()); |
| | | SearchResultFutureImpl future = new SearchResultFutureImpl( |
| | | messageID, request, resultHandler, searchResulthandler, this, |
| | | connFactory.getHandlerInvokers()); |
| | | ASN1StreamWriter asn1Writer = connFactory |
| | | .getASN1Writer(streamWriter); |
| | | |
| | |
| | | } |
| | | if (pendingBindOrStartTLS > 0) |
| | | { |
| | | future |
| | | .handleResult(Responses.newResult(ResultCode.OPERATIONS_ERROR) |
| | | .setDiagnosticMessage("Bind or Start TLS operation in progress")); |
| | | future.handleResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setDiagnosticMessage( |
| | | "Bind or Start TLS operation in progress")); |
| | | return future; |
| | | } |
| | | pendingRequests.put(messageID, future); |
| | |
| | | } |
| | | |
| | | // First abort all outstanding requests. |
| | | for (AbstractResultFutureImpl<?, ?> future : pendingRequests |
| | | for (AbstractResultFutureImpl<?> future : pendingRequests |
| | | .values()) |
| | | { |
| | | if (pendingBindOrStartTLS <= 0) |
| | |
| | | return isClosed; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // |
| | | // |
| | | // |
| | |
| | | |
| | | // Needed in order to expose type information. |
| | | private <R extends Result> void handleExtendedResult0( |
| | | ExtendedResultFutureImpl<R, ?> future, |
| | | GenericExtendedResult result) throws DecodeException |
| | | ExtendedResultFutureImpl<R> future, GenericExtendedResult result) |
| | | throws DecodeException |
| | | { |
| | | R decodedResponse = future.decodeResponse(result.getResultCode(), |
| | | result.getMatchedDN(), result.getDiagnosticMessage(), result |
| | |
| | | |
| | | |
| | | private void handleIncorrectResponse( |
| | | AbstractResultFutureImpl<?, ?> pendingRequest) |
| | | AbstractResultFutureImpl<?> pendingRequest) |
| | | { |
| | | // FIXME: I18N need to have a better error message. |
| | | Result errorResult = Responses.newResult(ResultCode.CLIENT_SIDE_DECODING_ERROR) |
| | | .setDiagnosticMessage("LDAP response message did not match request"); |
| | | Result errorResult = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_DECODING_ERROR).setDiagnosticMessage( |
| | | "LDAP response message did not match request"); |
| | | |
| | | pendingRequest.handleErrorResult(errorResult); |
| | | connectionErrorOccurred(errorResult); |
| | |
| | | |
| | | |
| | | @Override |
| | | protected void removeMessageHandler(com.sun.grizzly.Connection<?> connection) |
| | | protected void removeMessageHandler( |
| | | com.sun.grizzly.Connection<?> connection) |
| | | { |
| | | ldapConnectionAttr.remove(connection); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | private class ConnectionFutureImpl<P> implements |
| | | private class ConnectionFutureImpl implements |
| | | ConnectionFuture<AsynchronousConnection>, |
| | | com.sun.grizzly.CompletionHandler<com.sun.grizzly.Connection>, |
| | | ResultHandler<Result, Void> |
| | | ResultHandler<Result> |
| | | { |
| | | private volatile AsynchronousConnection connection; |
| | | |
| | |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | private final ConnectionResultHandler<? super AsynchronousConnection, P> handler; |
| | | private final ConnectionResultHandler<? super AsynchronousConnection> handler; |
| | | |
| | | private boolean cancelled; |
| | | |
| | | private final P p; |
| | | |
| | | |
| | | |
| | | private ConnectionFutureImpl( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | this.handler = handler; |
| | | this.p = p; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | StartTLSRequest startTLS = new StartTLSRequest(options |
| | | .getSSLContext()); |
| | | sslFuture = this.connection.extendedRequest(startTLS, this, |
| | | null); |
| | | sslFuture = this.connection.extendedRequest(startTLS, this); |
| | | } |
| | | else if (options.getSSLContext() != null) |
| | | { |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, this.connection); |
| | | handler.handleConnection(this.connection); |
| | | } |
| | | } |
| | | catch (CancellationException ce) |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, exception); |
| | | handler.handleConnectionError(exception); |
| | | } |
| | | } |
| | | } |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, this.connection); |
| | | handler.handleConnection(this.connection); |
| | | } |
| | | } |
| | | } |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, exception); |
| | | handler.handleConnectionError(exception); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | // This is called when the StartTLS request is successful |
| | | public void handleResult(Void v, Result result) |
| | | public void handleResult(Result result) |
| | | { |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, connection); |
| | | handler.handleConnection(connection); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // This is called when the StartTLS request is not successful |
| | | public void handleErrorResult(Void v, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | exception = error; |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, exception); |
| | | handler.handleConnectionError(exception); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | ConnectionFutureImpl<P> future = new ConnectionFutureImpl<P>( |
| | | handler, p); |
| | | ConnectionFutureImpl future = new ConnectionFutureImpl(handler); |
| | | |
| | | try |
| | | { |
| | |
| | | t = t.getCause(); |
| | | } |
| | | |
| | | Result result = Responses.newResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR).setCause(t) |
| | | Result result = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_CONNECT_ERROR).setCause(t) |
| | | .setDiagnosticMessage(t.getMessage()); |
| | | return ErrorResultException.wrap(result); |
| | | } |
| | |
| | | /** |
| | | * Result future implementation. |
| | | */ |
| | | public final class ResultFutureImpl<P> extends |
| | | AbstractResultFutureImpl<Result, P> implements ResultFuture<Result> |
| | | public final class ResultFutureImpl extends |
| | | AbstractResultFutureImpl<Result> implements ResultFuture<Result> |
| | | { |
| | | private final Request request; |
| | | |
| | | |
| | | |
| | | ResultFutureImpl(int messageID, Request request, |
| | | ResultHandler<Result, P> handler, P p, LDAPConnection connection, |
| | | ResultHandler<Result> handler, LDAPConnection connection, |
| | | ExecutorService handlerExecutor) |
| | | { |
| | | super(messageID, handler, p, connection, handlerExecutor); |
| | | super(messageID, handler, connection, handlerExecutor); |
| | | this.request = request; |
| | | } |
| | | |
| | |
| | | /** |
| | | * Search result future implementation. |
| | | */ |
| | | public final class SearchResultFutureImpl<P> extends |
| | | AbstractResultFutureImpl<Result, P> implements ResultFuture<Result> |
| | | public final class SearchResultFutureImpl extends |
| | | AbstractResultFutureImpl<Result> implements ResultFuture<Result> |
| | | { |
| | | |
| | | private final SearchResultHandler<P> searchResultHandler; |
| | | |
| | | private final P p; |
| | | private final SearchResultHandler searchResultHandler; |
| | | |
| | | private final SearchRequest request; |
| | | |
| | | |
| | | |
| | | SearchResultFutureImpl(int messageID, SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResultHandler, P p, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResultHandler, |
| | | LDAPConnection connection, ExecutorService handlerExecutor) |
| | | { |
| | | super(messageID, resultHandler, p, connection, handlerExecutor); |
| | | super(messageID, resultHandler, connection, handlerExecutor); |
| | | this.request = request; |
| | | this.searchResultHandler = searchResultHandler; |
| | | this.p = p; |
| | | } |
| | | |
| | | |
| | | |
| | | synchronized void handleSearchResultEntry( |
| | | void handleSearchResultEntry( |
| | | final SearchResultEntry entry) |
| | | { |
| | | if (!isDone()) |
| | |
| | | { |
| | | public void run() |
| | | { |
| | | searchResultHandler.handleEntry(p, entry); |
| | | searchResultHandler.handleEntry(entry); |
| | | } |
| | | }); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | synchronized void handleSearchResultReference( |
| | | void handleSearchResultReference( |
| | | final SearchResultReference reference) |
| | | { |
| | | if (!isDone()) |
| | |
| | | { |
| | | public void run() |
| | | { |
| | | searchResultHandler.handleReference(p, reference); |
| | | searchResultHandler.handleReference(reference); |
| | | } |
| | | }); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ConnectionFuture<? extends AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<? extends AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | return connFactory.getAsynchronousConnection(handler, p); |
| | | return connFactory.getAsynchronousConnection(handler); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private class LDAPSearchResultHandler implements |
| | | SearchResultHandler<Void> |
| | | private class LDAPSearchResultHandler implements SearchResultHandler |
| | | { |
| | | private int entryCount = 0; |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void handleEntry(Void p, SearchResultEntry entry) |
| | | public void handleEntry(SearchResultEntry entry) |
| | | { |
| | | entryCount++; |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void handleReference(Void p, SearchResultReference reference) |
| | | public void handleReference(SearchResultReference reference) |
| | | { |
| | | println(LocalizableMessage.raw(reference.toString())); |
| | | } |
| | |
| | | Result result; |
| | | try |
| | | { |
| | | result = connection.search(search, resultHandler, null); |
| | | result = connection.search(search, resultHandler); |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | |
| | | |
| | | |
| | | private class ModifyWorkerThread extends |
| | | WorkerThread<ResultHandler<Result, Void>> |
| | | WorkerThread<ResultHandler<Result>> |
| | | { |
| | | private ModifyRequest mr; |
| | | private Object[] data; |
| | |
| | | |
| | | |
| | | |
| | | public ResultHandler<Result, Void> getHandler(long startTime) |
| | | public ResultHandler<Result> getHandler(long startTime) |
| | | { |
| | | return new UpdateStatsResultHandler<Result>(startTime); |
| | | } |
| | |
| | | |
| | | public ResultFuture<?> performOperation( |
| | | AsynchronousConnection connection, |
| | | ResultHandler<Result, Void> handler, DataSource[] dataSources) |
| | | ResultHandler<Result> handler, DataSource[] dataSources) |
| | | { |
| | | if (dataSources != null) |
| | | { |
| | | data = DataSource.generateData(dataSources, data); |
| | | } |
| | | mr = newModifyRequest(data); |
| | | return connection.modify(mr, handler, null); |
| | | return connection.modify(mr, handler); |
| | | } |
| | | |
| | | |
| | |
| | | || noRebindArgument.isPresent()) |
| | | { |
| | | connection = connectionFactory.getAsynchronousConnection( |
| | | null, null).get(); |
| | | null).get(); |
| | | } |
| | | for (int j = 0; j < numThreads; j++) |
| | | { |
| | |
| | | |
| | | |
| | | class UpdateStatsResultHandler<S extends Result> implements |
| | | ResultHandler<S, Void> |
| | | ResultHandler<S> |
| | | { |
| | | private long eTime; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public void handleResult(Void p, S result) |
| | | public void handleResult(S result) |
| | | { |
| | | successRecentCount.getAndIncrement(); |
| | | eTime = System.nanoTime() - eTime; |
| | |
| | | |
| | | |
| | | |
| | | public void handleErrorResult(Void p, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | failedRecentCount.getAndIncrement(); |
| | | app.println(LocalizableMessage.raw(error.getResult().toString())); |
| | |
| | | |
| | | |
| | | |
| | | abstract class WorkerThread<R extends ResultHandler<?, ?>> extends |
| | | abstract class WorkerThread<R extends ResultHandler<?>> extends |
| | | Thread |
| | | { |
| | | private int count; |
| | |
| | | try |
| | | { |
| | | connection = connectionFactory.getAsynchronousConnection( |
| | | null, null).get(); |
| | | null).get(); |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | |
| | | AuthenticatedAsynchronousConnection ac = (AuthenticatedAsynchronousConnection) connection; |
| | | try |
| | | { |
| | | ac.rebind(null, null).get(); |
| | | ac.rebind(null).get(); |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | |
| | | |
| | | |
| | | private class SearchStatsHandler extends |
| | | UpdateStatsResultHandler<Result> implements |
| | | SearchResultHandler<Void> |
| | | UpdateStatsResultHandler<Result> implements SearchResultHandler |
| | | { |
| | | private SearchStatsHandler(long eTime) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public void handleEntry(Void p, SearchResultEntry entry) |
| | | public void handleEntry(SearchResultEntry entry) |
| | | { |
| | | entryRecentCount.getAndIncrement(); |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleReference(Void p, |
| | | SearchResultReference reference) |
| | | public void handleReference(SearchResultReference reference) |
| | | { |
| | | } |
| | | } |
| | |
| | | sr.setFilter(String.format(filter, data)); |
| | | sr.setName(String.format(baseDN, data)); |
| | | } |
| | | return connection.search(sr, handler, handler, null); |
| | | return connection.search(sr, handler, handler); |
| | | } |
| | | } |
| | | |
| | |
| | | * The type of the inner result. |
| | | * @param <N> |
| | | * The type of the outer result. |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | */ |
| | | public abstract class ResultChain<M, N, P> implements ResultFuture<N>, |
| | | ResultHandler<M, P> |
| | | public abstract class ResultChain<M, N> implements ResultFuture<N>, |
| | | ResultHandler<M> |
| | | { |
| | | |
| | | private ErrorResultException errorResult; |
| | | |
| | | private final ResultHandler<? super N, P> handler; |
| | | private final ResultHandler<? super N> handler; |
| | | |
| | | private final Object stateLock = new Object(); |
| | | |
| | |
| | | * @param handler |
| | | * The outer result handler. |
| | | */ |
| | | protected ResultChain(ResultHandler<? super N, P> handler) |
| | | protected ResultChain(ResultHandler<? super N> handler) |
| | | { |
| | | this.handler = handler; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void handleErrorResult(P p, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | synchronized (stateLock) |
| | | { |
| | |
| | | errorResult = e; |
| | | if (handler != null) |
| | | { |
| | | handler.handleErrorResult(p, errorResult); |
| | | handler.handleErrorResult(errorResult); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void handleResult(P p, M result) |
| | | public void handleResult(M result) |
| | | { |
| | | synchronized (stateLock) |
| | | { |
| | |
| | | errorResult = e; |
| | | if (handler != null) |
| | | { |
| | | handler.handleErrorResult(p, errorResult); |
| | | handler.handleErrorResult(errorResult); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | * should terminate. |
| | | */ |
| | | protected ResultFuture<N> chainErrorResult( |
| | | ErrorResultException innerError, |
| | | ResultHandler<? super N, P> handler) throws ErrorResultException |
| | | ErrorResultException innerError, ResultHandler<? super N> handler) |
| | | throws ErrorResultException |
| | | { |
| | | throw innerError; |
| | | } |
| | |
| | | * should terminate. |
| | | */ |
| | | protected abstract ResultFuture<N> chainResult(M innerResult, |
| | | ResultHandler<? super N, P> handler) throws ErrorResultException; |
| | | ResultHandler<? super N> handler) throws ErrorResultException; |
| | | |
| | | } |
| | |
| | | * The type of the inner result. |
| | | * @param <N> |
| | | * The type of the outer result. |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | */ |
| | | public abstract class ResultTransformer<M, N, P> implements |
| | | ResultFuture<N>, ResultHandler<M, P> |
| | | public abstract class ResultTransformer<M, N> implements |
| | | ResultFuture<N>, ResultHandler<M> |
| | | { |
| | | |
| | | private final ResultHandler<? super N, P> handler; |
| | | private final ResultHandler<? super N> handler; |
| | | |
| | | private volatile ResultFuture<M> future = null; |
| | | |
| | |
| | | * @param handler |
| | | * The outer result handler. |
| | | */ |
| | | protected ResultTransformer(ResultHandler<? super N, P> handler) |
| | | protected ResultTransformer(ResultHandler<? super N> handler) |
| | | { |
| | | this.handler = handler; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final void handleErrorResult(P p, ErrorResultException error) |
| | | public final void handleErrorResult(ErrorResultException error) |
| | | { |
| | | if (handler != null) |
| | | { |
| | | handler.handleErrorResult(p, error); |
| | | handler.handleErrorResult(error); |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public final void handleResult(P p, M result) |
| | | public final void handleResult(M result) |
| | | { |
| | | if (handler != null) |
| | | { |
| | | try |
| | | { |
| | | handler.handleResult(p, transformResult(result)); |
| | | handler.handleResult(transformResult(result)); |
| | | } |
| | | catch (ErrorResultException e) |
| | | { |
| | | handler.handleErrorResult(p, e); |
| | | handler.handleErrorResult(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | AsynchronousConnection |
| | | { |
| | | |
| | | private static final class SingleEntryFuture<P> implements |
| | | ResultFuture<SearchResultEntry>, ResultHandler<Result, P>, |
| | | SearchResultHandler<P> |
| | | private static final class SingleEntryFuture implements |
| | | ResultFuture<SearchResultEntry>, ResultHandler<Result>, |
| | | SearchResultHandler |
| | | { |
| | | private final ResultHandler<? super SearchResultEntry, P> handler; |
| | | private final ResultHandler<? super SearchResultEntry> handler; |
| | | |
| | | private volatile SearchResultEntry firstEntry = null; |
| | | |
| | |
| | | |
| | | |
| | | private SingleEntryFuture( |
| | | ResultHandler<? super SearchResultEntry, P> handler) |
| | | ResultHandler<? super SearchResultEntry> handler) |
| | | { |
| | | this.handler = handler; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public void handleEntry(P p, SearchResultEntry entry) |
| | | public void handleEntry(SearchResultEntry entry) |
| | | { |
| | | if (firstEntry == null) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public void handleErrorResult(P p, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | if (handler != null) |
| | | { |
| | | handler.handleErrorResult(p, error); |
| | | handler.handleErrorResult(error); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleReference(P p, SearchResultReference reference) |
| | | public void handleReference(SearchResultReference reference) |
| | | { |
| | | if (firstReference == null) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public void handleResult(P p, Result result) |
| | | public void handleResult(Result result) |
| | | { |
| | | if (handler != null) |
| | | { |
| | | try |
| | | { |
| | | handler.handleResult(p, get0()); |
| | | handler.handleResult(get0()); |
| | | } |
| | | catch (ErrorResultException e) |
| | | { |
| | | handler.handleErrorResult(p, e); |
| | | handler.handleErrorResult(e); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | public ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry, P> handler, P p) |
| | | ResultHandler<? super SearchResultEntry> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | SearchRequest request = Requests.newSearchRequest(name, |
| | | SearchScope.BASE_OBJECT, Filter.getObjectClassPresentFilter()) |
| | | .addAttribute(attributeDescriptions); |
| | | return searchSingleEntry(request, handler, p); |
| | | return searchSingleEntry(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | public ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return RootDSE.readRootDSE(this, handler, p); |
| | | return RootDSE.readRootDSE(this, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return Schema.readSchema(this, name, handler, p); |
| | | return Schema.readSchema(this, name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return Schema.readSchema(this, name, handler, p); |
| | | return Schema.readSchema(this, name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | public ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry, P> handler, P p) |
| | | ResultHandler<? super SearchResultEntry> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | final SingleEntryFuture<P> innerFuture = new SingleEntryFuture<P>( |
| | | handler); |
| | | final SingleEntryFuture innerFuture = new SingleEntryFuture(handler); |
| | | final ResultFuture<Result> future = search(request, innerFuture, |
| | | innerFuture, p); |
| | | innerFuture); |
| | | innerFuture.setResultFuture(future); |
| | | return innerFuture; |
| | | } |
| | |
| | | { |
| | | |
| | | private static final class SingleEntryHandler implements |
| | | SearchResultHandler<Void> |
| | | SearchResultHandler |
| | | { |
| | | private volatile SearchResultEntry firstEntry = null; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public void handleEntry(Void p, SearchResultEntry entry) |
| | | public void handleEntry(SearchResultEntry entry) |
| | | { |
| | | if (firstEntry == null) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public void handleReference(Void p, SearchResultReference reference) |
| | | public void handleReference(SearchResultReference reference) |
| | | { |
| | | if (firstReference == null) |
| | | { |
| | |
| | | Validator.ensureNotNull(request, entries); |
| | | |
| | | // FIXME: does this need to be thread safe? |
| | | SearchResultHandler<Void> handler = new SearchResultHandler<Void>() |
| | | SearchResultHandler handler = new SearchResultHandler() |
| | | { |
| | | |
| | | public void handleEntry(Void p, SearchResultEntry entry) |
| | | public void handleEntry(SearchResultEntry entry) |
| | | { |
| | | entries.add(entry); |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleReference(Void p, |
| | | SearchResultReference reference) |
| | | public void handleReference(SearchResultReference reference) |
| | | { |
| | | if (references != null) |
| | | { |
| | |
| | | } |
| | | }; |
| | | |
| | | return search(request, handler, null); |
| | | return search(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | NullPointerException |
| | | { |
| | | SingleEntryHandler handler = new SingleEntryHandler(); |
| | | search(request, handler, null); |
| | | search(request, handler); |
| | | |
| | | if (handler.entryCount == 0) |
| | | { |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public abstract <P> ConnectionFuture<? extends C> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super C, P> handler, P p); |
| | | public abstract ConnectionFuture<? extends C> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super C> handler); |
| | | |
| | | |
| | | |
| | |
| | | protected final C blockingGetAsynchronousConnection() |
| | | throws ErrorResultException |
| | | { |
| | | ConnectionFuture<? extends C> future = |
| | | getAsynchronousConnection(null, null); |
| | | ConnectionFuture<? extends C> future = getAsynchronousConnection(null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | // Cancel the request if possible. |
| | | future.cancel(false); |
| | | |
| | | Result result = |
| | | Responses.newResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR) |
| | | .setCause(e) |
| | | .setDiagnosticMessage(e.getLocalizedMessage()); |
| | | Result result = Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_CONNECT_ERROR).setCause(e) |
| | | .setDiagnosticMessage(e.getLocalizedMessage()); |
| | | throw ErrorResultException.wrap(result); |
| | | } |
| | | } |
| | |
| | | * Adds an entry to the Directory Server using the provided add |
| | | * request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The add request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support add operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * Authenticates to the Directory Server using the provided bind |
| | | * request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The bind request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support bind operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * Compares an entry in the Directory Server using the provided |
| | | * compare request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The compare request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support compare operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p) |
| | | ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * Deletes an entry from the Directory Server using the provided |
| | | * delete request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The delete request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support delete operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * |
| | | * @param <R> |
| | | * The type of result returned by the extended request. |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The extended request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support extended operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <R extends Result, P> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R, P> handler, |
| | | P p) throws UnsupportedOperationException, IllegalStateException, |
| | | <R extends Result> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | | |
| | |
| | | * Modifies an entry in the Directory Server using the provided modify |
| | | * request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The modify request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support modify operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * Renames an entry in the Directory Server using the provided modify |
| | | * DN request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The modify DN request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support modify DN operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * connection.searchSingleEntry(request, resultHandler, p); |
| | | * </pre> |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param name |
| | | * The distinguished name of the entry to be read. |
| | | * @param attributeDescriptions |
| | |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code name} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry, P> handler, P p) |
| | | ResultHandler<? super SearchResultEntry> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * request will fail with an {@link EntryNotFoundException}. More |
| | | * specifically, the returned future will never return {@code null}. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * If this connection has already been closed, i.e. if |
| | | * {@code isClosed() == true}. |
| | | */ |
| | | <P> ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | ResultFuture<RootDSE> readRootDSE(ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException; |
| | | |
| | | |
| | |
| | | * Implementations may choose to perform optimizations such as |
| | | * caching. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param name |
| | | * The distinguished name of the subschema sub-entry. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * If this connection has already been closed, i.e. if |
| | | * {@code isClosed() == true}. |
| | | */ |
| | | <P> ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | ResultFuture<Schema> readSchema(DN name, ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException; |
| | | |
| | | |
| | |
| | | * schema. However, implementations may choose to perform other |
| | | * optimizations, such as caching. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param name |
| | | * The distinguished name of the entry whose schema is to be |
| | | * located. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * {@code null}. Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * If this connection has already been closed, i.e. if |
| | | * {@code isClosed() == true}. |
| | | */ |
| | | <P> ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException; |
| | | |
| | | |
| | |
| | | /** |
| | | * Searches the Directory Server using the provided search request. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The search request. |
| | | * @param resultHandler |
| | |
| | | * A search result handler which can be used to |
| | | * asynchronously process the search result entries and |
| | | * references as they are received, may be {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResulthandler, P p) |
| | | ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResulthandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | |
| | | * then the request will fail with an |
| | | * {@link MultipleEntriesFoundException}. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The search request. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code request} was {@code null}. |
| | | */ |
| | | <P> ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry, P> handler, P p) |
| | | ResultHandler<? super SearchResultEntry> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ConnectionFuture<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | { |
| | | // TODO: bug here? if allowRebind= false then bind will never |
| | | // happen |
| | | ConnectionFutureImpl<P> future = new ConnectionFutureImpl<P>( |
| | | allowRebinds ? request : null, handler, p); |
| | | future.connectFuture = parentFactory.getAsynchronousConnection( |
| | | future, null); |
| | | ConnectionFutureImpl future = new ConnectionFutureImpl( |
| | | allowRebinds ? request : null, handler); |
| | | future.connectFuture = parentFactory |
| | | .getAsynchronousConnection(future); |
| | | return future; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.add(request, handler, p); |
| | | return connection.add(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | * connections. This method will always throw {@code |
| | | * UnsupportedOperationException}. |
| | | */ |
| | | public <P> ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | public ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<CompareResult> compare( |
| | | CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p) |
| | | public ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.compare(request, handler, p); |
| | | return connection.compare(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.delete(request, handler, p); |
| | | return connection.delete(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <R extends Result, P> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, |
| | | ResultHandler<? super R, P> handler, P p) |
| | | public <R extends Result> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.extendedRequest(request, handler, p); |
| | | return connection.extendedRequest(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.modify(request, handler, p); |
| | | return connection.modify(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.modifyDN(request, handler, p); |
| | | return connection.modifyDN(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | * associated with this connection. If re-authentication fails for |
| | | * some reason then this connection will be automatically closed. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param handler |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support rebind operations. |
| | |
| | | * If this connection has already been closed, i.e. if |
| | | * {@code isClosed() == true}. |
| | | */ |
| | | public <P> ResultFuture<BindResult> rebind( |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | public ResultFuture<BindResult> rebind( |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | if (request == null) |
| | |
| | | |
| | | // Wrap the client handler so that we can update the connection |
| | | // state. |
| | | final ResultHandler<? super BindResult, P> clientHandler = handler; |
| | | final P clientParameter = p; |
| | | final ResultHandler<? super BindResult> clientHandler = handler; |
| | | |
| | | ResultHandler<BindResult, Void> handlerWrapper = new ResultHandler<BindResult, Void>() |
| | | ResultHandler<BindResult> handlerWrapper = new ResultHandler<BindResult>() |
| | | { |
| | | |
| | | public void handleErrorResult(Void p, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | // This connection is now unauthenticated so prevent |
| | | // further use. |
| | |
| | | |
| | | if (clientHandler != null) |
| | | { |
| | | clientHandler.handleErrorResult(clientParameter, error); |
| | | clientHandler.handleErrorResult(error); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleResult(Void p, BindResult result) |
| | | public void handleResult(BindResult result) |
| | | { |
| | | // Save the result. |
| | | AuthenticatedAsynchronousConnection.this.result = result; |
| | | |
| | | if (clientHandler != null) |
| | | { |
| | | clientHandler.handleResult(clientParameter, result); |
| | | clientHandler.handleResult(result); |
| | | } |
| | | } |
| | | |
| | | }; |
| | | |
| | | return connection.bind(request, handlerWrapper, null); |
| | | return connection.bind(request, handlerWrapper); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResulthandler, P p) |
| | | public ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResulthandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.search(request, resultHandler, |
| | | searchResulthandler, p); |
| | | searchResulthandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | public ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readRootDSE(handler, p); |
| | | return connection.readRootDSE(handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | public ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.readEntry(name, attributeDescriptions, |
| | | resultHandler, p); |
| | | resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | public ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.searchSingleEntry(request, resultHandler, p); |
| | | return connection.searchSingleEntry(request, resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readSchemaForEntry(name, handler, p); |
| | | return connection.readSchemaForEntry(name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readSchema(name, handler, p); |
| | | return connection.readSchema(name, handler); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | private static final class ConnectionFutureImpl<P> implements |
| | | private static final class ConnectionFutureImpl implements |
| | | ConnectionFuture<AuthenticatedAsynchronousConnection>, |
| | | ConnectionResultHandler<AsynchronousConnection, Void>, |
| | | ResultHandler<BindResult, Void> |
| | | ConnectionResultHandler<AsynchronousConnection>, |
| | | ResultHandler<BindResult> |
| | | { |
| | | private volatile AuthenticatedAsynchronousConnection authenticatedConnection; |
| | | |
| | |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | private final ConnectionResultHandler<? super AuthenticatedAsynchronousConnection, P> handler; |
| | | |
| | | private final P p; |
| | | private final ConnectionResultHandler<? super AuthenticatedAsynchronousConnection> handler; |
| | | |
| | | private boolean cancelled; |
| | | |
| | |
| | | |
| | | private ConnectionFutureImpl( |
| | | BindRequest request, |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection, P> handler, |
| | | P p) |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | { |
| | | this.request = request; |
| | | this.handler = handler; |
| | | this.p = p; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public void handleConnection(Void v, |
| | | AsynchronousConnection connection) |
| | | public void handleConnection(AsynchronousConnection connection) |
| | | { |
| | | this.connection = connection; |
| | | this.bindFuture = this.connection.bind(request, this, null); |
| | | this.bindFuture = this.connection.bind(request, this); |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleConnectionError(Void v, ErrorResultException error) |
| | | public void handleConnectionError(ErrorResultException error) |
| | | { |
| | | exception = error; |
| | | latch.countDown(); |
| | |
| | | |
| | | |
| | | |
| | | public void handleResult(Void v, BindResult result) |
| | | public void handleResult(BindResult result) |
| | | { |
| | | // FIXME: should make the result unmodifiable. |
| | | authenticatedConnection = new AuthenticatedAsynchronousConnection( |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, authenticatedConnection); |
| | | handler.handleConnection(authenticatedConnection); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleErrorResult(Void v, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | // Ensure that the connection is closed. |
| | | try |
| | |
| | | latch.countDown(); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, exception); |
| | | handler.handleConnectionError(exception); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public <P> ConnectionFuture<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | { |
| | | return impl.getAsynchronousConnection(handler, p); |
| | | return impl.getAsynchronousConnection(handler); |
| | | } |
| | | |
| | | |
| | |
| | | * result references will be passed to the provided search result |
| | | * handler. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param request |
| | | * The search request. |
| | | * @param handler |
| | | * A search result handler which can be used to process the |
| | | * search result entries and references as they are received, |
| | | * may be {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * If the result code indicates that the request failed for |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <P> Result search(SearchRequest request, |
| | | SearchResultHandler<P> handler, P p) throws ErrorResultException, |
| | | InterruptedException, UnsupportedOperationException, |
| | | IllegalStateException, NullPointerException; |
| | | Result search(SearchRequest request, SearchResultHandler handler) |
| | | throws ErrorResultException, InterruptedException, |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | package org.opends.sdk; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A connection factory provides an interface for obtaining a connection |
| | | * to a Directory Server. Connection factories can be used to wrap other |
| | |
| | | * ConnectionResultHandler} is provided, the handler will be notified |
| | | * when the connection is available and ready for use. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param handler |
| | | * The completion handler, or {@code null} if no handler is |
| | | * to be used. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future which can be used to retrieve the asynchronous |
| | | * connection. |
| | | */ |
| | | <P> ConnectionFuture<? extends C> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super C, P> handler, P p); |
| | | ConnectionFuture<? extends C> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super C> handler); |
| | | } |
| | |
| | | // FIXME: should use a better collection than this - CLQ? |
| | | private final Stack<AsynchronousConnection> pool; |
| | | |
| | | private final ConcurrentLinkedQueue<PendingConnectionFuture<?>> pendingFutures; |
| | | private final ConcurrentLinkedQueue<PendingConnectionFuture> pendingFutures; |
| | | |
| | | private final Object lock = new Object(); |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.add(request, handler, p); |
| | | return connection.add(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | public ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.bind(request, handler, p); |
| | | return connection.bind(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | // See if there waiters pending |
| | | PendingConnectionFuture<?> future = pendingFutures.poll(); |
| | | PendingConnectionFuture future = pendingFutures.poll(); |
| | | if (future != null) |
| | | { |
| | | PooledConnectionWapper pooledConnection = new PooledConnectionWapper( |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<CompareResult> compare( |
| | | CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p) |
| | | public ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.compare(request, handler, p); |
| | | return connection.compare(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.delete(request, handler, p); |
| | | return connection.delete(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <R extends Result, P> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, |
| | | ResultHandler<? super R, P> handler, P p) |
| | | public <R extends Result> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.extendedRequest(request, handler, p); |
| | | return connection.extendedRequest(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.modify(request, handler, p); |
| | | return connection.modify(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.modifyDN(request, handler, p); |
| | | return connection.modifyDN(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResulthandler, P p) |
| | | public ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResulthandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.search(request, resultHandler, |
| | | searchResulthandler, p); |
| | | searchResulthandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | public ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.readEntry(name, attributeDescriptions, |
| | | resultHandler, p); |
| | | resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | public ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.searchSingleEntry(request, resultHandler, p); |
| | | return connection.searchSingleEntry(request, resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | public ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | if (connection == null) |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.readRootDSE(handler, p); |
| | | return connection.readRootDSE(handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | if (connection == null) |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.readSchemaForEntry(name, handler, p); |
| | | return connection.readSchemaForEntry(name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | if (connection == null) |
| | | { |
| | | throw new IllegalStateException(); |
| | | } |
| | | return connection.readSchema(name, handler, p); |
| | | return connection.readSchema(name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private final class PendingConnectionFuture<P> implements |
| | | private final class PendingConnectionFuture implements |
| | | ConnectionFuture<AsynchronousConnection> |
| | | { |
| | | private volatile boolean isCancelled; |
| | |
| | | |
| | | private volatile ErrorResultException err; |
| | | |
| | | private final ConnectionResultHandler<? super AsynchronousConnection, P> handler; |
| | | |
| | | private final P p; |
| | | private final ConnectionResultHandler<? super AsynchronousConnection> handler; |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | |
| | | |
| | | private PendingConnectionFuture( |
| | | P p, |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler) |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | this.handler = handler; |
| | | this.p = p; |
| | | } |
| | | |
| | | |
| | |
| | | this.connection = connection; |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, connection); |
| | | handler.handleConnection(connection); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | this.err = e; |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, e); |
| | | handler.handleConnectionError(e); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | this.connectionFactory = connectionFactory; |
| | | this.poolSize = poolSize; |
| | | this.pool = new Stack<AsynchronousConnection>(); |
| | | this.pendingFutures = new ConcurrentLinkedQueue<PendingConnectionFuture<?>>(); |
| | | this.pendingFutures = new ConcurrentLinkedQueue<PendingConnectionFuture>(); |
| | | } |
| | | |
| | | |
| | | |
| | | private final class WrapConnectionResultHandler implements |
| | | ConnectionResultHandler<AsynchronousConnection, Void> |
| | | ConnectionResultHandler<AsynchronousConnection> |
| | | { |
| | | private final PendingConnectionFuture<?> future; |
| | | private final PendingConnectionFuture future; |
| | | |
| | | |
| | | |
| | | private WrapConnectionResultHandler( |
| | | PendingConnectionFuture<?> future) |
| | | private WrapConnectionResultHandler(PendingConnectionFuture future) |
| | | { |
| | | this.future = future; |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleConnection(java.lang.Void p, |
| | | AsynchronousConnection connection) |
| | | public void handleConnection(AsynchronousConnection connection) |
| | | { |
| | | PooledConnectionWapper pooledConnection = new PooledConnectionWapper( |
| | | connection); |
| | |
| | | |
| | | |
| | | |
| | | public void handleConnectionError(java.lang.Void p, |
| | | ErrorResultException error) |
| | | public void handleConnectionError(ErrorResultException error) |
| | | { |
| | | future.error(error); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public <P> ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | synchronized (lock) |
| | | { |
| | |
| | | conn); |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, pooledConnection); |
| | | handler.handleConnection(pooledConnection); |
| | | } |
| | | return new CompletedConnectionFuture(pooledConnection); |
| | | } |
| | | |
| | | PendingConnectionFuture<P> pendingFuture = new PendingConnectionFuture<P>( |
| | | p, handler); |
| | | PendingConnectionFuture pendingFuture = new PendingConnectionFuture( |
| | | handler); |
| | | // Pool was empty. Maybe a new connection if pool size is not |
| | | // reached |
| | | if (numConnections < poolSize) |
| | |
| | | numConnections++; |
| | | WrapConnectionResultHandler wrapHandler = new WrapConnectionResultHandler( |
| | | pendingFuture); |
| | | connectionFactory.getAsynchronousConnection(wrapHandler, null); |
| | | connectionFactory.getAsynchronousConnection(wrapHandler); |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) |
| | | { |
| | | StaticUtils.DEBUG_LOG |
| | |
| | | |
| | | package org.opends.sdk; |
| | | |
| | | |
| | | |
| | | /** |
| | | * A completion handler which is notified when an asynchronous |
| | | * connection attempt has completed. |
| | |
| | | * @param <C> |
| | | * The type of asynchronous connection handled by this |
| | | * connection result handler. |
| | | * @param <P> |
| | | * The type of the additional parameter to this handler's |
| | | * methods. Use {@link java.lang.Void} for visitors that do not |
| | | * need an additional parameter. |
| | | */ |
| | | public interface ConnectionResultHandler<C extends AsynchronousConnection, P> |
| | | public interface ConnectionResultHandler<C extends AsynchronousConnection> |
| | | { |
| | | /** |
| | | * Invoked when the asynchronous connection has completed |
| | | * successfully. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * @param connection |
| | | * The connection which can be used to interact with the |
| | | * Directory Server. |
| | | */ |
| | | void handleConnection(P p, C connection); |
| | | void handleConnection(C connection); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Invoked when the asynchronous connection attempt has failed. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * @param error |
| | | * The error result exception indicating why the asynchronous |
| | | * connection attempt has failed. |
| | | */ |
| | | void handleConnectionError(P p, ErrorResultException error); |
| | | void handleConnectionError(ErrorResultException error); |
| | | } |
| | |
| | | */ |
| | | private final class AsynchronousConnectionImpl implements |
| | | AsynchronousConnection, ConnectionEventListener, |
| | | ResultHandler<Result, Void> |
| | | ResultHandler<Result> |
| | | { |
| | | private final AsynchronousConnection connection; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> add(AddRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.add(request, handler, p); |
| | | return connection.add(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult, P> handler, P p) |
| | | public ResultFuture<BindResult> bind(BindRequest request, |
| | | ResultHandler<? super BindResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.bind(request, handler, p); |
| | | return connection.bind(request, handler); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<CompareResult> compare( |
| | | CompareRequest request, |
| | | ResultHandler<? super CompareResult, P> handler, P p) |
| | | public ResultFuture<CompareResult> compare(CompareRequest request, |
| | | ResultHandler<? super CompareResult> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.compare(request, handler, p); |
| | | return connection.compare(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> delete(DeleteRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.delete(request, handler, p); |
| | | return connection.delete(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <R extends Result, P> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, |
| | | ResultHandler<? super R, P> handler, P p) |
| | | public <R extends Result> ResultFuture<R> extendedRequest( |
| | | ExtendedRequest<R> request, ResultHandler<? super R> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.extendedRequest(request, handler, p); |
| | | return connection.extendedRequest(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modify(ModifyRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.modify(request, handler, p); |
| | | return connection.modify(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result, P> handler, P p) |
| | | public ResultFuture<Result> modifyDN(ModifyDNRequest request, |
| | | ResultHandler<Result> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.modifyDN(request, handler, p); |
| | | return connection.modifyDN(request, handler); |
| | | } |
| | | |
| | | |
| | | |
| | | public <P> ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result, P> resultHandler, |
| | | SearchResultHandler<P> searchResultHandler, P p) |
| | | public ResultFuture<Result> search(SearchRequest request, |
| | | ResultHandler<Result> resultHandler, |
| | | SearchResultHandler searchResultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.search(request, resultHandler, |
| | | searchResultHandler, p); |
| | | searchResultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | public ResultFuture<SearchResultEntry> readEntry(DN name, |
| | | Collection<String> attributeDescriptions, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.readEntry(name, attributeDescriptions, |
| | | resultHandler, p); |
| | | resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | public ResultFuture<SearchResultEntry> searchSingleEntry( |
| | | SearchRequest request, |
| | | ResultHandler<? super SearchResultEntry, P> resultHandler, P p) |
| | | ResultHandler<? super SearchResultEntry> resultHandler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | return connection.searchSingleEntry(request, resultHandler, p); |
| | | return connection.searchSingleEntry(request, resultHandler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | public ResultFuture<RootDSE> readRootDSE( |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readRootDSE(handler, p); |
| | | return connection.readRootDSE(handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchemaForEntry(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readSchemaForEntry(name, handler, p); |
| | | return connection.readSchemaForEntry(name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema, P> handler, P p) |
| | | public ResultFuture<Schema> readSchema(DN name, |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException |
| | | { |
| | | return connection.readSchema(name, handler, p); |
| | | return connection.readSchema(name, handler); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public void handleErrorResult(Void aVoid, ErrorResultException error) |
| | | public void handleErrorResult(ErrorResultException error) |
| | | { |
| | | // TODO: I18N |
| | | if (error instanceof TimeoutResultException) |
| | |
| | | |
| | | |
| | | |
| | | public void handleResult(Void aVoid, Result result) |
| | | public void handleResult(Result result) |
| | | { |
| | | // Do nothing |
| | | } |
| | |
| | | |
| | | private void sendHeartBeat() |
| | | { |
| | | search(heartBeat, this, null, null); |
| | | search(heartBeat, this, null); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private final class ConnectionFutureImpl<P> implements |
| | | private final class ConnectionFutureImpl implements |
| | | ConnectionFuture<AsynchronousConnection>, |
| | | ConnectionResultHandler<AsynchronousConnection, Void> |
| | | ConnectionResultHandler<AsynchronousConnection> |
| | | { |
| | | private volatile AsynchronousConnectionImpl heartBeatConnection; |
| | | |
| | |
| | | |
| | | private final CountDownLatch latch = new CountDownLatch(1); |
| | | |
| | | private final ConnectionResultHandler<? super AsynchronousConnectionImpl, P> handler; |
| | | |
| | | private final P p; |
| | | private final ConnectionResultHandler<? super AsynchronousConnectionImpl> handler; |
| | | |
| | | private boolean cancelled; |
| | | |
| | | |
| | | |
| | | private ConnectionFutureImpl( |
| | | ConnectionResultHandler<? super AsynchronousConnectionImpl, P> handler, |
| | | P p) |
| | | ConnectionResultHandler<? super AsynchronousConnectionImpl> handler) |
| | | { |
| | | this.handler = handler; |
| | | this.p = p; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | public void handleConnection(Void v, |
| | | AsynchronousConnection connection) |
| | | public void handleConnection(AsynchronousConnection connection) |
| | | { |
| | | heartBeatConnection = new AsynchronousConnectionImpl(connection); |
| | | synchronized (activeConnections) |
| | |
| | | } |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnection(p, heartBeatConnection); |
| | | handler.handleConnection(heartBeatConnection); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | | |
| | | |
| | | |
| | | public void handleConnectionError(Void v, ErrorResultException error) |
| | | public void handleConnectionError(ErrorResultException error) |
| | | { |
| | | exception = error; |
| | | if (handler != null) |
| | | { |
| | | handler.handleConnectionError(p, error); |
| | | handler.handleConnectionError(error); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | public <P> ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | ConnectionFutureImpl<P> future = new ConnectionFutureImpl<P>( |
| | | handler, p); |
| | | future.connectFuture = parentFactory.getAsynchronousConnection( |
| | | future, null); |
| | | ConnectionFutureImpl future = new ConnectionFutureImpl(handler); |
| | | future.connectFuture = parentFactory |
| | | .getAsynchronousConnection(future); |
| | | return future; |
| | | } |
| | | } |
| | |
| | | * |
| | | * @param <S> |
| | | * The type of result handled by this result handler. |
| | | * @param <P> |
| | | * The type of the additional parameter to this handler's |
| | | * methods. Use {@link java.lang.Void} for visitors that do not |
| | | * need an additional parameter. |
| | | */ |
| | | public interface ResultHandler<S, P> |
| | | public interface ResultHandler<S> |
| | | { |
| | | /** |
| | | * Invoked when the asynchronous operation has failed. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * @param error |
| | | * The error result exception indicating why the asynchronous |
| | | * operation has failed. |
| | | */ |
| | | void handleErrorResult(P p, ErrorResultException error); |
| | | void handleErrorResult(ErrorResultException error); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Invoked when the asynchronous operation has completed successfully. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * @param result |
| | | * The result of the asynchronous operation. |
| | | */ |
| | | void handleResult(P p, S result); |
| | | void handleResult(S result); |
| | | } |
| | |
| | | * request will fail with an {@link EntryNotFoundException}. More |
| | | * specifically, the returned future will never return {@code null}. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param connection |
| | | * A connection to the Directory Server whose Root DSE is to |
| | | * be read. |
| | |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If the connection does not support search operations. |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code connection} was {@code null}. |
| | | */ |
| | | public static <P> ResultFuture<RootDSE> readRootDSE( |
| | | public static ResultFuture<RootDSE> readRootDSE( |
| | | AsynchronousConnection connection, |
| | | ResultHandler<RootDSE, P> handler, P p) |
| | | ResultHandler<RootDSE> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | final ResultTransformer<SearchResultEntry, RootDSE, P> future = |
| | | new ResultTransformer<SearchResultEntry, RootDSE, P>(handler) |
| | | final ResultTransformer<SearchResultEntry, RootDSE> future = |
| | | new ResultTransformer<SearchResultEntry, RootDSE>(handler) |
| | | { |
| | | |
| | | protected RootDSE transformResult(SearchResultEntry result) |
| | |
| | | }; |
| | | |
| | | ResultFuture<SearchResultEntry> innerFuture = connection |
| | | .searchSingleEntry(SEARCH_REQUEST, future, p); |
| | | .searchSingleEntry(SEARCH_REQUEST, future); |
| | | future.setResultFuture(innerFuture); |
| | | return future; |
| | | } |
| | |
| | | * Implementations of these methods should complete in a timely manner |
| | | * so as to avoid keeping the invoking thread from dispatching to other |
| | | * completion handlers. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to this handler's |
| | | * methods. Use {@link java.lang.Void} for visitors that do not |
| | | * need an additional parameter. |
| | | */ |
| | | public interface SearchResultHandler<P> |
| | | public interface SearchResultHandler |
| | | { |
| | | /** |
| | | * Invoked each time a search result entry is returned from an |
| | | * asynchronous search operation. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * |
| | | * @param entry |
| | | * The search result entry. |
| | | */ |
| | | void handleEntry(P p, SearchResultEntry entry); |
| | | void handleEntry(SearchResultEntry entry); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Invoked each time a search result reference is returned from an |
| | | * asynchronous search operation. |
| | | * |
| | | * @param p |
| | | * A handler specified parameter. |
| | | * |
| | | * @param reference |
| | | * The search result reference. |
| | | */ |
| | | void handleReference(P p, SearchResultReference reference); |
| | | void handleReference(SearchResultReference reference); |
| | | } |
| | |
| | | InterruptedException, UnsupportedOperationException, |
| | | IllegalStateException, NullPointerException |
| | | { |
| | | ResultFuture<Result> future = connection.add(request, null, null); |
| | | ResultFuture<Result> future = connection.add(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | ResultFuture<BindResult> future = connection.bind(request, null, |
| | | null); |
| | | ResultFuture<BindResult> future = connection.bind(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | NullPointerException |
| | | { |
| | | ResultFuture<CompareResult> future = connection.compare(request, |
| | | null, null); |
| | | null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | ResultFuture<Result> future = connection |
| | | .delete(request, null, null); |
| | | ResultFuture<Result> future = connection.delete(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | ResultFuture<R> future = connection.extendedRequest(request, null, |
| | | null); |
| | | ResultFuture<R> future = connection.extendedRequest(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | ResultFuture<Result> future = connection |
| | | .modify(request, null, null); |
| | | ResultFuture<Result> future = connection.modify(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | ResultFuture<Result> future = connection.modifyDN(request, null, |
| | | null); |
| | | ResultFuture<Result> future = connection.modifyDN(request, null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public <P> Result search(SearchRequest request, |
| | | SearchResultHandler<P> handler, P p) throws ErrorResultException, |
| | | public Result search(SearchRequest request, |
| | | SearchResultHandler handler) throws ErrorResultException, |
| | | InterruptedException, UnsupportedOperationException, |
| | | IllegalStateException, NullPointerException |
| | | { |
| | | ResultFuture<Result> future = connection.search(request, null, |
| | | handler, p); |
| | | handler); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | UnsupportedOperationException, IllegalStateException |
| | | { |
| | | ResultFuture<Schema> future = connection.readSchemaForEntry(name, |
| | | null, null); |
| | | null); |
| | | try |
| | | { |
| | | return future.get(); |
| | |
| | | import com.sun.opends.sdk.ldap.LDAPConnectionFactoryImpl; |
| | | |
| | | |
| | | |
| | | /** |
| | | * LDAP connection factory implementation. |
| | | */ |
| | |
| | | |
| | | |
| | | |
| | | public <P> ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection, P> handler, |
| | | P p) |
| | | public ConnectionFuture<AsynchronousConnection> getAsynchronousConnection( |
| | | ConnectionResultHandler<? super AsynchronousConnection> handler) |
| | | { |
| | | return impl.getAsynchronousConnection(handler, p); |
| | | return impl.getAsynchronousConnection(handler); |
| | | } |
| | | |
| | | |
| | |
| | | * Implementations may choose to perform optimizations such as |
| | | * caching. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param connection |
| | | * A connection to the Directory Server whose schema is to be |
| | | * read. |
| | |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * If the {@code connection} or {@code name} was {@code |
| | | * null}. |
| | | */ |
| | | public static <P> ResultFuture<Schema> readSchema( |
| | | public static ResultFuture<Schema> readSchema( |
| | | AsynchronousConnection connection, DN name, |
| | | ResultHandler<? super Schema, P> handler, P p) |
| | | ResultHandler<? super Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | final SearchRequest request = getReadSchemaSearchRequest(name); |
| | | |
| | | final ResultTransformer<SearchResultEntry, Schema, P> future = new ResultTransformer<SearchResultEntry, Schema, P>( |
| | | final ResultTransformer<SearchResultEntry, Schema> future = new ResultTransformer<SearchResultEntry, Schema>( |
| | | handler) |
| | | { |
| | | |
| | |
| | | }; |
| | | |
| | | ResultFuture<SearchResultEntry> innerFuture = connection |
| | | .searchSingleEntry(request, future, p); |
| | | .searchSingleEntry(request, future); |
| | | future.setResultFuture(innerFuture); |
| | | return future; |
| | | } |
| | |
| | | * schema. However, implementations may choose to perform other |
| | | * optimizations, such as caching. |
| | | * |
| | | * @param <P> |
| | | * The type of the additional parameter to the handler's |
| | | * methods. |
| | | * @param connection |
| | | * A connection to the Directory Server whose schema is to be |
| | | * read. |
| | |
| | | * A result handler which can be used to asynchronously |
| | | * process the operation result when it is received, may be |
| | | * {@code null}. |
| | | * @param p |
| | | * Optional additional handler parameter. |
| | | * @return A future representing the result of the operation. |
| | | * @throws UnsupportedOperationException |
| | | * If this connection does not support search operations. |
| | |
| | | * If the {@code connection} or {@code name} was {@code |
| | | * null}. |
| | | */ |
| | | public static <P> ResultFuture<Schema> readSchemaForEntry( |
| | | public static ResultFuture<Schema> readSchemaForEntry( |
| | | final AsynchronousConnection connection, final DN name, |
| | | ResultHandler<Schema, P> handler, final P p) |
| | | ResultHandler<Schema> handler) |
| | | throws UnsupportedOperationException, IllegalStateException, |
| | | NullPointerException |
| | | { |
| | | final ResultChain<SearchResultEntry, Schema, P> future = new ResultChain<SearchResultEntry, Schema, P>( |
| | | final ResultChain<SearchResultEntry, Schema> future = new ResultChain<SearchResultEntry, Schema>( |
| | | handler) |
| | | { |
| | | |
| | | protected ResultFuture<Schema> chainResult( |
| | | SearchResultEntry innerResult, |
| | | ResultHandler<? super Schema, P> handler) |
| | | ResultHandler<? super Schema> handler) |
| | | throws ErrorResultException |
| | | { |
| | | final DN subschemaDN = getSubschemaSubentryDN(name, innerResult); |
| | | return readSchema(connection, subschemaDN, handler, p); |
| | | return readSchema(connection, subschemaDN, handler); |
| | | } |
| | | |
| | | }; |
| | | |
| | | final SearchRequest request = getReadSchemaForEntrySearchRequest(name); |
| | | ResultFuture<SearchResultEntry> innerFuture = connection |
| | | .searchSingleEntry(request, future, p); |
| | | .searchSingleEntry(request, future); |
| | | future.setInnerResultFuture(innerFuture); |
| | | return future; |
| | | } |