package org.jboss.mq.il.oil2;
import java.io.IOException;
import java.rmi.RemoteException;
import org.jboss.mq.Connection;
import org.jboss.mq.ReceiveRequest;
import org.jboss.mq.SpyDestination;
public final class OIL2ClientILService
implements org.jboss.mq.il.ClientILService, OIL2RequestListner
{
private Connection connection;
OIL2ServerIL serverIL;
OIL2SocketHandler socketHandler;
public org.jboss.mq.il.ClientIL getClientIL() throws java.lang.Exception
{
return new OIL2ClientIL();
}
public void init(org.jboss.mq.Connection connection, java.util.Properties props) throws java.lang.Exception
{
this.connection = connection;
}
public void start() throws java.lang.Exception
{
serverIL = (OIL2ServerIL) connection.getServerIL();
socketHandler = serverIL.socketHandler;
socketHandler.setRequestListner(this);
}
public void stop() throws java.lang.Exception
{
}
public void handleConnectionException(Exception e)
{
connection.asynchFailure("Connection failure", e);
serverIL.close();
}
public void handleRequest(OIL2Request request)
{
Object result = null;
Exception resultException = null;
try
{
switch (request.operation)
{
case OIL2Constants.CLIENT_RECEIVE :
connection.asynchDeliver((ReceiveRequest[]) request.arguments[0]);
break;
case OIL2Constants.CLIENT_DELETE_TEMPORARY_DESTINATION :
connection.asynchDeleteTemporaryDestination((SpyDestination) request.arguments[0]);
break;
case OIL2Constants.CLIENT_CLOSE :
connection.asynchClose();
break;
case OIL2Constants.CLIENT_PONG :
connection.asynchPong(((Long) request.arguments[0]).longValue());
break;
default :
throw new RemoteException("Bad method code !");
} }
catch (Exception e)
{
resultException = e;
}
try
{
OIL2Response response = new OIL2Response(request);
response.result = result;
response.exception = resultException;
socketHandler.sendResponse(response);
}
catch (IOException e)
{
handleConnectionException(e);
}
}
}