if ( result != null && (result instanceof Throwable) )
{
if ( !(result instanceof RemoteException) )
{
throw new RemoteException(
"The server did return an Exception while handling your request!",
(Throwable) result );
}
else
{
throw (RemoteException) result;
}
}
return result;
}
}
else if ( selKey.isReadable() )
{
result = receive( clientInfo );
selKey.cancel();
if ( result != null && (result instanceof Throwable) )
{
if ( !(result instanceof RemoteException) )
{
throw new RemoteException(
"The server did return an Exception while handling your request!",
(Throwable) result );
}
else
{
throw (RemoteException) result;
}
}
return result;
}
}
catch ( IncompleteIOException ioe )
{
// selKey.cancel();
if ( ioe.getIOBuffer() != null )
{
clientInfo.setWaitingBuffer( ioe.getIOBuffer() );
_channel.register( this._selector, ioe.getSelectionInterest() );
}
else
{
// rethrow origin exception to inform the caller
// without the hassle of nested exceptions
throw ioe;
}
}
catch ( ParseException e )
{
error = true;
throw new IOException(
"Connection closed due to unparseable connection header! Exact message was: "
+ e.getMessage() );
}
catch ( IOException e )
{
if ( !(e instanceof RemoteException) )
{
error = true;
}
// rethrow origin exception to inform the caller
// without the hassle of nested exceptions
throw e;
}
}
}
}
finally
{
selKey.cancel();
// beeing a little bit paranoid is sometimes better
clientInfo.releaseAttachment();
clientInfo.releaseWaitingBuffer();
if ( _serverInfo != null )
{
_serverInfo.releaseAttachment();
_serverInfo.releaseWaitingBuffer();
}
if ( error )
{
close();
}
else if ( !clientInfo.isPersistent() || _serverInfo == null || !_serverInfo.isPersistent() )
{
close();
}
else
{
// clean out cancelled keys
this._selector.selectNow();
if ( _channel.isBlocking() ) _channel.configureBlocking( false );
}
}
}
if ( result != null && result instanceof Throwable )
{
throw new RemoteException( "The server did return an Exception while handling your request!",
(Throwable) result );
}
return result;
}