| | |
| | | * then the connection attempt will fail and an {@code |
| | | * ErrorResultException} will be thrown. |
| | | */ |
| | | final class AuthenticatedConnectionFactory |
| | | implements |
| | | ConnectionFactory<AuthenticatedConnectionFactory.AuthenticatedAsynchronousConnection> |
| | | final class AuthenticatedConnectionFactory extends |
| | | AbstractConnectionFactory implements ConnectionFactory |
| | | { |
| | | // We implement the factory using the pimpl idiom in order have |
| | | // cleaner Javadoc which does not expose implementation methods from |
| | | // AbstractConnectionFactory. |
| | | |
| | | private static final class Impl |
| | | extends |
| | | AbstractConnectionFactory<AuthenticatedConnectionFactory.AuthenticatedAsynchronousConnection> |
| | | implements |
| | | ConnectionFactory<AuthenticatedConnectionFactory.AuthenticatedAsynchronousConnection> |
| | | { |
| | | private final BindRequest request; |
| | | private final BindRequest request; |
| | | |
| | | private final ConnectionFactory<?> parentFactory; |
| | | private final ConnectionFactory parentFactory; |
| | | |
| | | private boolean allowRebinds = false; |
| | | |
| | | |
| | | |
| | | private Impl(ConnectionFactory<?> factory, BindRequest request) |
| | | throws NullPointerException |
| | | { |
| | | Validator.ensureNotNull(factory, request); |
| | | this.parentFactory = factory; |
| | | |
| | | // FIXME: should do a defensive copy. |
| | | this.request = request; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public FutureResult<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | { |
| | | FutureResultImpl future = new FutureResultImpl(request, handler); |
| | | future.futureConnectionResult.setFutureResult(parentFactory |
| | | .getAsynchronousConnection(future.futureConnectionResult)); |
| | | return future.futureBindResult; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public AuthenticatedConnection getConnection() |
| | | throws ErrorResultException |
| | | { |
| | | return new AuthenticatedConnection( |
| | | blockingGetAsynchronousConnection()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | private final Impl impl; |
| | | private boolean allowRebinds = false; |
| | | |
| | | |
| | | |
| | |
| | | * @throws NullPointerException |
| | | * If {@code factory} or {@code request} was {@code null}. |
| | | */ |
| | | public AuthenticatedConnectionFactory(ConnectionFactory<?> factory, |
| | | public AuthenticatedConnectionFactory(ConnectionFactory factory, |
| | | BindRequest request) throws NullPointerException |
| | | { |
| | | impl = new Impl(factory, request); |
| | | Validator.ensureNotNull(factory, request); |
| | | this.parentFactory = factory; |
| | | |
| | | // FIXME: should do a defensive copy. |
| | | this.request = request; |
| | | } |
| | | |
| | | |
| | | |
| | | private static final class FutureResultImpl |
| | | { |
| | | private final FutureResultTransformer<BindResult, AuthenticatedAsynchronousConnection> futureBindResult; |
| | | private final FutureResultTransformer<BindResult, AsynchronousConnection> futureBindResult; |
| | | |
| | | private final RecursiveFutureResult<AsynchronousConnection, BindResult> futureConnectionResult; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | private FutureResultImpl( |
| | | BindRequest request, |
| | | ResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | private FutureResultImpl(BindRequest request, |
| | | ResultHandler<AsynchronousConnection> handler) |
| | | { |
| | | this.bindRequest = request; |
| | | this.futureBindResult = new FutureResultTransformer<BindResult, AuthenticatedAsynchronousConnection>( |
| | | this.futureBindResult = new FutureResultTransformer<BindResult, AsynchronousConnection>( |
| | | handler) |
| | | { |
| | | |
| | |
| | | public AuthenticatedConnectionFactory setRebindAllowed( |
| | | boolean allowRebinds) |
| | | { |
| | | impl.allowRebinds = allowRebinds; |
| | | this.allowRebinds = allowRebinds; |
| | | return this; |
| | | } |
| | | |
| | |
| | | */ |
| | | public boolean isRebindAllowed() |
| | | { |
| | | return impl.allowRebinds; |
| | | return allowRebinds; |
| | | } |
| | | |
| | | |
| | | |
| | | public FutureResult<AuthenticatedAsynchronousConnection> getAsynchronousConnection( |
| | | ResultHandler<? super AuthenticatedAsynchronousConnection> handler) |
| | | public FutureResult<AsynchronousConnection> getAsynchronousConnection( |
| | | ResultHandler<AsynchronousConnection> handler) |
| | | { |
| | | return impl.getAsynchronousConnection(handler); |
| | | FutureResultImpl future = new FutureResultImpl(request, handler); |
| | | future.futureConnectionResult.setFutureResult(parentFactory |
| | | .getAsynchronousConnection(future.futureConnectionResult)); |
| | | return future.futureBindResult; |
| | | } |
| | | |
| | | |
| | |
| | | public AuthenticatedConnection getConnection() |
| | | throws ErrorResultException |
| | | { |
| | | return impl.getConnection(); |
| | | return new AuthenticatedConnection( |
| | | (AuthenticatedAsynchronousConnection) blockingGetAsynchronousConnection()); |
| | | } |
| | | |
| | | } |