com.lightdev.app.trec.client
Class Client

java.lang.Object
  extended by com.lightdev.app.trec.client.Client

public class Client
extends Object

A class that can be used by arbitrary applications to turn them into a client in the context of the Light Development Transparent Remote Computing (TREC) platform.

A Client encapsulates the communication model of TREC and provides basic functionality for calling remote methods, login/logout and for changes to the own password of a currently logged in user.

Version:
2, 31.12.2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software

Field Summary
static String DEFAULT_AUTHORIZER
          default name of TREC authorizer agent
static String DEFAULT_METHOD_CHG_PW
          default name of change own password method of TREC authorizer agent
static String DEFAULT_METHOD_LOGIN
          default name of login method of TREC authorizer agent
static String DEFAULT_METHOD_LOGOUT
          default name of logout method of TREC authorizer agent
static String DEFAULT_SAM_ADMIN
          default name of TREC SAM administrator agent
static String DEFAULT_SERVER_ADMIN
          default name of TREC server administrator agent
static int STORE_TYPE_EMBEDDED
           
static int STORE_TYPE_ROOT
           
static int STORE_TYPE_SHARED_JDBC
           
static int UDSS_CONNECT_STR
           
static int UDSS_DRIVER
           
static int UDSS_TYPE
           
 
Constructor Summary
Client(ServerAddress sa)
          create a new instance of a Client object
 
Method Summary
 boolean changeOwnPassword(String agentName, String currentPw, String newPw)
          change the password of the user of a given session id
 Object deserialize(byte[] bytes)
          deserialize a given byte array back to an object The JaCS platform uses Apache XML-RPC for all communication between clients and servers.
 Object executeRequest(Request request)
          execute a client reqeust as an XML-RPC remote procedure call
 void executeRequest(Request request, AsyncCallback listener)
          Execute a client request asynchronously as an XML-RPC remote procedure call.
 ServerAddress getServerAddress()
          get the server address this client is created for
 String getUserId()
           
 boolean isLoggedIn()
           
 String login(String agentName, String userId, String pw)
          login using a given authorizer address
 boolean logout(String agentName)
          logout the user with a given session id using the authorizer at a given address
 byte[] serialize(Object obj)
          serialize a given object for transport to a remote agent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AUTHORIZER

public static final String DEFAULT_AUTHORIZER
default name of TREC authorizer agent

See Also:
Constant Field Values

DEFAULT_SERVER_ADMIN

public static final String DEFAULT_SERVER_ADMIN
default name of TREC server administrator agent

See Also:
Constant Field Values

DEFAULT_SAM_ADMIN

public static final String DEFAULT_SAM_ADMIN
default name of TREC SAM administrator agent

See Also:
Constant Field Values

DEFAULT_METHOD_LOGIN

public static final String DEFAULT_METHOD_LOGIN
default name of login method of TREC authorizer agent

See Also:
Constant Field Values

DEFAULT_METHOD_LOGOUT

public static final String DEFAULT_METHOD_LOGOUT
default name of logout method of TREC authorizer agent

See Also:
Constant Field Values

DEFAULT_METHOD_CHG_PW

public static final String DEFAULT_METHOD_CHG_PW
default name of change own password method of TREC authorizer agent

See Also:
Constant Field Values

UDSS_TYPE

public static final int UDSS_TYPE
See Also:
Constant Field Values

UDSS_DRIVER

public static final int UDSS_DRIVER
See Also:
Constant Field Values

UDSS_CONNECT_STR

public static final int UDSS_CONNECT_STR
See Also:
Constant Field Values

STORE_TYPE_ROOT

public static final int STORE_TYPE_ROOT
See Also:
Constant Field Values

STORE_TYPE_EMBEDDED

public static final int STORE_TYPE_EMBEDDED
See Also:
Constant Field Values

STORE_TYPE_SHARED_JDBC

public static final int STORE_TYPE_SHARED_JDBC
See Also:
Constant Field Values
Constructor Detail

Client

public Client(ServerAddress sa)
create a new instance of a Client object

Parameters:
sa - address of the server this client should communicate with
Method Detail

getServerAddress

public ServerAddress getServerAddress()
get the server address this client is created for

Returns:
the server address of this client

executeRequest

public Object executeRequest(Request request)
                      throws Throwable
execute a client reqeust as an XML-RPC remote procedure call

Parameters:
request - request to send
Returns:
the result of the remote procedure call
Throws:
Throwable - could be many errors such as MalformedURLException, AccessException, XmlRpcException partly with nested causes such as SQLException, etc. Caller need to analyze exception for appropriate handling

executeRequest

public void executeRequest(Request request,
                           AsyncCallback listener)
                    throws Throwable

Execute a client request asynchronously as an XML-RPC remote procedure call. This method returns immediately. The caller needs to provide a listener that handles the result.

Parameters:
request - request to send
listener - listener that handles the result once the method returns
Throws:
Throwable - could be many errors such as MalformedURLException, AccessException, XmlRpcException partly with nested causes such as SQLException, etc. Caller need to analyze exception for appropriate handling

login

public String login(String agentName,
                    String userId,
                    String pw)
             throws MalformedURLException,
                    Throwable
login using a given authorizer address

Parameters:
agentName - name of agent to use for login
userId - id of user to login
pw - password of user to login
Returns:
session id for logged in user
Throws:
Throwable
MalformedURLException

logout

public boolean logout(String agentName)
               throws MalformedURLException,
                      Throwable
logout the user with a given session id using the authorizer at a given address

Parameters:
agentName - name of agent to call for logout, normally Client.DEFAULT_AUTHORIZER
Returns:
true, if logout was successful, exception if not
Throws:
Throwable
MalformedURLException

isLoggedIn

public boolean isLoggedIn()

getUserId

public String getUserId()

changeOwnPassword

public boolean changeOwnPassword(String agentName,
                                 String currentPw,
                                 String newPw)
                          throws MalformedURLException,
                                 Throwable
change the password of the user of a given session id

Parameters:
agentName - name of agent to use for pw chg
currentPw - current password of user
newPw - new password of user
Returns:
true, when successful, exception if not
Throws:
Throwable
MalformedURLException

serialize

public byte[] serialize(Object obj)

serialize a given object for transport to a remote agent.

The TREC platform uses Apache XML-RPC for all communication between clients and servers. When a data type is not supported by XML-RPC this method can be used to serialize the object to a byte array using interface java.io.Serializable (the object that is to be serialized needs to implement that interface).

For a listing of types supported by XML-RPC see http://ws.apache.org/xmlrpc/types.html

Subclasses of class Client can override this method to implement another serialization method such as XStream at http://xstream.codehaus.org/

With XStream a serialization/deserialization could look as follows:

   Point p = new Point( 120, 32 );
   XStream xstream = new XStream();
   String xml = xstream.toXML( p );
   System.out.println( xml );
   Point q = (Point) xstream.fromXML( xml );
 

Parameters:
obj - the object to serialize
Returns:
the byte array representing the serialized object

deserialize

public Object deserialize(byte[] bytes)
                   throws IOException,
                          ClassNotFoundException
deserialize a given byte array back to an object

The JaCS platform uses Apache XML-RPC for all communication between clients and servers. When a data type is not supported by XML-RPC this method can be used to deserialize a byte array back to an object using interface java.io.Serializable (the object that is to be deserialized needs to implement that interface).

For a listing of types supported by XML-RPC see http://ws.apache.org/xmlrpc/types.html

Subclasses of class Client can override this method to implement another serialization method such as XStream at http://xstream.codehaus.org/

With XStream a serialization/deserialization could look as follows:

   Point p = new Point( 120, 32 );
   XStream xstream = new XStream();
   String xml = xstream.toXML( p );
   System.out.println( xml );
   Point q = (Point) xstream.fromXML( xml );
 

Parameters:
bytes -
Returns:
the deserialized object
Throws:
IOException
ClassNotFoundException