de.enough.polish.rmi
Class RemoteClient

java.lang.Object
  extended by de.enough.polish.rmi.RemoteClient
Direct Known Subclasses:
L2CapRemoteClient, SppRemoteClient, XmlRpcRemoteClient

public class RemoteClient
extends Object

The remote client is capable of calling any server based method and will decode return values accordingly.

By default the RemoteClient calls methods in an asynchrone way (in a separate thread). If you are calling methods from a thread anyhow, you can disable this behavior by setting the "polish.rmi.synchrone" variable to true:

    <variable name="polish.rmi.synchrone" value="true" />
 

Copyright Enough Software 2006 - 2009

 history
        Dec 20, 2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  String cookie
           
static int RMI_VERSION
          The version of the RMI protocol, currently 102 (=1.0.2) is used (support for dynamic obfuscation)
protected  String url
           
 
Constructor Summary
protected RemoteClient(String url)
          Createsa new client.
 
Method Summary
protected  Object callMethod(String name, long primitivesFlag, Object[] parameters)
          Calls a remote method in the same thread.
static Remote open(String remoteInterfaceName, String url)
          Retrieves a new remote client implementation for the specified remote interface.
protected  Object readResponse(DataInputStream in)
          Reads the RMI response from the given input stream
protected  void writeMethodParameters(String name, long primitivesFlag, Object[] parameters, DataOutputStream out)
          Writes a method request to the specified output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RMI_VERSION

public static final int RMI_VERSION
The version of the RMI protocol, currently 102 (=1.0.2) is used (support for dynamic obfuscation)

See Also:
Constant Field Values

url

protected String url

cookie

protected String cookie
Constructor Detail

RemoteClient

protected RemoteClient(String url)
Createsa new client.

Parameters:
url - the url of the server, e.g. http://myserver.com/myservice
Method Detail

open

public static Remote open(String remoteInterfaceName,
                          String url)
Retrieves a new remote client implementation for the specified remote interface.

Parameters:
remoteInterfaceName - the name of the remote interface;
url - the URL of the server, e.g. http://myserver.com/myservice
Returns:
the stub which is capable of connecting to the server

callMethod

protected Object callMethod(String name,
                            long primitivesFlag,
                            Object[] parameters)
                     throws RemoteException
Calls a remote method in the same thread. Note that this method must not be called manually when polish.rmi.synchrone is set to true.

Parameters:
name - the method name
primitivesFlag - for each element of the parameters which is originally a primitive the bit will be one: element n = primitive means that (primitiveFlags & 2^n) != 0
parameters - any parameters, can be null
Returns:
a return value for methods; void methods return null
Throws:
RemoteException - when a checked or an unchecked exception has occurred on the server side or the connection failed

readResponse

protected Object readResponse(DataInputStream in)
                       throws IOException,
                              RemoteException
Reads the RMI response from the given input stream

Parameters:
in - the input
Returns:
the read response data, or throws an exception
Throws:
IOException - when reading fails
RemoteException - when a remote exception occurred

writeMethodParameters

protected void writeMethodParameters(String name,
                                     long primitivesFlag,
                                     Object[] parameters,
                                     DataOutputStream out)
                              throws IOException
Writes a method request to the specified output stream

Parameters:
name - the name of the method
primitivesFlag - flag that indicates which parameters are primitive
parameters - the parameters
out - the output stream
Throws:
IOException - when writing fails