* @see java.lang.Runnable#run()
*/
public void run()
{
Object request = null;
SocketChannel channel = this._senderInfo.getChannel();
try
{
if ( !this._senderInfo.isConnected() )
{
log.log( Level.FINEST, "Handshaking client..." );
// handshake the client, get infos about compression...
this._senderInfo = DataChannel.getInstance().handshake( this._receiverInfo, channel,
EJConstants.EJOE_CONNECTION_TIMEOUT );
}
if ( this._senderInfo != null )
{
log.log( Level.FINEST, "Remote requested " + this._senderInfo.getAdapterName() );
SerializeAdapter adapter = AdapterFactory.createAdapter( this._senderInfo.getAdapterName() );
if ( this._receiverInfo.hasNonBlockingReadWrite() )
{
log.log( Level.FINEST, "Going to read client request on a non blocking socket..." );
request = read( adapter );
}
else
{
log.log( Level.FINEST, "Going to read client request on a blocking socket..." );
request = readBlocked( adapter );
}
this._senderInfo.releaseAttachment();
this._senderInfo.releaseWaitingBuffer();
log.log( Level.FINE, "Client request read." );
Object result = handleObject( request );
if ( this._registrar.isValid() )
{
this._senderInfo.setAttachment( result );
this._registrar.register( this._senderInfo, SelectionKey.OP_WRITE );
}
}
else
{
log.log( Level.WARNING, "Connection timeout reached while waiting for Handshake complete. "
+ "Closing connection." );
shutdownConnection( channel );
}
}
// partial read detected, registering for read again
catch ( IncompleteIOException ioe )
{
this._senderInfo.setWaitingBuffer( ioe.getIOBuffer() );
this._registrar.register( this._senderInfo, SelectionKey.OP_READ );
}
catch ( EOFException eof )
{
log.log( Level.FINEST, "EOF received while reading client data " + "- closing connection." );
shutdownConnection( channel );
}
catch ( ParseException pe )
{
log.log( Level.WARNING, "Unparseable connection header detected!", pe );
if ( !this._senderInfo.isHttp() )
{
this._senderInfo.setAttachment( new RemoteException( "Unparseable connection header!", pe ) );
}
else
{
this._senderInfo.setAttachment( new RemoteException( "Unparseable connection header!", pe ),
HttpResponse.HTTP_BAD_REQUEST );
}
this._registrar.register( this._senderInfo, SelectionKey.OP_WRITE );
}
catch ( SocketTimeoutException ste )
{
log.log( Level.FINE, "Timeout occured while waiting for client data!", ste );
shutdownConnection( channel );
}
catch ( RemoteException re )
{
if ( !this._senderInfo.isHttp() )
{
this._senderInfo.setAttachment( re );
}
else
{
this._senderInfo.setAttachment( re, HttpResponse.HTTP_INTERNAL_SERVER_ERROR );
}
this._registrar.register( this._senderInfo, SelectionKey.OP_WRITE );
}
// the client did something strange with the channel, probably the
// client is just too slow for
catch ( NonReadableChannelException e )
{
log.log( Level.INFO, "Connection probably closed by client." );
shutdownConnection( channel );
}
// the client did close the connection, or the connection was
// disconnected
catch ( ClosedChannelException cce )
{
log.log( Level.INFO, "Connection closed by client." );
shutdownConnection( channel );
}
catch ( Throwable e )
{
if ( !channel.isBlocking() && channel.isConnected() && channel.isOpen() )
{
// something goes completely wrong!
log.log( Level.WARNING, "!!! Exception while reading client data !!! "
+ "Probably the client just closed the connection but it could also be a serious failure.", e );
}