if (trace) { log.trace("Stream is NOT a DataOutputStream - must be using HTTP transport"); }
}
try
{
PacketSupport packet = null;
if (obj instanceof InvocationRequest)
{
InvocationRequest req = (InvocationRequest)obj;
Object param = req.getParameter();
if (param instanceof PacketSupport)
{
// A JBM invocation
packet = (PacketSupport)param;
if (trace) { log.trace("JBM Request"); }
}
else if (param instanceof OnewayInvocation)
{
if (trace) { log.trace("It's a OnewayInvocation"); }
// This is fucking horrendous - remoting should not force us to deal with
// its internal objects
// Hmmm... hidden somewhere in the depths of this crap there must be the callback,
// The search begins....
OnewayInvocation oneWay = (OnewayInvocation)param;
param = oneWay.getParameters()[0];
if (param instanceof RequestSupport)
{
//A JBM invocation being sent one way (e.g. changeRate, send)
if (trace) { log.trace("JBM oneway request"); }
packet = (PacketSupport)param;
}
else if (param instanceof InternalInvocation)
{
InternalInvocation ii = (InternalInvocation)param;
Object[] params = ii.getParameters();
if (trace) { log.trace("Params is " + params); }
if (params != null && params.length > 0 && params[0] instanceof Callback)
{
Callback callback = (Callback) params[0];
if (trace) { log.trace("It's a callback: " + callback); }
if (callback.getParameter() instanceof ClientDelivery)
{
packet = (ClientDelivery)callback.getParameter();
if (trace) { log.trace("Message delivery callback"); }
}
else if (callback.getParameter() instanceof ConnectionFactoryUpdate)
{
packet = (ConnectionFactoryUpdate)callback.getParameter();
if (trace) { log.trace("Connection factory update callback"); }
}
}
}
else
{
throw new IllegalArgumentException("Invalid request param " + param);
}
}
else
{
//Some other remoting internal thing, e.g. PING, DISCONNECT, add listener etc
packet = new SerializedPacket(req);
}
}
else if (obj instanceof InvocationResponse)
{
InvocationResponse resp = (InvocationResponse)obj;
Object param = resp.getResult();
if (param instanceof ResponseSupport)
{
// A JBM invocation response
packet = (ResponseSupport)param;
if (trace) { log.trace("JBM Response"); }
}
else if (param instanceof List)
{
// List of polled Callbacks, this is how messages are delivered when using
// polled callbacks e.g. the HTTP transport
packet = new PolledCallbacksDelivery((List)param, resp.getSessionId());
}
else if (param == null)
{
// Null response
packet = new NullResponse();
if (trace) { log.trace("Null Response"); }
}
else
{
// Return value from some remoting internal invocation e.g. PONG - return value from PING
packet = new SerializedPacket(obj);
}
}
else
{
//Actually this should never occur
packet = new SerializedPacket(obj);
}
if (trace) { log.trace("Writing packet: " + packet); }
packet.write(dos);
if (trace) { log.trace("Wrote packet"); }
}
catch (Exception e)
{