|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.sourceforge.jemmrpc.server.RPCServer
public class RPCServer
The RPCServer offers RPC interfaces to connecting clients. The server can handle multiple client
connections.
See EchoClient
/EchoServer
for an example of usage.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected java.util.Map<ClientId,ServerThread> |
clientThreads
The map of clientIds to active clients |
protected boolean |
closing
Used for graceful shutdown. |
protected java.util.concurrent.CountDownLatch |
initialisationLatch
A latch to ensure server is ready when initialisation call returns. |
protected static org.apache.log4j.Logger |
logger
|
protected java.util.concurrent.ExecutorService |
msgProccessingThreadPool
The thread pool for processing client call requests (shared among all clients) |
protected int |
port
The port the server listens on. |
protected java.net.ServerSocket |
serverSocket
The server socket which listens for client connections. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
RPCServer(int port,
java.util.concurrent.ExecutorService executorService)
Creates an RPCServer instance |
|
RPCServer(int port,
int noProcessingThreads)
Creates an RPCServer instance |
Method Summary | |
---|---|
void |
clientDisconnected(ClientId clientId)
Notification that a given client has disconnected. |
ClientId |
getClientId()
Used by called methods to find out ID of calling client. |
java.lang.Object |
getClientIF(ClientId clientId,
java.lang.Class<?> ifClass)
Retrieve a proxy for the given interface on the given client. |
void |
notifyNewClient(ClientId clientId,
java.lang.String clientHostname,
int clientPort)
|
void |
processMessage(ClientId clientId,
Message message)
Process an incoming message. |
void |
registerInterface(java.lang.Class<?> targetIF,
java.lang.Object targetIFImpl)
Register an interface for RPC calls by clients. |
void |
run()
|
void |
setClientListener(ClientConnectionListener listener)
Sets the client listener to the given listener. |
void |
shutdown()
Request by the system for the server to be shutdown. |
void |
waitForInitialisation()
This method will pause the caller until the server is ready to start accepting connections. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.log4j.Logger logger
protected java.util.Map<ClientId,ServerThread> clientThreads
protected java.util.concurrent.CountDownLatch initialisationLatch
protected boolean closing
protected java.util.concurrent.ExecutorService msgProccessingThreadPool
protected int port
protected java.net.ServerSocket serverSocket
Constructor Detail |
---|
public RPCServer(int port, int noProcessingThreads)
port
- The socket to listen for connections onnoProcessingThreads
- The number of processing threads.public RPCServer(int port, java.util.concurrent.ExecutorService executorService)
port
- The socket to listen for connections onexecutorService
- The executor used to service requests.Method Detail |
---|
public ClientId getClientId()
public java.lang.Object getClientIF(ClientId clientId, java.lang.Class<?> ifClass)
clientId
- The id of the client.ifClass
- The required interface class.
public void clientDisconnected(ClientId clientId)
clientId
- The assigned id of the disconnected client.public void processMessage(ClientId clientId, Message message)
clientId
- The ID of the sending client.message
- The received message.public void waitForInitialisation()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void shutdown()
public void registerInterface(java.lang.Class<?> targetIF, java.lang.Object targetIFImpl)
targetIF
- The interface to offer to clients.targetIFImpl
- The server side implementation of the given interface.public void setClientListener(ClientConnectionListener listener)
listener
- The listener to receive disconnection events.public void notifyNewClient(ClientId clientId, java.lang.String clientHostname, int clientPort)
clientId
- The id of the new client.clientHostname
- The clients hostname.clientPort
- The clients port.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |