org.jboss.remoting
Class Client

java.lang.Object
  extended byorg.jboss.remoting.Client

public class Client
extends java.lang.Object

Client is a convience method for invoking remote methods for a given subsystem

Version:
$Revision: 1.14 $
Author:
Jeff Haynie, Tom Elrod

Field Summary
static java.lang.String LISTENER_ID_KEY
           
static int MAX_NUM_ONEWAY_THREADS
          Specifies the default number of work threads in the pool for executing one way invocations on the client.
static java.lang.String RAW
           
 
Constructor Summary
Client(java.lang.ClassLoader cl, ClientInvoker invoker, java.lang.String subsystem)
           
Client(java.lang.ClassLoader cl, InvokerLocator locator, java.lang.String subsystem)
           
Client(InvokerLocator locator)
           
Client(InvokerLocator locator, java.lang.String subsystem)
           
 
Method Summary
 void addConnectionListener(ConnectionListener listener)
          Adds a connection listener that will be notified if/when the connection to the server fails while the client is idle (no calls being made).
 void addListener(InvokerCallbackHandler callbackHandler)
          Adds the specified handler as a callback listener for pull (sync) callbacks.
 void addListener(InvokerCallbackHandler callbackHandler, InvokerLocator clientLocator)
          Adds the specified handler as a callback listener for push (async) callbacks.
 void addListener(InvokerCallbackHandler callbackHandler, InvokerLocator clientLocator, java.lang.Object callbackHandlerObject)
          Adds the specified handler as a callback listener for push (async) callbacks.
 void connect()
           
 void disconnect()
           
 java.util.List getCallbacks(InvokerCallbackHandler callbackHandler)
          Gets the callbacks for specified callback handler.
 ClientInvoker getInvoker()
           
 int getMaxNumberOfThreads()
           
 org.jboss.util.threadpool.ThreadPool getOnewayThreadPool()
           
 java.lang.String getSessionId()
           
 java.lang.String getSubsystem()
           
 java.lang.Object invoke(java.io.InputStream inputStream, java.lang.Object param)
          Takes an inputstream and wraps a server around.
 java.lang.Object invoke(java.lang.Object param)
          Invokes the server invoker handler with the payload parameter passed.
 java.lang.Object invoke(java.lang.Object param, java.util.Map metadata)
          invoke the method remotely
 void invokeOneway(java.lang.Object param, java.util.Map sendPayload)
          Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with clientSide param being false.
 void invokeOneway(java.lang.Object param, java.util.Map sendPayload, boolean clientSide)
          Will invoke a oneway call to server without a return object.
 boolean isConnected()
           
 boolean removeConnectionListener(ConnectionListener listener)
          Removes specified connection listener.
 void removeListener(InvokerCallbackHandler callbackHandler)
          Removes callback handler as a callback listener from the server (and client in the case that it was setup to receive async callbacks).
 void setInvoker(ClientInvoker invoker)
           
 void setMarshaller(Marshaller marshaller)
           
 void setMaxNumberOfThreads(int numOfThreads)
           
 void setOnewayThreadPool(org.jboss.util.threadpool.ThreadPool pool)
           
 void setSessionId(java.lang.String sessionId)
          This will set the session id used when making invocations on server invokers.
 void setSubsystem(java.lang.String subsystem)
           
 void setUnMarshaller(UnMarshaller unmarshaller)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LISTENER_ID_KEY

public static final java.lang.String LISTENER_ID_KEY
See Also:
Constant Field Values

MAX_NUM_ONEWAY_THREADS

public static final int MAX_NUM_ONEWAY_THREADS
Specifies the default number of work threads in the pool for executing one way invocations on the client. Value is 10.

See Also:
Constant Field Values

RAW

public static final java.lang.String RAW
See Also:
Constant Field Values
Constructor Detail

Client

public Client(InvokerLocator locator)
       throws java.lang.Exception

Client

public Client(InvokerLocator locator,
              java.lang.String subsystem)
       throws java.lang.Exception

Client

public Client(java.lang.ClassLoader cl,
              InvokerLocator locator,
              java.lang.String subsystem)
       throws java.lang.Exception

Client

public Client(java.lang.ClassLoader cl,
              ClientInvoker invoker,
              java.lang.String subsystem)
       throws java.lang.Exception
Method Detail

addConnectionListener

public void addConnectionListener(ConnectionListener listener)
Adds a connection listener that will be notified if/when the connection to the server fails while the client is idle (no calls being made).

Parameters:
listener -

removeConnectionListener

public boolean removeConnectionListener(ConnectionListener listener)
Removes specified connection listener. Will return true if it has already been registered, false otherwise.

Parameters:
listener -
Returns:

setSessionId

public void setSessionId(java.lang.String sessionId)
This will set the session id used when making invocations on server invokers. There is a default unique id automatically generated for each Client instance, so unless you have a good reason to set this, do not set this.

Parameters:
sessionId -

getSessionId

public java.lang.String getSessionId()

isConnected

public boolean isConnected()

connect

public void connect()
             throws java.lang.Exception
Throws:
java.lang.Exception

disconnect

public void disconnect()

getInvoker

public ClientInvoker getInvoker()

setInvoker

public void setInvoker(ClientInvoker invoker)

getSubsystem

public java.lang.String getSubsystem()

setSubsystem

public void setSubsystem(java.lang.String subsystem)

invoke

public java.lang.Object invoke(java.lang.Object param)
                        throws java.lang.Throwable
Invokes the server invoker handler with the payload parameter passed.

Parameters:
param -
Returns:
Throws:
java.lang.Throwable

invoke

public java.lang.Object invoke(java.lang.Object param,
                               java.util.Map metadata)
                        throws java.lang.Throwable
invoke the method remotely

Parameters:
param - - payload for the server invoker handler
metadata - - any extra metadata that may be needed by the transport (i.e. GET or POST if using http invoker) or if need to pass along extra data to the server invoker handler.
Returns:
Throws:
java.lang.Throwable

invokeOneway

public void invokeOneway(java.lang.Object param,
                         java.util.Map sendPayload,
                         boolean clientSide)
                  throws java.lang.Throwable
Will invoke a oneway call to server without a return object. This should be used when not expecting a return value from the server and wish to achieve higher performance, since the client will not wait for a return. This is done one of two ways. The first is to pass true as the clientSide param. This will cause the execution of the remote call to be excuted in a new thread on the client side and will return the calling thread before making call to server side. Although, this is optimal for performance, will not know about any problems contacting server.

The second, is to pass false as the clientSide param. This will allow the current calling thread to make the call to the remote server, at which point, the server side processing of the thread will be executed on the remote server in a new executing thread and the client thread will return. This is a little slower, but will know that the call made it to the server.

Parameters:
param -
sendPayload -
clientSide -
Throws:
java.lang.Throwable

setMaxNumberOfThreads

public void setMaxNumberOfThreads(int numOfThreads)

getMaxNumberOfThreads

public int getMaxNumberOfThreads()

getOnewayThreadPool

public org.jboss.util.threadpool.ThreadPool getOnewayThreadPool()

setOnewayThreadPool

public void setOnewayThreadPool(org.jboss.util.threadpool.ThreadPool pool)

invokeOneway

public void invokeOneway(java.lang.Object param,
                         java.util.Map sendPayload)
                  throws java.lang.Throwable
Same as calling invokeOneway(Object param, Map sendPayload, boolean clientSide) with clientSide param being false. Therefore, client thread will not return till it has made remote call.

Parameters:
param -
sendPayload -
Throws:
java.lang.Throwable

addListener

public void addListener(InvokerCallbackHandler callbackHandler)
                 throws java.lang.Throwable
Adds the specified handler as a callback listener for pull (sync) callbacks. The invoker server will then collect the callbacks for this specific handler. The callbacks can be retrieved by calling the getCallbacks() method. Note: this will cause the client invoker's client locator to be set to null.

Parameters:
callbackHandler -
Throws:
java.lang.Throwable

addListener

public void addListener(InvokerCallbackHandler callbackHandler,
                        InvokerLocator clientLocator)
                 throws java.lang.Throwable
Adds the specified handler as a callback listener for push (async) callbacks. The invoker server will then callback on this handler (via the server invoker specified by the clientLocator) when it gets a callback from the server handler. Note: passing a null clientLocator will cause the client invoker's client locator to be set to null.

Parameters:
callbackHandler -
clientLocator -
Throws:
java.lang.Throwable

addListener

public void addListener(InvokerCallbackHandler callbackHandler,
                        InvokerLocator clientLocator,
                        java.lang.Object callbackHandlerObject)
                 throws java.lang.Throwable
Adds the specified handler as a callback listener for push (async) callbacks. The invoker server will then callback on this handler (via the server invoker specified by the clientLocator) when it gets a callback from the server handler. Note: passing a null clientLocator will cause the client invoker's client locator to be set to null.

Parameters:
callbackHandler - interface to call on with callback
clientLocator - locator for callback server to callback on
callbackHandlerObject - will be included in the callback object passed upon callback
Throws:
java.lang.Throwable

removeListener

public void removeListener(InvokerCallbackHandler callbackHandler)
                    throws java.lang.Throwable
Removes callback handler as a callback listener from the server (and client in the case that it was setup to receive async callbacks). See addListener().

Parameters:
callbackHandler -
Throws:
java.lang.Throwable

getCallbacks

public java.util.List getCallbacks(InvokerCallbackHandler callbackHandler)
                            throws java.lang.Throwable
Gets the callbacks for specified callback handler. The handler is required because an id is generated for each handler. So if have two callback handlers registered with the same server, no other way to know for which handler to get the callbacks for.

Parameters:
callbackHandler -
Returns:
Throws:
java.lang.Throwable

setMarshaller

public void setMarshaller(Marshaller marshaller)

setUnMarshaller

public void setUnMarshaller(UnMarshaller unmarshaller)

invoke

public java.lang.Object invoke(java.io.InputStream inputStream,
                               java.lang.Object param)
                        throws java.lang.Throwable
Takes an inputstream and wraps a server around. Then calls the target remoting server and passes a proxy for an inputstream to the server's handler. When the server handler calls on this proxy, it will call back on this server wrapped around this inputstream.

Parameters:
inputStream -
param - invocation payload
Returns:
the return value from the invocation
Throws:
java.lang.Throwable


Copyright © 1998-2005 JBoss Inc . All Rights Reserved.