com.sibvisions.rad.remote
Class AbstractSerializedConnection

java.lang.Object
  extended by com.sibvisions.rad.remote.AbstractSerializedConnection
All Implemented Interfaces:
IConnection
Direct Known Subclasses:
HttpConnection

public abstract class AbstractSerializedConnection
extends Object
implements IConnection

This is the default IConnection implementation. It's independent of the communication protocol.


Field Summary
static String PROP_SERIALIZER
          the property name for the serializer.
 
Fields inherited from interface javax.rad.remote.IConnection
COMPRESSION_BYTES, FLAG_ACKNOWLEDGE, FLAG_BROKEN, FLAG_ESTABLISHED, MET_SESSION_CREATE, MET_SESSION_DESTROY, MET_SESSION_GET_PROPERTIES, MET_SESSION_GET_PROPERTY, MET_SESSION_SET_NEW_PASSWORD, MET_SESSION_SET_PROPERTY, MET_SESSION_SETCHECKALIVE, MET_SESSION_SUBSESSION_CREATE, MODE_COMPRESSED, MODE_UNCOMPRESSED, OBJ_SESSION, TYPE_CALL_ERROR, TYPE_CALL_RESULT, TYPE_CALLBACK_ERROR, TYPE_CALLBACK_RESULT, TYPE_PROPERTY_RESULT
 
Constructor Summary
AbstractSerializedConnection(ISerializer pSerializer)
          Creates a new instance of AbstractSerializedConnection.
AbstractSerializedConnection(Properties pProperties)
          Creates a new instance of AbstractSerializedConnection with properties containing relevant information.
 
Method Summary
 Object[] call(ConnectionInfo pConnectionInfo, String[] pObjectName, String[] pMethod, Object[][] pParams, ICallBackListener[] pCallBack)
          Calls desired methods from a remote server object.
 void close(ConnectionInfo pConnectionInfo)
          Close the connection to the server.
protected static ISerializer createSerializer(String pClassName)
          Creates the serializer from a given class name.
protected  void finalize()
          
abstract  InputStream getInputStream(ConnectionInfo pConnectionInfo)
          Gets the InputStream for reading the response from the server.
abstract  OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
          Gets the OutputStream for submitting requests to the server.
 Hashtable<String,Object> getProperties(ConnectionInfo pConnectionInfo)
          Gets a clone of all connection properties.
 Object getProperty(ConnectionInfo pConnectionInfo, String pName)
          Gets a connection property.
 boolean isCalling()
          Gets whether a call is active.
 boolean isOpen(ConnectionInfo pConnectionInfo)
          Checks if the connection to the server is opened.
 void open(ConnectionInfo pConnectionInfo)
          Opens the connection to the server.
 void openSub(ConnectionInfo pConnectionInfo, ConnectionInfo pConnectionInfoSub)
          Opens a new sub connection.
 void reopen(ConnectionInfo pConnectionInfo)
          Closes and opens the connection to the server.
 ConnectionInfo[] setAndCheckAlive(ConnectionInfo pConnectionInfo, ConnectionInfo[] pSubConnections)
          Sets the alive state for a connection, on the server, and validates the alive state of subconnections.
 void setNewPassword(ConnectionInfo pConnectionInfo, String pOldPassword, String pNewPassword)
          Sets a new password for the connected user.
 void setProperty(ConnectionInfo pConnectionInfo, String pName, Object pValue)
          Sets a connection property.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SERIALIZER

public static final String PROP_SERIALIZER
the property name for the serializer.

See Also:
Constant Field Values
Constructor Detail

AbstractSerializedConnection

public AbstractSerializedConnection(Properties pProperties)
                             throws ClassNotFoundException
Creates a new instance of AbstractSerializedConnection with properties containing relevant information. The supported property keys are:

Parameters:
pProperties - the properties for the connection
Throws:
ClassNotFoundException - if the serializer is defined and could not be created

AbstractSerializedConnection

public AbstractSerializedConnection(ISerializer pSerializer)
Creates a new instance of AbstractSerializedConnection.

Parameters:
pSerializer - the serializer for the communication between client and server or null to use the default serializer
See Also:
ISerializer, ByteSerializer
Method Detail

open

public void open(ConnectionInfo pConnectionInfo)
          throws Throwable
Opens the connection to the server. The credentials have to be a key/value mapping in the connection information.

Specified by:
open in interface IConnection
Parameters:
pConnectionInfo - the connection information
Throws:
Throwable - if the connection can not be established

openSub

public void openSub(ConnectionInfo pConnectionInfo,
                    ConnectionInfo pConnectionInfoSub)
             throws Throwable
Opens a new sub connection. The name of the sub connection has to be a key/value mapping in the sub connection information.

Specified by:
openSub in interface IConnection
Parameters:
pConnectionInfo - the connection information of the master connection
pConnectionInfoSub - the connection information of the sub connection
Throws:
Throwable - communication error, security checks, invalid method, ...

isOpen

public boolean isOpen(ConnectionInfo pConnectionInfo)
Checks if the connection to the server is opened.

Specified by:
isOpen in interface IConnection
Parameters:
pConnectionInfo - the connection information
Returns:
true if the connection is open

close

public void close(ConnectionInfo pConnectionInfo)
           throws Throwable
Close the connection to the server.

Specified by:
close in interface IConnection
Parameters:
pConnectionInfo - the connection information
Throws:
Throwable - if the connection can not be established

reopen

public void reopen(ConnectionInfo pConnectionInfo)
            throws Throwable
Closes and opens the connection to the server. This might be useful if the connection was timed out.

Specified by:
reopen in interface IConnection
Parameters:
pConnectionInfo - the connection information
Throws:
Throwable - if the connection can not be established

call

public Object[] call(ConnectionInfo pConnectionInfo,
                     String[] pObjectName,
                     String[] pMethod,
                     Object[][] pParams,
                     ICallBackListener[] pCallBack)
              throws Throwable
Calls desired methods from a remote server object.

Specified by:
call in interface IConnection
Parameters:
pConnectionInfo - the connection information
pObjectName - list of server object names/aliases
pMethod - method names which should be called
pParams - parameters for the method calls
pCallBack - callback listeners for asynchronous or null for synchronous calls
Returns:
result list from the remote method calls
Throws:
Throwable - communication error, security checks, invalid method, ...

setAndCheckAlive

public ConnectionInfo[] setAndCheckAlive(ConnectionInfo pConnectionInfo,
                                         ConnectionInfo[] pSubConnections)
                                  throws Throwable
Sets the alive state for a connection, on the server, and validates the alive state of subconnections.

Specified by:
setAndCheckAlive in interface IConnection
Parameters:
pConnectionInfo - the connection information
pSubConnections - the connection information of the sub connections, for the alive validation
Returns:
the invalid/expired sub connections
Throws:
Throwable - communication error, security checks, invalid method, ...

setProperty

public void setProperty(ConnectionInfo pConnectionInfo,
                        String pName,
                        Object pValue)
                 throws Throwable
Sets a connection property.

Specified by:
setProperty in interface IConnection
Parameters:
pConnectionInfo - the connection information
pName - the property name
pValue - the value of the property or null to delete the property
Throws:
Throwable - communication error, security checks, invalid method, ...
SecurityException - if it's not allowed to set the property

getProperty

public Object getProperty(ConnectionInfo pConnectionInfo,
                          String pName)
                   throws Throwable
Gets a connection property.

Specified by:
getProperty in interface IConnection
Parameters:
pConnectionInfo - the connection information
pName - the property name
Returns:
the value of the property or null if the property is not set
Throws:
Throwable - communication error, security checks, invalid method, ...

getProperties

public Hashtable<String,Object> getProperties(ConnectionInfo pConnectionInfo)
                                       throws Throwable
Gets a clone of all connection properties.

Specified by:
getProperties in interface IConnection
Parameters:
pConnectionInfo - the connection information
Returns:
a Hashtable with property names and values
Throws:
Throwable - communication error, security checks, invalid method, ...

setNewPassword

public void setNewPassword(ConnectionInfo pConnectionInfo,
                           String pOldPassword,
                           String pNewPassword)
                    throws Throwable
Sets a new password for the connected user.

Specified by:
setNewPassword in interface IConnection
Parameters:
pConnectionInfo - the connection information
pOldPassword - the old password
pNewPassword - the new password
Throws:
Throwable - communication error, security checks, invalid method, ...

getOutputStream

public abstract OutputStream getOutputStream(ConnectionInfo pConnectionInfo)
                                      throws Throwable
Gets the OutputStream for submitting requests to the server.

Parameters:
pConnectionInfo - the connection information
Returns:
output stream
Throws:
Throwable - if it's not possible to get the output stream

getInputStream

public abstract InputStream getInputStream(ConnectionInfo pConnectionInfo)
                                    throws Throwable
Gets the InputStream for reading the response from the server.

Parameters:
pConnectionInfo - the connection information
Returns:
input stream
Throws:
Throwable - if it's not possible to get the the input stream

finalize

protected void finalize()
                 throws Throwable

Overrides:
finalize in class Object
Throws:
Throwable

createSerializer

protected static ISerializer createSerializer(String pClassName)
                                       throws ClassNotFoundException
Creates the serializer from a given class name.

Parameters:
pClassName - the ISerializer implementation class
Returns:
the serializer implementation
Throws:
ClassNotFoundException - if the serializer could not be created

isCalling

public boolean isCalling()
Gets whether a call is active.

Specified by:
isCalling in interface IConnection
Returns:
true if a call is active, false otherwise


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.