org.sourceforge.jemmrpc.client
Class RPCClient

java.lang.Object
  extended by org.sourceforge.jemmrpc.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.

Author:
Rory Graves

Field Summary
protected  boolean connected
           
protected  java.lang.String hostname
          The server hostname
protected  java.util.HashMap<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 logger
           
protected  int port
          The server port
protected  RPCHandler rpcHandler
          The underlying RPCHandler (calls are delegated)
protected  java.net.Socket socket
          The connection socket
protected  java.util.concurrent.ExecutorService threadPool
          A thread pool for handling server callback requests
 
Constructor Summary
RPCClient(java.lang.String hostname, int port)
          Creates an instance of Client.
 
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

logger

protected static final org.apache.log4j.Logger logger

localIFMap

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


hostname

protected java.lang.String hostname
The server hostname


port

protected int port
The server port


socket

protected java.net.Socket socket
The connection socket


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
Constructor Detail

RPCClient

public RPCClient(java.lang.String hostname,
                 int port)
Creates an instance of Client. 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
Method Detail

connect

public void connect()
             throws java.io.IOException
Make the connection to the remote server.

Throws:
java.io.IOException - 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 © 2008. All Rights Reserved.