org.sourceforge.jemm.comm.client
Class RPCClient

java.lang.Object
  extended by org.sourceforge.jemm.comm.client.RPCClient
All Implemented Interfaces:
RPCHandlerListener

public class RPCClient
extends java.lang.Object
implements RPCHandlerListener

RPCClient is the client end of an interface RPC connection. The class allows the client program to both make RPC calls to a server instance and also present interfaces for the server to call back on. See EchoClient/ EchoServer for a simple example.

Released under the Apache License V2.0 license by the JEMM Project

Author:
Rory Graves

Field Summary
protected  boolean connected
           
protected  ClientConnectionFactory connFactory
           
protected  java.util.Map<java.lang.Class<?>,java.lang.Object> localIFMap
          A map of the local interfaces offered by the client to the server
protected static org.apache.log4j.Logger LOG
           
protected  RPCHandler rpcHandler
          The underlying RPCHandler (calls are delegated)
protected  java.util.concurrent.ExecutorService threadPool
          A thread pool for handling server callback requests
 
Constructor Summary
RPCClient(ClientConnectionFactory connFactory)
          Creates o RPCClient instance using the given connection factory.
RPCClient(java.lang.String hostname, int port)
          Creates an RPCClient instance.
 
Method Summary
 void close()
          Close the connection to the server.
 void connect()
          Make the connection to the remote server.
 void connectionTerminated()
          Notification that the RPCHandler has had the connection terminated.
 java.lang.Object getServerIF(java.lang.Class<?> ifClass)
          Get a remote interface implemented by the server.
 boolean isConnected()
          Returns whether the client is connected to the server
 void registerIF(java.lang.Class<?> ifClass, java.lang.Object ifImplentor)
          Register an interface that the client offers for callback from the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.log4j.Logger LOG

localIFMap

protected java.util.Map<java.lang.Class<?>,java.lang.Object> localIFMap
A map of the local interfaces offered by the client to the server


rpcHandler

protected RPCHandler rpcHandler
The underlying RPCHandler (calls are delegated)


threadPool

protected java.util.concurrent.ExecutorService threadPool
A thread pool for handling server callback requests


connected

protected volatile boolean connected

connFactory

protected final ClientConnectionFactory connFactory
Constructor Detail

RPCClient

public RPCClient(java.lang.String hostname,
                 int port)
Creates an RPCClient instance. The client attempts to connect to the hostname/port specified and will throw an IOException on error

Parameters:
hostname - The servers hostname
port - The server's port

RPCClient

public RPCClient(ClientConnectionFactory connFactory)
Creates o RPCClient instance using the given connection factory.

Parameters:
connFactory - The connection factory to use to connect to the RPCServer.
Method Detail

connect

public void connect()
             throws ConnectionException
Make the connection to the remote server.

Throws:
ConnectionException - On connection error.

registerIF

public void registerIF(java.lang.Class<?> ifClass,
                       java.lang.Object ifImplentor)
Register an interface that the client offers for callback from the server.

Parameters:
ifClass - The interface being offered.
ifImplentor - The implementor of the interface that will process the requests

getServerIF

public java.lang.Object getServerIF(java.lang.Class<?> ifClass)
Get a remote interface implemented by the server.

Parameters:
ifClass - The interface required.
Returns:
A proxy object implementing the remote interface.

close

public void close()
Close the connection to the server.


isConnected

public boolean isConnected()
Returns whether the client is connected to the server

Returns:
True if the client is connected, false otherwise.

connectionTerminated

public void connectionTerminated()
Description copied from interface: RPCHandlerListener
Notification that the RPCHandler has had the connection terminated.

Specified by:
connectionTerminated in interface RPCHandlerListener


Copyright © 2009. All Rights Reserved.