org.jboss.remoting.stream
public class: StreamServer.Handler [javadoc |
source]
java.lang.Object
org.jboss.remoting.stream.StreamServer$Handler
All Implemented Interfaces:
ServerInvocationHandler
Handler for accepting method calls on the input stream and perform the coresponding
method call on the original input stream and returning the data.
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.jboss.remoting.stream.StreamServer$Handler Detail: |
public void addListener(InvokerCallbackHandler callbackHandler) {
// NO OP as do not handling callback listeners in this example
}
Adds a callback handler that will listen for callbacks from
the server invoker handler. |
public Object invoke(InvocationRequest invocation) throws Throwable {
Object obj = invocation.getParameter();
// will expect the parameter to ALWAYS be of type StreamCallPaylod
if(obj instanceof StreamCallPayload)
{
StreamCallPayload payload = (StreamCallPayload) obj;
String method = payload.getMethod();
if(StreamHandler.READ.equals(method))
{
int i = streamSource.read();
return new Integer(i);
}
else if(StreamHandler.AVAILABLE.equals(method))
{
int i = streamSource.available();
return new Integer(i);
}
else if(StreamHandler.CLOSE.equals(method))
{
streamSource.close();
if(connector != null && internalConnector)
{
connector.stop();
connector.destroy();
}
}
else if(StreamHandler.RESET.equals(method))
{
streamSource.reset();
}
else if(StreamHandler.MARKSUPPORTED.equals(method))
{
boolean b = streamSource.markSupported();
return new Boolean(b);
}
else if(StreamHandler.MARKREADLIMIT.equals(method))
{
Object[] param = payload.getParams();
Integer intr = (Integer) param[0];
int readLimit = intr.intValue();
streamSource.mark(readLimit);
}
else if(StreamHandler.SKIP.equals(method))
{
Object[] param = payload.getParams();
Long lg = (Long) param[0];
long n = lg.longValue();
long ret = streamSource.skip(n);
return new Long(ret);
}
else if(StreamHandler.READBYTEARRAY.equals(method))
{
Object[] param = payload.getParams();
byte[] byteParam = (byte[]) param[0];
int i = streamSource.read(byteParam);
StreamCallPayload ret = new StreamCallPayload(StreamHandler.READBYTEARRAY);
ret.setParams(new Object[]{byteParam, new Integer(i)});
return ret;
}
else
{
throw new Exception("Unsupported method call - " + method);
}
}
else
{
log.error("Can not process invocation request because is not of type StreamCallPayload.");
throw new Exception("Invalid payload type. Must be of type StreamCallPayload.");
}
return null;
}
|
public void removeListener(InvokerCallbackHandler callbackHandler) {
// NO OP as do not handling callback listeners in this example
}
Removes the callback handler that was listening for callbacks
from the server invoker handler. |
public void setInvoker(ServerInvoker invoker) {
// NO OP as do not need reference back to the server invoker
}
set the invoker that owns this handler |
public void setMBeanServer(MBeanServer server) {
// NO OP as do not need reference to MBeanServer for this handler
}
set the mbean server that the handler can reference |