org.clazzes.remoting.client
Class Client

java.lang.Object
  extended by org.clazzes.remoting.client.Client
All Implemented Interfaces:
InvocationContext, RemoteInvoker

public class Client
extends java.lang.Object
implements RemoteInvoker

A remote invocation client, which support callbacks over a single TCP/IP.

Author:
wglas

Constructor Summary
Client(java.net.URI uri)
          Construct a client, which will connect to the given URI.
 
Method Summary
 void connect()
          Connect to the remote resource.
 void deregisterBroadcastHandler(java.lang.String subSystem)
          Deregister a broadcast handler previously added with RemoteInvoker.registerBroadcastHandler(String, OneWayHandler).
 void deregisterCallback(java.rmi.server.UID handlerUID)
          Deregister a callback previously added with RemoteInvoker.registerCallback(InvocationHandler).
 void disconnect()
          Disconnect from the remote resource.
 OneWayHandler getBroadcastHandler(java.lang.String subSystem)
          Get a broadcast handler previously added with RemoteInvoker.registerBroadcastHandler(String, OneWayHandler).
 InvocationHandler getCallback(java.rmi.server.UID handlerUID)
          Get a callback previously added with RemoteInvoker.registerCallback(InvocationHandler).
 ClientParameters getClientParameters()
           
 java.rmi.server.UID getClientUID()
           
 java.util.concurrent.ExecutorService getExecutorService()
           
 java.lang.ClassLoader getMarshalClassLoader()
           
 java.lang.Object invoke(java.lang.String subSystem, java.lang.Object arg, java.util.Map<java.lang.String,java.lang.Object> metadata)
           
 boolean isConnected()
           
 ClassBytes loadClass(java.lang.String className)
          Request a binary class from the server.
 void registerBroadcastHandler(java.lang.String subSystem, OneWayHandler handler)
           
 java.rmi.server.UID registerCallback(InvocationHandler handler)
           
 void setClientParameters(ClientParameters clientParameters)
           
 void setExecutorService(java.util.concurrent.ExecutorService executorService)
           
 void setMarshalClassLoader(java.lang.ClassLoader classLoader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client(java.net.URI uri)
       throws java.io.IOException
Construct a client, which will connect to the given URI. Please note, that any name resolution required will be performed by connect(). The following default parameters will be set:
soTimeout60000
tcpNoDelaytrue

Parameters:
uri - An URI with a supported scheme. Currently, only the tcp and ssl schemes are supported.
Throws:
java.io.IOException - If the URI has an unsupported scheme.
Method Detail

getClientParameters

public ClientParameters getClientParameters()
Returns:
The client configuration object. If not set via setClientParameters(ClientParameters), a new instance of ClientParameters or SSLClientParameters is returned depending on the scheme of the URI passed to the constructor.

setClientParameters

public void setClientParameters(ClientParameters clientParameters)
Parameters:
clientParameters - The client parameters to set.

getMarshalClassLoader

public java.lang.ClassLoader getMarshalClassLoader()
Returns:
The class loader used for resolving deserialized objects. If not set via setMarshalClassLoader(ClassLoader), the context class loader of the current thread is used.

setMarshalClassLoader

public void setMarshalClassLoader(java.lang.ClassLoader classLoader)
Parameters:
classLoader - The custom class loader used for resolving deserialized objects.

getExecutorService

public java.util.concurrent.ExecutorService getExecutorService()
Returns:
The executor service used to execute the asynchronous reader process. If no set via setExecutorService(ExecutorService), the result of Executors.newSingleThreadExecutor() is returned.

setExecutorService

public void setExecutorService(java.util.concurrent.ExecutorService executorService)
Parameters:
executorService - The executor service used to execute the asynchronous reader process.

connect

public void connect()
             throws java.io.IOException
Description copied from interface: RemoteInvoker
Connect to the remote resource.

Specified by:
connect in interface RemoteInvoker
Throws:
java.io.IOException

deregisterCallback

public void deregisterCallback(java.rmi.server.UID handlerUID)
Description copied from interface: RemoteInvoker
Deregister a callback previously added with RemoteInvoker.registerCallback(InvocationHandler).

Specified by:
deregisterCallback in interface RemoteInvoker
Parameters:
handlerUID - The handler UID of the callback to deregister as returned by {RemoteInvoker.registerCallback(InvocationHandler).

getCallback

public InvocationHandler getCallback(java.rmi.server.UID handlerUID)
Description copied from interface: RemoteInvoker
Get a callback previously added with RemoteInvoker.registerCallback(InvocationHandler).

Specified by:
getCallback in interface RemoteInvoker
Parameters:
handlerUID - The handler UID of the callback to get as returned by {RemoteInvoker.registerCallback(InvocationHandler).

disconnect

public void disconnect()
Description copied from interface: RemoteInvoker
Disconnect from the remote resource.

Specified by:
disconnect in interface RemoteInvoker

invoke

public java.lang.Object invoke(java.lang.String subSystem,
                               java.lang.Object arg,
                               java.util.Map<java.lang.String,java.lang.Object> metadata)
                        throws java.lang.reflect.InvocationTargetException,
                               java.io.IOException
Specified by:
invoke in interface RemoteInvoker
Parameters:
subSystem - The subsystem, on which the method is invoked.
arg - The argument passed to the invocation handler.
metadata - The metadata accompanying the remote call, which is passed to the invocation handler. Metadata may be used to communicate authorization information such as user/password or a session Id.
Returns:
The result of the operation.
Throws:
java.lang.reflect.InvocationTargetException - If InvocationHandler.invoke(InvocationContext, Object, Map) on the server threw an exception. The exception of the server may be retrieved by InvocationTargetException.getCause().
java.io.IOException - Upon errors in the transport layer-

loadClass

public ClassBytes loadClass(java.lang.String className)
                     throws java.io.IOException
Description copied from interface: RemoteInvoker
Request a binary class from the server.

Specified by:
loadClass in interface RemoteInvoker
Parameters:
className - The fully qualified name of the class to load.
Returns:
The binary class.
Throws:
java.io.IOException - Upon errors in the transport layer-

isConnected

public boolean isConnected()
Specified by:
isConnected in interface RemoteInvoker
Returns:
Whether this invoker is connected to the remote resource. If the return value is true, the server-generated client UID may be retrieved by InvocationContext.getClientUID().

registerCallback

public java.rmi.server.UID registerCallback(InvocationHandler handler)
Specified by:
registerCallback in interface RemoteInvoker
Parameters:
handler - An invocation handler for the given callback.
Returns:
The unique ID of the registered handler. The ID is unique in the context of the virtual machine of the client, so the server must be aware of the fact, that multiple clients may register callbacks with the same client side UID.

deregisterBroadcastHandler

public void deregisterBroadcastHandler(java.lang.String subSystem)
Description copied from interface: RemoteInvoker
Deregister a broadcast handler previously added with RemoteInvoker.registerBroadcastHandler(String, OneWayHandler).

Specified by:
deregisterBroadcastHandler in interface RemoteInvoker
Parameters:
subSystem - The subsystem for which to deregister a broadcast handler.

registerBroadcastHandler

public void registerBroadcastHandler(java.lang.String subSystem,
                                     OneWayHandler handler)
                              throws java.io.IOException
Specified by:
registerBroadcastHandler in interface RemoteInvoker
Parameters:
subSystem - The subsystem for which to register a broadcast handler.
handler - A one way invocation handler for the given subsystem.
Throws:
java.io.IOException

getBroadcastHandler

public OneWayHandler getBroadcastHandler(java.lang.String subSystem)
Description copied from interface: RemoteInvoker
Get a broadcast handler previously added with RemoteInvoker.registerBroadcastHandler(String, OneWayHandler).

Specified by:
getBroadcastHandler in interface RemoteInvoker
Parameters:
subSystem - The subsystem for which to get a broadcast handler.

getClientUID

public java.rmi.server.UID getClientUID()
Specified by:
getClientUID in interface InvocationContext
Returns:
The server-generated client UID, which is being assigned during the startup handshake inside connect(). Multiple clients connected to the same server are guaranteed to have distinct client UIDs. Return null, if the client is not connected.


Copyright © 2010. All Rights Reserved.