* @return delete operation's response, null if a non-null listener value is provided
* @throws LdapException If the DN is not valid or if the deletion failed
*/
public DeleteResponse delete( DeleteRequest deleteRequest ) throws LdapException
{
DeleteFuture deleteFuture = deleteAsync( deleteRequest );
// Get the result from the future
try
{
// Read the response, waiting for it if not available immediately
long timeout = getTimeout( deleteRequest.getTimeout() );
// Get the response, blocking
DeleteResponse delResponse = ( DeleteResponse ) deleteFuture.get( timeout, TimeUnit.MILLISECONDS );
if ( delResponse == null )
{
// We didn't received anything : this is an error
LOG.error( "Delete failed : timeout occured" );
throw new LdapException( TIME_OUT_ERROR );
}
if ( delResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Delete successful : {}", delResponse );
}
else
{
// We have had an error
LOG.debug( "Delete failed : {}", delResponse );
}
return delResponse;
}
catch ( TimeoutException te )
{
// Send an abandon request
if ( !deleteFuture.isCancelled() )
{
abandon( deleteRequest.getMessageId() );
}
// We didn't received anything : this is an error
LOG.error( "Del failed : timeout occured" );
throw new LdapException( TIME_OUT_ERROR );
}
catch ( Exception ie )
{
// Catch all other exceptions
LOG.error( NO_RESPONSE_ERROR, ie );
LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
ldapException.initCause( ie );
// Send an abandon request
if ( !deleteFuture.isCancelled() )
{
abandon( deleteRequest.getMessageId() );
}
throw ldapException;