javax.rad.remote
Class AbstractConnection

java.lang.Object
  extended by javax.rad.remote.AbstractConnection
All Implemented Interfaces:
ICloseable
Direct Known Subclasses:
MasterConnection, SubConnection

public abstract class AbstractConnection
extends Object
implements ICloseable

The AbstractConnection encapsulates the access to an IConnection implementation.
It implements the connection listener handling and an implementation of ConnectionInfo.

See Also:
IConnection

Field Summary
protected  ConnectionInfo coninf
          the connection information.
protected  IConnection connection
          the connection implementation.
 
Constructor Summary
protected AbstractConnection(IConnection pConnection)
          Creates a new instance of AppliationConnection with an IConnection implementation.
 
Method Summary
 void addConnectionListener(IConnectionListener pListener)
          Adds an IConnectionListener to the list of registered listeners.
 void call(ICallBackListener[] pCallBack, String[] pObjectName, String[] pMethod, Object[][] pParams)
          Calls desired methods of server objects, through the connection.
 void call(ICallBackListener pCallBack, String pObjectName, String pMethod)
          The method will call a remote method from a remote object.
 void call(ICallBackListener pCallBack, String pObjectName, String pMethod, Object... pParams)
          The method will call a remote method from a remote object.
 Object[] call(String[] pObjectName, String[] pMethod)
          Calls desired methods of server objects, through the connection.
 Object[] call(String[] pObjectName, String[] pMethod, Object[][] pParams)
          Calls desired methods of server objects, through the connection.
 Object call(String pObjectName, String pMethod)
          The method will call a remote method from a remote object.
 Object call(String pObjectName, String pMethod, Object... pParams)
          The method will call a remote method from a remote object.
 void callAction(ICallBackListener[] pCallBack, String[] pAction, Object[][] pParams)
          The method will call one or more remote actions.
 void callAction(ICallBackListener pCallBack, String pAction)
          The method will call a remote action.
 void callAction(ICallBackListener pCallBack, String pAction, Object... pParams)
          The method will call a remote action.
 Object callAction(String pAction)
          The method will call a remote action.
 Object[] callAction(String[] pAction)
          The method will call one or more remote actions.
 Object[] callAction(String[] pAction, Object[][] pParams)
          The method will call one or more remote actions.
 Object callAction(String pAction, Object... pParams)
          The method will call a remote action.
 void close()
          Close the connection.
protected  void close(boolean pDoCall)
          Close the connection, with or without remote call.
protected  ChangedHashtable<String,Object> createConnectionProperties()
          Gets the properties which will be sent to the server when opening a new connection.
protected  void finalize()
          
protected  void fireCall(boolean pCallBack, String pObjectName, String pMethodName, Object... pParams)
          Fires the objectCalled methods to all registered connection listeners.
protected  void fireCallAction(boolean pCallBack, String pAction, Object... pParams)
          Fires the actionCalled methods to all registered connection listeners.
protected  void fireCallError(Throwable pError)
          Fires the callError methods to all registered connection listeners.
protected  void fireClose()
          Fires the connectionClosed methods to all registered connection listeners.
protected  void fireOpen()
          Fires the connectionOpened methods to all registered connection listeners.
protected  void fireReOpen()
          Fires the connectionReOpened methods to all registered connection listeners.
 String getApplicationName()
          Gets the application name which will be used from the remote server to authenticate the connection.
 IConnection getConnection()
          Returns the connection to the server.
 Object getConnectionId()
          Gets the connection identifier for this connection.
 IConnectionListener[] getConnectionListener()
          Gets all registered IConnectionListeners.
 String getLifeCycleName()
          Gets the name of the server-side life-cycle object.
 String getPassword()
          Gets the password which will be used from the remote server to authenticate the connection.
 Hashtable<String,Object> getProperties()
          Gets a copy of the current properties.
 Object getProperty(String pName)
          Gets a connection property.
 int getTimeout()
          Gets the timeout of the connection.
protected abstract  UIInvoker getUIInvoker()
          Gets the UI invoker.
 String getUserName()
          Gets the user name which will be used from the remote server to authenticate the connection.
protected  Throwable handleCallError(Throwable pError)
          Handles a call error.
 boolean isOpen()
          Checks if the connection is open.
static boolean isTimeoutEnabled()
          Gets whether the timeout should be used.
protected  void logCommunication(long pStart, String pTitle, Throwable pError, Object... pInfo)
          Loggs communication duration.
 void open()
          Opens the connection.
protected abstract  void openConnection()
          Opens the connection without event handling.
 void removeConnectionListener(IConnectionListener pListener)
          Removes an IConnectionListener from the list of registered listeners.
 void reopen()
          Reopens the connection.
 void setApplicationName(String pApplicationName)
          Sets the application name which will be used from the remote server to authenticate the connection, when the connection is not open.
protected  Throwable setConnection(Throwable pError)
          Sets the connection property for all CommunicationException in the hierarchy of the given error.
 void setLifeCycleName(String pName)
          Sets the name of the server-side life-cycle object.
 void setPassword(String pPassword)
          Sets the password which will be used from the remote server to authenticate the connection, when the connection is not open.
 void setProperty(String pName, Object pValue)
          Sets a connection property.
 void setTimeout(int pMinutes)
          Sets the timeout of the connection.
static void setTimeoutEnabled(boolean pEnabled)
          Sets whether timeout should be used.
 void setUserName(String pUserName)
          Sets the user name which will be used from the remote server to authenticate the connection, when the connection is not open.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected IConnection connection
the connection implementation.


coninf

protected ConnectionInfo coninf
the connection information.

Constructor Detail

AbstractConnection

protected AbstractConnection(IConnection pConnection)
Creates a new instance of AppliationConnection with an IConnection implementation.

Parameters:
pConnection - the IConnection implementation
Method Detail

openConnection

protected abstract void openConnection()
                                throws Throwable
Opens the connection without event handling.

Throws:
Throwable - if the connection can not be or is already opened

getUIInvoker

protected abstract UIInvoker getUIInvoker()
Gets the UI invoker.

Returns:
the UI invoker
See Also:
UIInvoker

finalize

protected void finalize()
                 throws Throwable

Overrides:
finalize in class Object
Throws:
Throwable

setLifeCycleName

public void setLifeCycleName(String pName)
Sets the name of the server-side life-cycle object.

Parameters:
pName - the name of the life-cycle object

getLifeCycleName

public String getLifeCycleName()
Gets the name of the server-side life-cycle object.

Returns:
the name of the life-cycle object

setApplicationName

public void setApplicationName(String pApplicationName)
Sets the application name which will be used from the remote server to authenticate the connection, when the connection is not open.

Parameters:
pApplicationName - the application name

getApplicationName

public String getApplicationName()
Gets the application name which will be used from the remote server to authenticate the connection.

Returns:
the application name

setUserName

public void setUserName(String pUserName)
Sets the user name which will be used from the remote server to authenticate the connection, when the connection is not open.

Parameters:
pUserName - the user name

getUserName

public String getUserName()
Gets the user name which will be used from the remote server to authenticate the connection.

Returns:
the user name

setPassword

public void setPassword(String pPassword)
Sets the password which will be used from the remote server to authenticate the connection, when the connection is not open.

Parameters:
pPassword - the password

getPassword

public String getPassword()
Gets the password which will be used from the remote server to authenticate the connection.

Returns:
the password

open

public void open()
          throws Throwable
Opens the connection.

Throws:
Throwable - if the connection can not be or is already opened

isOpen

public boolean isOpen()
Checks if the connection is open.

Returns:
true if the connection is open, otherwise false

close

public void close()
           throws Throwable
Close the connection.

Specified by:
close in interface ICloseable
Throws:
Throwable - if it is not possible to close the connection

close

protected void close(boolean pDoCall)
              throws Throwable
Close the connection, with or without remote call.

Parameters:
pDoCall - true to send close to the server, false to close internal without remote communication (client-side close)
Throws:
Throwable - if it is not possible to close the connection

reopen

public void reopen()
            throws Throwable
Reopens the connection.

Throws:
Throwable - if an error occurs while opening the connection

getConnection

public IConnection getConnection()
Returns the connection to the server.

Returns:
the connection

getConnectionId

public Object getConnectionId()
Gets the connection identifier for this connection.

Returns:
the connection identifier

call

public void call(ICallBackListener[] pCallBack,
                 String[] pObjectName,
                 String[] pMethod,
                 Object[][] pParams)
          throws Throwable
Calls desired methods of server objects, through the connection.

Parameters:
pCallBack - callback listeners for asynchronous or null for synchronous calls
pObjectName - list of already mapped server object names/aliases
pMethod - method names which should be called
pParams - parameters for the method calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

call

public void call(ICallBackListener pCallBack,
                 String pObjectName,
                 String pMethod,
                 Object... pParams)
          throws Throwable
The method will call a remote method from a remote object.

Parameters:
pCallBack - callback listener for asynchronous or null for synchronous call
pObjectName - an already mapped server object name/alias
pMethod - method name which should be called
pParams - parameters for the method call
Throws:
Throwable - communication error, security checks, invalid method, ...

call

public void call(ICallBackListener pCallBack,
                 String pObjectName,
                 String pMethod)
          throws Throwable
The method will call a remote method from a remote object.

Parameters:
pCallBack - callback listener for asynchronous or null for synchronous call
pObjectName - an already mapped server object name/alias
pMethod - method name which should be called
Throws:
Throwable - communication error, security checks, invalid method, ...

call

public Object[] call(String[] pObjectName,
                     String[] pMethod,
                     Object[][] pParams)
              throws Throwable
Calls desired methods of server objects, through the connection. This call will be synchronous.

Parameters:
pObjectName - list of already mapped server object names/aliases
pMethod - method names which should be called
pParams - parameters for the method calls
Returns:
result list from the remote method calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

call

public Object[] call(String[] pObjectName,
                     String[] pMethod)
              throws Throwable
Calls desired methods of server objects, through the connection. This call will be synchronous.

Parameters:
pObjectName - list of already mapped server object names/aliases
pMethod - method names which should be called
Returns:
result list from the remote method calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

call

public Object call(String pObjectName,
                   String pMethod,
                   Object... pParams)
            throws Throwable
The method will call a remote method from a remote object. The call will be synchronous.

Parameters:
pObjectName - an already mapped server object name/alias
pMethod - method name which should be called
pParams - parameters for the method call
Returns:
result from the remote method call
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

call

public Object call(String pObjectName,
                   String pMethod)
            throws Throwable
The method will call a remote method from a remote object. The call will be synchronous.

Parameters:
pObjectName - an already mapped server object name/alias
pMethod - method name which should be called
Returns:
result from the remote method call
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public Object callAction(String pAction)
                  throws Throwable
The method will call a remote action. The call will be synchronous.

Parameters:
pAction - action which should be called
Returns:
result from the remote action call
Throws:
Throwable - communication error, security checks, invalid action, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public Object callAction(String pAction,
                         Object... pParams)
                  throws Throwable
The method will call a remote action. The call will be synchronous.

Parameters:
pAction - action which should be called
pParams - parameters for the action call
Returns:
result from the remote action call
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public Object[] callAction(String[] pAction,
                           Object[][] pParams)
                    throws Throwable
The method will call one or more remote actions. The call will be synchronous.

Parameters:
pAction - list of actions which should be called
pParams - parameters for the action calls
Returns:
result list from the remote action calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public Object[] callAction(String[] pAction)
                    throws Throwable
The method will call one or more remote actions. The call will be synchronous.

Parameters:
pAction - list of actions which should be called
Returns:
result list from the remote action calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public void callAction(ICallBackListener pCallBack,
                       String pAction)
                throws Throwable
The method will call a remote action.

Parameters:
pCallBack - callback listener for asynchronous or null for synchronous call
pAction - action which should be called
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public void callAction(ICallBackListener pCallBack,
                       String pAction,
                       Object... pParams)
                throws Throwable
The method will call a remote action.

Parameters:
pCallBack - callback listener for asynchronous or null for synchronous call
pAction - action which should be called
pParams - parameters for the action call
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

callAction

public void callAction(ICallBackListener[] pCallBack,
                       String[] pAction,
                       Object[][] pParams)
                throws Throwable
The method will call one or more remote actions.

Parameters:
pCallBack - callback listeners for asynchronous or null for synchronous calls
pAction - list of actions which should be called
pParams - parameters for the action calls
Throws:
Throwable - communication error, security checks, invalid method, ...
See Also:
IConnection.call(ConnectionInfo, String[], String[], Object[][], ICallBackListener[])

setProperty

public void setProperty(String pName,
                        Object pValue)
                 throws Throwable
Sets a connection property. It's not allowed to set/change client properties.

Parameters:
pName - the property name
pValue - the value of the property or null to delete the property
Throws:
Throwable - communication error, security checks, invalid method, ...

getProperty

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

Parameters:
pName - the property name
Returns:
the value of the property or null if the property is not available
Throws:
Throwable - communication error, security checks, invalid method, ...

getProperties

public Hashtable<String,Object> getProperties()
                                       throws Throwable
Gets a copy of the current properties.

Returns:
the known properties and its values
Throws:
Throwable - communication error, security checks, invalid method, ...

setTimeout

public void setTimeout(int pMinutes)
                throws Throwable
Sets the timeout of the connection.

Parameters:
pMinutes - the timeout in minutes
Throws:
Throwable - communication error, security checks, invalid method, ...

getTimeout

public int getTimeout()
               throws Throwable
Gets the timeout of the connection.

Returns:
the timeout in minutes (-2 if timeout is unknown or not explicitely set)
Throws:
Throwable - communication error, security checks, invalid method, ...

setTimeoutEnabled

public static void setTimeoutEnabled(boolean pEnabled)
Sets whether timeout should be used. If the timeout was disable and will be enabled, the timeout won't be set automatically. It will be used after close/open the connection.

Parameters:
pEnabled - true to enable the alive check, false to disable the check

isTimeoutEnabled

public static boolean isTimeoutEnabled()
Gets whether the timeout should be used.

Returns:
true if the timeout is enabled, false if it's disabled
See Also:
setTimeoutEnabled(boolean)

createConnectionProperties

protected ChangedHashtable<String,Object> createConnectionProperties()
Gets the properties which will be sent to the server when opening a new connection.

Returns:
the properties as list with key/value pairs

addConnectionListener

public void addConnectionListener(IConnectionListener pListener)
Adds an IConnectionListener to the list of registered listeners.

Parameters:
pListener - the new connection listener

removeConnectionListener

public void removeConnectionListener(IConnectionListener pListener)
Removes an IConnectionListener from the list of registered listeners.

Parameters:
pListener - the new connection listener

getConnectionListener

public IConnectionListener[] getConnectionListener()
Gets all registered IConnectionListeners.

Returns:
an array with IConnectionListeners or null if no listener is registered

fireCallError

protected void fireCallError(Throwable pError)
Fires the callError methods to all registered connection listeners.

Parameters:
pError - the occured error

handleCallError

protected Throwable handleCallError(Throwable pError)
Handles a call error. This methods sets the connection for every CommunicationException and notifies connection listeners via fireCallError(Throwable).

Parameters:
pError - the occured error
Returns:
the changed pError
See Also:
setConnection(Throwable), fireCallError(Throwable)

setConnection

protected Throwable setConnection(Throwable pError)
Sets the connection property for all CommunicationException in the hierarchy of the given error.

Parameters:
pError - the occured error
Returns:
the changed pError

fireOpen

protected void fireOpen()
Fires the connectionOpened methods to all registered connection listeners.


fireReOpen

protected void fireReOpen()
Fires the connectionReOpened methods to all registered connection listeners.


fireClose

protected void fireClose()
Fires the connectionClosed methods to all registered connection listeners.


fireCall

protected void fireCall(boolean pCallBack,
                        String pObjectName,
                        String pMethodName,
                        Object... pParams)
Fires the objectCalled methods to all registered connection listeners.

Parameters:
pCallBack - whether the call was a callback call
pObjectName - the name of the remote object
pMethodName - the name of the method
pParams - the method parameters

fireCallAction

protected void fireCallAction(boolean pCallBack,
                              String pAction,
                              Object... pParams)
Fires the actionCalled methods to all registered connection listeners.

Parameters:
pCallBack - whether the action call was a callback call
pAction - the name of the action
pParams - the method parameters

logCommunication

protected void logCommunication(long pStart,
                                String pTitle,
                                Throwable pError,
                                Object... pInfo)
Loggs communication duration.

Parameters:
pStart - the communication start
pTitle - the communication "title", means the triggering method name like "open"
pError - if an error occured
pInfo - the log information (parameter)


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.