org.clazzes.remoting.server
Class ServerConnectionHandler
java.lang.Object
org.clazzes.remoting.cmd.CmdVisitorSupport
org.clazzes.remoting.server.ServerConnectionHandler
- All Implemented Interfaces:
- java.io.Closeable, java.lang.Runnable, CallbackInvocationContext, CmdVisitor, InvocationContext
public class ServerConnectionHandler
- extends CmdVisitorSupport
- implements CallbackInvocationContext, java.lang.Runnable, java.io.Closeable
A runnable connection handler for a single server connection of a client.
- Author:
- wglas
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ServerConnectionHandler
public ServerConnectionHandler(ServerRegistry serverRegistry,
java.rmi.server.UID clientUID,
Marshaler marshaler,
java.util.Map<java.lang.String,java.lang.Object> meta)
- Parameters:
serverRegistry
- marshaler
- The marshaler used for encapsulating the socket.clientUID
- The generated UID of the client.meta
-
getBroadcastable
public Broadcastable getBroadcastable()
- Specified by:
getBroadcastable
in interface CallbackInvocationContext
- Returns:
- The broadcast context for initiating broadcasts to all connected clients.
callBack
public java.lang.Object callBack(java.rmi.server.UID callbackUID,
java.lang.Object arg,
java.util.Map<java.lang.String,java.lang.Object> metadata)
throws java.lang.reflect.InvocationTargetException,
java.io.IOException
- Specified by:
callBack
in interface CallbackInvocationContext
- Parameters:
callbackUID
- The ID of the callback as returned by
RemoteInvoker.registerCallback(InvocationHandler)
.arg
- The argument, which is passed to the InvocationHandler
.metadata
- The metadata passed to the InvocationHandler
.
- Returns:
- The result of the callback
- Throws:
java.lang.reflect.InvocationTargetException
- If InvocationHandler.invoke(InvocationContext, Object, Map)
on the server threw an exception. The exception of the invoker may
be retrieved by InvocationTargetException.getCause()
.
java.io.IOException
- Upon transport errors.
getClientUID
public java.rmi.server.UID getClientUID()
- Specified by:
getClientUID
in interface InvocationContext
- Returns:
- The server-generated client UID, which is being assigned during the
startup handshake inside
Client.connect()
. Multiple clients connected
to the same server are guaranteed to have distinct client UIDs.
Return null
, if the client is not connected.
run
public void run()
- Specified by:
run
in interface java.lang.Runnable
close
public void close()
throws java.io.IOException
- Close the server connection. Please mind that the connection handler calls
ClientTerminationListener.clientTerminated(UID)
asynchronously.
- Specified by:
close
in interface java.io.Closeable
- Throws:
java.io.IOException
broadcast
public void broadcast(InvocationCmd cmd)
throws java.io.IOException
- Parameters:
cmd
- The invocation command to send to the client represented by this
connection.
- Throws:
java.io.IOException
- Upon errors from the marshaler.
visit
public void visit(InvocationCmd cmd)
- Specified by:
visit
in interface CmdVisitor
- Overrides:
visit
in class CmdVisitorSupport
visit
public void visit(LoadClassCmd cmd)
- Specified by:
visit
in interface CmdVisitor
- Overrides:
visit
in class CmdVisitorSupport
visit
public void visit(InvocationResultCmd cmd)
- Specified by:
visit
in interface CmdVisitor
- Overrides:
visit
in class CmdVisitorSupport
visit
public void visit(InvocationExceptionCmd cmd)
- Specified by:
visit
in interface CmdVisitor
- Overrides:
visit
in class CmdVisitorSupport
Copyright © 2010. All Rights Reserved.