String msg = "Cannot process a null extendedRequest";
LOG.debug( msg );
throw new IllegalArgumentException( msg );
}
ExtendedFuture extendedFuture = extendedAsync( extendedRequest );
// Get the result from the future
try
{
// Read the response, waiting for it if not available immediately
// Get the response, blocking
ExtendedResponse response = ( ExtendedResponse ) extendedFuture
.get( timeout, TimeUnit.MILLISECONDS );
if ( response == null )
{
// We didn't received anything : this is an error
LOG.error( "Extended failed : timeout occurred" );
throw new LdapException( TIME_OUT_ERROR );
}
if ( response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Extended successful : {}", response );
}
else
{
// We have had an error
LOG.debug( "Extended failed : {}", response );
}
// Get back the response. It's still an opaque response
if ( Strings.isEmpty( response.getResponseName() ) )
{
response.setResponseName( extendedRequest.getRequestName() );
}
// Decode the payload now
ExtendedResponseDecorator<?> decoratedResponse = codec.decorate( response );
return decoratedResponse;
}
catch ( TimeoutException te )
{
// Send an abandon request
if ( !extendedFuture.isCancelled() )
{
abandon( extendedRequest.getMessageId() );
}
// We didn't received anything : this is an error
LOG.error( "Extended failed : timeout occurred" );
throw new LdapException( TIME_OUT_ERROR, te );
}
catch ( Exception ie )
{
// Catch all other exceptions
LOG.error( NO_RESPONSE_ERROR, ie );
// Send an abandon request
if ( !extendedFuture.isCancelled() )
{
abandon( extendedRequest.getMessageId() );
}
throw new LdapException( NO_RESPONSE_ERROR, ie );