|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.sourceforge.jemm.comm.shared.RPCHandler
public class RPCHandler
RPCHandler is used to implement the shared logic used by both org.sourceforge.jemm.comm.server.RPCClient
and RPCServer
.
Given a socket RPCHandler basically manages the client and server interfaces, the proxies and the
actual message passing.
N.B. A client/server flag is passed to the constructor because ObjectInputStream
/ObjectOutputStream
must be invoked in alternate order on the two sides of the connection or it deadlocks.
Field Summary | |
---|---|
protected boolean |
closing
|
protected Connection |
connection
|
protected java.lang.Object |
connectionId
|
protected java.util.concurrent.CountDownLatch |
initialisationLatch
|
protected java.io.ObjectInputStream |
is
|
protected boolean |
isClient
|
protected RPCHandlerListener |
listener
|
protected java.util.Map<java.lang.Class<?>,java.lang.Object> |
localInterfaces
|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.SynchronousQueue<Message>> |
msgSyncPoints
|
protected java.io.ObjectOutputStream |
os
|
protected java.util.Map<java.lang.Class<?>,java.lang.Object> |
remoteInterfaces
|
protected java.util.concurrent.ExecutorService |
requestExecutor
|
protected java.lang.ThreadLocal<java.util.concurrent.SynchronousQueue<Message>> |
syncQueueTL
|
protected java.lang.ThreadLocal<java.lang.String> |
threadIdTL
|
Constructor Summary | |
---|---|
RPCHandler(boolean isClient,
Connection connection,
java.util.Map<java.lang.Class<?>,java.lang.Object> localInterfaces,
java.util.concurrent.ExecutorService requestExecutor,
java.lang.Object connectionId)
Create an RPCHandler |
Method Summary | |
---|---|
void |
close()
Close the connection to the server. |
protected void |
connectionTerminated()
|
protected java.lang.Object |
createProxyClass(java.lang.Class<?> ifClass)
|
static java.lang.Object |
getConnectionId()
Retrieve the connection id object associated with the current processing thread. |
java.lang.Object |
getRemoteIF(java.lang.Class<?> ifClass)
Returns an local interface for calling the remote interface. |
void |
initialise()
|
protected void |
makeAsyncCall(java.lang.Class<?> ifClass,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Object[] args)
Internal method to make an asynchronous call to a given method. |
protected RPCCallRespMessage |
makeSyncCall(java.lang.Class<?> ifClass,
java.lang.String methodName,
java.lang.Class<?>[] parameterTypes,
java.lang.Object[] args)
Internal method to make a make a synchronous call to a given method. |
protected void |
processCallMessage(RPCCallMessage message)
Internal method to handle RPC call method. |
protected void |
receiveMessage(Message message)
|
void |
run()
|
Message |
sendSyncMessage(Message message)
Send a synchronous message to the server. |
void |
setHandlerListener(RPCHandlerListener newListener)
Set the listener for this handler for event notification. |
void |
start()
Start the RPCHandler. |
protected void |
writeMessage(Message message)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Connection connection
protected java.util.concurrent.CountDownLatch initialisationLatch
protected volatile boolean closing
protected java.io.ObjectInputStream is
protected java.io.ObjectOutputStream os
protected java.util.Map<java.lang.Class<?>,java.lang.Object> remoteInterfaces
protected java.util.Map<java.lang.Class<?>,java.lang.Object> localInterfaces
protected java.util.concurrent.ExecutorService requestExecutor
protected java.lang.ThreadLocal<java.lang.String> threadIdTL
protected java.lang.ThreadLocal<java.util.concurrent.SynchronousQueue<Message>> syncQueueTL
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.SynchronousQueue<Message>> msgSyncPoints
protected final boolean isClient
protected RPCHandlerListener listener
protected java.lang.Object connectionId
Constructor Detail |
---|
public RPCHandler(boolean isClient, Connection connection, java.util.Map<java.lang.Class<?>,java.lang.Object> localInterfaces, java.util.concurrent.ExecutorService requestExecutor, java.lang.Object connectionId)
isClient
- Is this the client side of the connection (false for server)connection
- The socket connection.localInterfaces
- The interfaces this side offers.requestExecutor
- The service to use for running requests.connectionId
- The id of the connection.Method Detail |
---|
public void setHandlerListener(RPCHandlerListener newListener)
newListener
- The listener to inform of events.public java.lang.Object getRemoteIF(java.lang.Class<?> ifClass)
ifClass
- The interface to get.
java.lang.IllegalArgumentException
- If the requested class is not an interface or not supported.protected java.lang.Object createProxyClass(java.lang.Class<?> ifClass)
public void initialise()
public void run()
run
in interface java.lang.Runnable
protected void receiveMessage(Message message)
protected void processCallMessage(RPCCallMessage message)
message
- The message to process.protected void connectionTerminated()
public void close()
protected void writeMessage(Message message)
public Message sendSyncMessage(Message message)
message
- The message to send
protected void makeAsyncCall(java.lang.Class<?> ifClass, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args)
ifClass
- The interface class being called.methodName
- The method being called.parameterTypes
- The parameter types of the methodargs
- The actual call arguments (based types wrapped by Proxy.invoke).protected RPCCallRespMessage makeSyncCall(java.lang.Class<?> ifClass, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args)
ifClass
- The interface class being called.methodName
- The method being called.parameterTypes
- The parameter types of the methodargs
- The actual call arguments (based types wrapped by Proxy.invoke).
public static java.lang.Object getConnectionId()
public void start()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |