* @throws Exception If there is some error while processing the message
*/
public void messageReceived( IoSession session, Object message ) throws Exception
{
// Feed the response and store it into the session
Message response = ( Message ) message;
LOG.debug( "-------> {} Message received <-------", response );
int messageId = response.getMessageId();
// this check is necessary to prevent adding an abandoned operation's
// result(s) to corresponding queue
ResponseFuture<? extends Response> responseFuture = peekFromFutureMap( messageId );
boolean isNoD = isNoticeOfDisconnect( response );
if ( ( responseFuture == null ) && !isNoD )
{
LOG.info( "There is no future associated with the messageId {}, ignoring the message", messageId );
return;
}
if ( isNoD )
{
// close the session
session.close( true );
return;
}
switch ( response.getType() )
{
case ADD_RESPONSE:
// Transform the response
AddResponse addResponse = ( AddResponse ) response;
AddFuture addFuture = ( AddFuture ) responseFuture;
// remove the listener from the listener map
if ( LOG.isDebugEnabled() )
{
if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Add successful : {}", addResponse );
}
else
{
// We have had an error
LOG.debug( "Add failed : {}", addResponse );
}
}
// Store the response into the future
addFuture.set( addResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case BIND_RESPONSE:
// Transform the response
BindResponse bindResponse = ( BindResponse ) response;
BindFuture bindFuture = ( BindFuture ) responseFuture;
// remove the listener from the listener map
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
authenticated.set( true );
// Everything is fine, return the response
LOG.debug( "Bind successful : {}", bindResponse );
}
else
{
// We have had an error
LOG.debug( "Bind failed : {}", bindResponse );
}
// Store the response into the future
bindFuture.set( bindResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case COMPARE_RESPONSE:
// Transform the response
CompareResponse compareResponse = ( CompareResponse ) response;
CompareFuture compareFuture = ( CompareFuture ) responseFuture;
// remove the listener from the listener map
if ( LOG.isDebugEnabled() )
{
if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Compare successful : {}", compareResponse );
}
else
{
// We have had an error
LOG.debug( "Compare failed : {}", compareResponse );
}
}
// Store the response into the future
compareFuture.set( compareResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case DEL_RESPONSE:
// Transform the response
DeleteResponse deleteResponse = ( DeleteResponse ) response;
DeleteFuture deleteFuture = ( DeleteFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
if ( deleteResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Delete successful : {}", deleteResponse );
}
else
{
// We have had an error
LOG.debug( "Delete failed : {}", deleteResponse );
}
}
// Store the response into the future
deleteFuture.set( deleteResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case EXTENDED_RESPONSE:
// Transform the response
ExtendedResponse extendedResponse = ( ExtendedResponse ) response;
ExtendedFuture extendedFuture = ( ExtendedFuture ) responseFuture;
// remove the listener from the listener map
if ( LOG.isDebugEnabled() )
{
if ( extendedResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Extended successful : {}", extendedResponse );
}
else
{
// We have had an error
LOG.debug( "Extended failed : {}", extendedResponse );
}
}
// Store the response into the future
extendedFuture.set( extendedResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case INTERMEDIATE_RESPONSE:
IntermediateResponse intermediateResponse = null;
if ( responseFuture instanceof SearchFuture )
{
intermediateResponse = new IntermediateResponseImpl( messageId );
addControls( intermediateResponse, ( IntermediateResponse ) response );
( ( SearchFuture ) responseFuture ).set( intermediateResponse );
}
else if ( responseFuture instanceof ExtendedFuture )
{
intermediateResponse = new IntermediateResponseImpl( messageId );
addControls( intermediateResponse, ( IntermediateResponse ) response );
( ( ExtendedFuture ) responseFuture ).set( intermediateResponse );
}
else
{
// currently we only support IR for search and extended operations
throw new UnsupportedOperationException( "Unknown ResponseFuture type "
+ responseFuture.getClass().getName() );
}
intermediateResponse.setResponseName( ( ( IntermediateResponse ) response ).getResponseName() );
intermediateResponse.setResponseValue( ( ( IntermediateResponse ) response ).getResponseValue() );
break;
case MODIFY_RESPONSE:
// Transform the response
ModifyResponse modifyResponse = ( ModifyResponse ) response;
ModifyFuture modifyFuture = ( ModifyFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
if ( modifyResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "ModifyFuture successful : {}", modifyResponse );
}
else
{
// We have had an error
LOG.debug( "ModifyFuture failed : {}", modifyResponse );
}
}
// Store the response into the future
modifyFuture.set( modifyResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case MODIFYDN_RESPONSE:
// Transform the response
ModifyDnResponse modifyDnResponse = ( ModifyDnResponse ) response;
ModifyDnFuture modifyDnFuture = ( ModifyDnFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
if ( modifyDnResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "ModifyDN successful : {}", modifyDnResponse );
}
else
{
// We have had an error
LOG.debug( "ModifyDN failed : {}", modifyDnResponse );
}
}
// Store the response into the future
modifyDnFuture.set( modifyDnResponse );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case SEARCH_RESULT_DONE:
// Store the response into the responseQueue
SearchResultDone searchResultDone = ( SearchResultDone ) response;
SearchFuture searchFuture = ( SearchFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Search successful : {}", searchResultDone );
}
else
{
// We have had an error
LOG.debug( "Search failed : {}", searchResultDone );
}
}
// Store the response into the future
searchFuture.set( searchResultDone );
// Remove the future from the map
removeFromFutureMaps( messageId );
break;
case SEARCH_RESULT_ENTRY:
// Store the response into the responseQueue
SearchResultEntry searchResultEntry = ( SearchResultEntry ) response;
if ( schemaManager != null )
{
searchResultEntry.setEntry( new DefaultEntry( schemaManager, searchResultEntry.getEntry() ) );
}
searchFuture = ( SearchFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
LOG.debug( "Search entry found : {}", searchResultEntry );
}
// Store the response into the future
searchFuture.set( searchResultEntry );
break;
case SEARCH_RESULT_REFERENCE:
// Store the response into the responseQueue
SearchResultReference searchResultReference = ( SearchResultReference ) response;
searchFuture = ( SearchFuture ) responseFuture;
if ( LOG.isDebugEnabled() )
{
LOG.debug( "Search reference found : {}", searchResultReference );
}
// Store the response into the future
searchFuture.set( searchResultReference );
break;
default:
throw new IllegalStateException( "Unexpected response type " + response.getType() );
}
}