Holger's
Java API

com.antelmann.net
Class RemoteNetInterfaceProtocol

java.lang.Object
  extended by com.antelmann.net.RemoteNetInterfaceProtocol
All Implemented Interfaces:
NetConnectionHandler

public class RemoteNetInterfaceProtocol
extends Object
implements NetConnectionHandler

implements a convenient protocol for invoking calls to an object remotely using reflection via proxy. This implementation only works on interfaces using methods that solely use method parameters and return values that are serializable! Also, the interface methods should not alter object parameters (using call by reference), as these are not sent back!

Since:
21. März 2008, 01:26
Author:
Holger Antelmann

Constructor Summary
RemoteNetInterfaceProtocol(Object serverInstance)
          calls RemoteNetInterfaceProtocol(serverInstance, false, null)
RemoteNetInterfaceProtocol(Object serverInstance, boolean enforceAccessibility, Logger logger)
          constructs the handler that implements the server side of the protocol
 
Method Summary
 void connectionLost(NetConnection con)
          called when a connection caused an IOException during reading or writing; the connection may not have been closed at this point.
static Object createRemoteObject(NetConnection con, Class<?>... interfaces)
           
static Object createRemoteObject(NetConnection con, ClassLoader cl, Class<?>... interfaces)
           
static Object createRemoteObject(NetConnection con, Logger logger, Class<?>... interfaces)
           
static Object createRemoteObject(NetConnection con, Logger logger, ClassLoader cl, Class<?>... interfaces)
          creates and returns a client object that will be handled remotely through the given NetConnection.
static Object createRemoteObject(String host, int port, Class<?>... interfaces)
           
static Object createRemoteObject(String host, int port, Handshake hs, Class<?>... interfaces)
           
static Object createRemoteObject(String host, int port, Handshake hs, Logger logger, Class<?>... interfaces)
           
 Logger getLogger()
           
 void handleMessage(Object message, NetConnection con)
          called when a message is received by the given NetConnection object
static void sendInfoMessage(NetConnection con, Object msg)
          allows to send an arbitrary message (even just a ping) from one end to another
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteNetInterfaceProtocol

public RemoteNetInterfaceProtocol(Object serverInstance)
calls RemoteNetInterfaceProtocol(serverInstance, false, null)


RemoteNetInterfaceProtocol

public RemoteNetInterfaceProtocol(Object serverInstance,
                                  boolean enforceAccessibility,
                                  Logger logger)
constructs the handler that implements the server side of the protocol

Parameters:
serverInstance - the object used to handle the requests; this object must implement the interfaces expected by the client
logger - used to log connection related events
enforceAccessibility - if true, even an implementation of a method that would normally not be accessible, will be made accessible via reflection
Method Detail

createRemoteObject

public static Object createRemoteObject(String host,
                                        int port,
                                        Class<?>... interfaces)
                                 throws IOException
Throws:
IOException

createRemoteObject

public static Object createRemoteObject(String host,
                                        int port,
                                        Handshake hs,
                                        Class<?>... interfaces)
                                 throws IOException
Throws:
IOException

createRemoteObject

public static Object createRemoteObject(String host,
                                        int port,
                                        Handshake hs,
                                        Logger logger,
                                        Class<?>... interfaces)
                                 throws IOException
Throws:
IOException

createRemoteObject

public static Object createRemoteObject(NetConnection con,
                                        Class<?>... interfaces)

createRemoteObject

public static Object createRemoteObject(NetConnection con,
                                        ClassLoader cl,
                                        Class<?>... interfaces)

createRemoteObject

public static Object createRemoteObject(NetConnection con,
                                        Logger logger,
                                        Class<?>... interfaces)

createRemoteObject

public static Object createRemoteObject(NetConnection con,
                                        Logger logger,
                                        ClassLoader cl,
                                        Class<?>... interfaces)
creates and returns a client object that will be handled remotely through the given NetConnection. The returned Object can savely be casted to any of the given interfaces.


sendInfoMessage

public static void sendInfoMessage(NetConnection con,
                                   Object msg)
                            throws IOException
allows to send an arbitrary message (even just a ping) from one end to another

Throws:
IOException

getLogger

public Logger getLogger()

handleMessage

public void handleMessage(Object message,
                          NetConnection con)
                   throws UnexpectedDataException
Description copied from interface: NetConnectionHandler
called when a message is received by the given NetConnection object

Specified by:
handleMessage in interface NetConnectionHandler
Throws:
UnexpectedDataException

connectionLost

public void connectionLost(NetConnection con)
Description copied from interface: NetConnectionHandler
called when a connection caused an IOException during reading or writing; the connection may not have been closed at this point.
Usually, it is a good idea to close the connection here explicitly.

Specified by:
connectionLost in interface NetConnectionHandler


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads