se.entra.phantom.server
Class ClientSession

java.lang.Object
  extended by se.entra.phantom.server.ClientSession
All Implemented Interfaces:
Runnable, ClientSessionInterface, HostSessionManagerListener, HostSessionManagerListener2

public class ClientSession
extends Object
implements Runnable, HostSessionManagerListener2, ClientSessionInterface

The threaded client session that one clients can connect to.


Method Summary
 void checkInactivity(int inactivityWarning, int inactivityTimeout)
          Checks if a warning message should be displayed on the client due to inactivity or if the session should be closed.
 void clientTrace(String text)
          Performs a trace output (normally after a call to doClientVerboseTrace.
 Transaction createTransaction()
          Create Transaction depending on the current codepage for this session.
 void displayTerminal()
          Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it.
 void displayTerminal(boolean keepVisible)
          Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it.
 void displayTerminal(boolean keepVisible, String heading)
          Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it.
 void dispose()
          Disposes of the client session.
 boolean doClientVerboseTrace()
          Checks if client verbose trace is turned on.
 boolean doesScreenContainData()
          Checks if the host screen contains data.
 boolean doesScreenMatch(PhantomHostScreen phantomScreen)
          Checks if a host screen currently matches.
 void dontUpdateLastTime()
          Causes the last client transaction time not to be set after processing of a client event.
 void enableWriteCache(IniFile ini)
          Enables the write cache of string for the Java Client.
 boolean exitApplication()
          Exits the current client session.
 void flagClientEventForProcessing()
          Flags a client event to be processed asynchronously.
 void flagHostEventForProcessing()
          Flags a host event to be processed asynchronously.
 ClientCommunicationInterface getClientCommunicationInterface()
          Gets the client communication interface..
 ClientCommunicationListener getClientCommunicationListener()
          Gets the non-Java client listener.
 ClientConnectionData getClientConnectionData()
          Gets the client connection data.
 se.entra.phantom.server.ClientJar getClientJar(String fn)
          Gets a Client JAR from a file request.
 ClientSessionManager getClientSessionManager()
          Gets a instance of the Client Session Manager.
 ClientWorker getClientWorker()
          Get client worker.
 Object getComponentLockObject()
          Gets the lock object for synchronization for Control Components.
 long getConnectionID()
          Gets the client connection ID.
 HostSession getCurrentHostSession()
          Gets the current host session.
 HostScreen getHostScreen()
          Gets the host screen.
 HostSessionManager getHostSessionManager()
          Gets the host session manager.
 long getLastTransactionTime()
          The last transaction time in "System.currentTimeMillis()".
 Object getLockObject()
          Gets the lock object (the virtual session manager).
 Transaction getModalReturnCode(int replyType)
          Gets the return code (Transaction) for a modal server-client request.
 PhantomRuntime getRuntimeApplication(String name)
          Gets a runtime application of an ID.
 int getSessionType()
          Gets the session type.
 long getWarningTime()
          Gets the warning time in milliseconds.
 VirtualSessionManager getVirtualSessionManager()
          Gets the VirtualSessionManager.
 boolean grabSessionFromPool(String[] runtimeIDs, int hostID)
          Checks if there is a session pooling handler that can be used for this client session.
 boolean hasJavaClient()
          Checks if this session is connected to a NetPhantom Java Client.
 boolean hasSessionTimedOut(long timeoutMillis)
          Checks if a session has been inactive for a certain amount of time.
 boolean initialize()
          Initiates a new session that is not connected to the NetPhantom Java Client.
 boolean initialize(boolean isEditor)
          Initiates a new session and indicates if it should be run in editor mode.
 Object invokeAndWait(ServerAction serverAction)
          Invokes the server action in the client worker thread and waits for a reply.
 void invokeLater(ServerAction serverAction)
          Invokes the server action in the client worker thread later and doesn't wait for a reply.
 boolean isClientTerminalDisplayed()
          Checks if the client is displaying the terminal window.
 boolean isClientTerminalDisplayedProgrammatically()
          Checks if the client is displaying the terminal window programmatically.
 boolean isDisposed()
          Checks if the session is disposed.
 boolean isEditor()
          Is this an editor instance.
 boolean isEditorParallelRun()
          Checks the flag to indicate that the instance runs in parallel with the editor.
 boolean isHostInducedHostChange()
          Checks if a host change (typically in a VirtualControl.refresh) is induced from host or from local host interaction.
 boolean isHostInErrorState()
          Checks if the current host session is in error state.
 boolean isHostLocked()
          Checks if the current host session is locked.
 boolean isInitialized()
          Is this initialized.
 boolean isMainThread()
          Checks if the current calling thread is the main thread.
 boolean isServerAdministration()
          Checks if the server administration is the current application.
 void logEvent(int id)
          Logs an event for the client.
 void logEvent(int id, String param)
          Logs an event for the client.
 void onHostConnectChange(boolean connected)
          Notifies the session of a connect state change.
 void onHostCursorPositionChange(int x, int y)
          Informs that the cursor position has changed.
 void onHostDataStreamProcessing(boolean isEntering)
          Called when entering or exiting data stream processing.
 void onHostFieldChange()
          Notifies the session that fields have changed.
 void onHostPrinterSessionFailure(Throwable exception)
          Called when a printer session has had a failure.
 void onHostScreenChange()
          Notifies the session of a screen change.
 void onHostSessionChange(HostSession hostSession, boolean isNewSession)
          Called when the current host session is changed.
 void onHostSessionFailure(String description)
          Deprecated. as of NetPhantom Version 3.8
 void onHostSessionFailure(Throwable exception)
          Called when a session has had a failure.
 void onHostStateChange()
          Notifies the session of a state change (such as insert mode, lock state, error state).
 void postClientTransaction(Transaction trans)
          Posts a client transaction for processing.
 boolean postMessageBoxTransaction(VirtualMessageBox vmb)
          Post a transaction to sent to the client from queue.
 void processCheckInactivity(int inactivityWarning, int inactivityTimeout)
          Checks if a warning message should be displayed on the client due to inactivity or if the session should be closed.
 void processClientEvent()
          Process a new client event.
 void processClientTransaction(Transaction trans)
          Processes events posted to the client worker for processing in the virtual session manager.
 void processHostEvent()
          Process a new host event.
 void removeTerminal()
          Removes the terminal window and displays all the panels again.
 void removeTerminal(boolean alwaysRemove)
          Removes the terminal window and displays all the panels again.
 void run()
          Starts running the threaded Client Session.
 void sendNegotiateSSL()
          Sends the negotiate SSL transaction to the client and waits for the reader thread to reply (it gets held for a while).
 void sendTransaction(Transaction trans)
          Sends a transaction to the client.
 void sendTransaction(Transaction trans, boolean doSetLastTransactionTime)
          Sends a transaction to the client.
 void setHostSessionManager(HostSessionManager manager)
          Sets the host session manager.
 void setInitialized(boolean init)
          Set initialized.
 void setLastTransactionTime()
          Sets the last timestamp for a transaction between the client and the server.
 void setModalReturnCode(Transaction trans)
          Sets the return code for a server-client request (message box).
 void setVirtualSessionManager(VirtualSessionManager manager)
          Sets the VirtualSessionManager.
 void soundAlarm()
          Sound alarm on the client.
 void soundAlarm(boolean fromHost)
          Sound alarm on the client.
 boolean waitForScreenChange(long msTime)
          Waits for a screen change for a certain time.
 boolean waitForUnlock(long msTime)
          Waits for the lock state to disappear for a certain time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSessionType

public int getSessionType()
Gets the session type. Can value can be ClientSessionManager.CLIENT_TYPE_JAVA, ClientSessionManager.CLIENT_TYPE_HTML or ClientSessionManager.CLIENT_TYPE_RAPP.


initialize

public boolean initialize()
Initiates a new session that is not connected to the NetPhantom Java Client.

Returns:
false if the session should not be created, due to lack of memory, host session failure, etc.

initialize

public boolean initialize(boolean isEditor)
Initiates a new session and indicates if it should be run in editor mode.

Returns:
false if the session should not be created, due to lack of memory, host session failure, etc.

getLockObject

public Object getLockObject()
Gets the lock object (the virtual session manager).

Specified by:
getLockObject in interface HostSessionManagerListener

isDisposed

public boolean isDisposed()
Checks if the session is disposed.


dispose

public void dispose()
Disposes of the client session.

Specified by:
dispose in interface ClientSessionInterface

sendNegotiateSSL

public void sendNegotiateSSL()
Sends the negotiate SSL transaction to the client and waits for the reader thread to reply (it gets held for a while).


isEditor

public boolean isEditor()
Is this an editor instance.

Returns:
boolean

isInitialized

public boolean isInitialized()
Is this initialized.

Returns:
boolean

setInitialized

public void setInitialized(boolean init)
Set initialized.

Parameters:
boolean -

isEditorParallelRun

public boolean isEditorParallelRun()
Checks the flag to indicate that the instance runs in parallel with the editor.


isServerAdministration

public boolean isServerAdministration()
Checks if the server administration is the current application.


run

public void run()
Starts running the threaded Client Session. The thread only runs for permanent connections (NetPhantom Java Clients).

Specified by:
run in interface Runnable

getClientCommunicationInterface

public ClientCommunicationInterface getClientCommunicationInterface()
Gets the client communication interface..

Specified by:
getClientCommunicationInterface in interface ClientSessionInterface

getConnectionID

public long getConnectionID()
Gets the client connection ID.


doesScreenMatch

public boolean doesScreenMatch(PhantomHostScreen phantomScreen)
Checks if a host screen currently matches.

Specified by:
doesScreenMatch in interface HostSessionManagerListener

getVirtualSessionManager

public VirtualSessionManager getVirtualSessionManager()
Gets the VirtualSessionManager.

Specified by:
getVirtualSessionManager in interface ClientSessionInterface

setVirtualSessionManager

public void setVirtualSessionManager(VirtualSessionManager manager)
Sets the VirtualSessionManager. This method should be called with CARE!


getRuntimeApplication

public PhantomRuntime getRuntimeApplication(String name)
Gets a runtime application of an ID.

Returns:
null if application does not exist.

getClientSessionManager

public ClientSessionManager getClientSessionManager()
Gets a instance of the Client Session Manager.


getClientConnectionData

public final ClientConnectionData getClientConnectionData()
Gets the client connection data.

Specified by:
getClientConnectionData in interface ClientSessionInterface
Returns:
null if there is no client connection, i.e. that this client session isn't disposed for caching purposes.

enableWriteCache

public void enableWriteCache(IniFile ini)
Enables the write cache of string for the Java Client. If "ini" is null, the cache is disabled.


sendTransaction

public void sendTransaction(Transaction trans)
Sends a transaction to the client. The transaction is first encrypted.

Specified by:
sendTransaction in interface ClientSessionInterface

sendTransaction

public void sendTransaction(Transaction trans,
                            boolean doSetLastTransactionTime)
Sends a transaction to the client. The transaction is first encrypted.


flagClientEventForProcessing

public void flagClientEventForProcessing()
Flags a client event to be processed asynchronously.

Specified by:
flagClientEventForProcessing in interface ClientSessionInterface

flagHostEventForProcessing

public void flagHostEventForProcessing()
Flags a host event to be processed asynchronously.

Specified by:
flagHostEventForProcessing in interface ClientSessionInterface

postClientTransaction

public void postClientTransaction(Transaction trans)
Posts a client transaction for processing.

Specified by:
postClientTransaction in interface ClientSessionInterface

postMessageBoxTransaction

public boolean postMessageBoxTransaction(VirtualMessageBox vmb)
Post a transaction to sent to the client from queue.


setModalReturnCode

public void setModalReturnCode(Transaction trans)
Sets the return code for a server-client request (message box). This method should be called only from the VirtualSessionManager client transaction reader thread.

Specified by:
setModalReturnCode in interface ClientSessionInterface

getModalReturnCode

public Transaction getModalReturnCode(int replyType)
Gets the return code (Transaction) for a modal server-client request.

Specified by:
getModalReturnCode in interface ClientSessionInterface

getHostScreen

public HostScreen getHostScreen()
Gets the host screen.

Specified by:
getHostScreen in interface ClientSessionInterface

getHostSessionManager

public HostSessionManager getHostSessionManager()
Gets the host session manager.

Specified by:
getHostSessionManager in interface ClientSessionInterface

setHostSessionManager

public void setHostSessionManager(HostSessionManager manager)
Sets the host session manager. This method should be used with CARE!


getCurrentHostSession

public HostSession getCurrentHostSession()
Gets the current host session.

Specified by:
getCurrentHostSession in interface ClientSessionInterface
Returns:
null if no session is current.

isHostLocked

public boolean isHostLocked()
Checks if the current host session is locked.

Specified by:
isHostLocked in interface ClientSessionInterface

isHostInErrorState

public boolean isHostInErrorState()
Checks if the current host session is in error state.

Specified by:
isHostInErrorState in interface ClientSessionInterface

isHostInducedHostChange

public boolean isHostInducedHostChange()
Checks if a host change (typically in a VirtualControl.refresh) is induced from host or from local host interaction.


waitForUnlock

public boolean waitForUnlock(long msTime)
Waits for the lock state to disappear for a certain time. Note that if the wait-time is negative, an "indefinite" wait will be done. The time is in milliseconds.

Specified by:
waitForUnlock in interface ClientSessionInterface
Returns:
true = success, false = time-out.

waitForScreenChange

public boolean waitForScreenChange(long msTime)
Waits for a screen change for a certain time. Note that if the wait-time is negative, an "indefinite" wait will be done. The time is in milliseconds. This method will return true if there has been any kind of screen change since the last call to this routine.

Specified by:
waitForScreenChange in interface ClientSessionInterface
Returns:
true = success, false = time-out.

getComponentLockObject

public Object getComponentLockObject()
Gets the lock object for synchronization for Control Components.


onHostConnectChange

public void onHostConnectChange(boolean connected)
Notifies the session of a connect state change.

Specified by:
onHostConnectChange in interface HostSessionManagerListener

doesScreenContainData

public boolean doesScreenContainData()
Checks if the host screen contains data.

Specified by:
doesScreenContainData in interface ClientSessionInterface

onHostStateChange

public void onHostStateChange()
Notifies the session of a state change (such as insert mode, lock state, error state).

Specified by:
onHostStateChange in interface HostSessionManagerListener

onHostFieldChange

public void onHostFieldChange()
Notifies the session that fields have changed.

Specified by:
onHostFieldChange in interface HostSessionManagerListener

onHostScreenChange

public void onHostScreenChange()
Notifies the session of a screen change.

Specified by:
onHostScreenChange in interface HostSessionManagerListener

onHostCursorPositionChange

public void onHostCursorPositionChange(int x,
                                       int y)
Informs that the cursor position has changed.

Specified by:
onHostCursorPositionChange in interface HostSessionManagerListener

processHostEvent

public void processHostEvent()
Process a new host event.

Specified by:
processHostEvent in interface ClientSessionInterface

processClientEvent

public void processClientEvent()
Process a new client event.

Specified by:
processClientEvent in interface ClientSessionInterface

processClientTransaction

public void processClientTransaction(Transaction trans)
Processes events posted to the client worker for processing in the virtual session manager.

Specified by:
processClientTransaction in interface ClientSessionInterface

isMainThread

public boolean isMainThread()
Checks if the current calling thread is the main thread. Main threads are not allowed to wait for screen/host changes.

Specified by:
isMainThread in interface ClientSessionInterface

exitApplication

public boolean exitApplication()
Exits the current client session.

The connection to the client will be closed and the terminal sessions stopped. The session will then be restarted for use by another client session.

Specified by:
exitApplication in interface ClientSessionInterface

displayTerminal

public void displayTerminal()
Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it.

Specified by:
displayTerminal in interface ClientSessionInterface

displayTerminal

public void displayTerminal(boolean keepVisible)
Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it.


displayTerminal

public void displayTerminal(boolean keepVisible,
                            String heading)
Creates the terminal window, gets the contents of the terminal window, hides all the panels, and displays it. The heading parameter can be set to null for default title text.


removeTerminal

public void removeTerminal()
Removes the terminal window and displays all the panels again.

Specified by:
removeTerminal in interface ClientSessionInterface

removeTerminal

public void removeTerminal(boolean alwaysRemove)
Removes the terminal window and displays all the panels again.


isClientTerminalDisplayed

public boolean isClientTerminalDisplayed()
Checks if the client is displaying the terminal window.

Specified by:
isClientTerminalDisplayed in interface ClientSessionInterface

isClientTerminalDisplayedProgrammatically

public boolean isClientTerminalDisplayedProgrammatically()
Checks if the client is displaying the terminal window programmatically.


soundAlarm

public void soundAlarm()
Sound alarm on the client.

Specified by:
soundAlarm in interface ClientSessionInterface
Specified by:
soundAlarm in interface HostSessionManagerListener

soundAlarm

public void soundAlarm(boolean fromHost)
Sound alarm on the client.


getClientWorker

public ClientWorker getClientWorker()
Get client worker.

Specified by:
getClientWorker in interface ClientSessionInterface

onHostSessionFailure

@Deprecated
public void onHostSessionFailure(String description)
Deprecated. as of NetPhantom Version 3.8

Called when a session has had a failure.

Specified by:
onHostSessionFailure in interface HostSessionManagerListener

onHostSessionFailure

public void onHostSessionFailure(Throwable exception)
Called when a session has had a failure.

Specified by:
onHostSessionFailure in interface HostSessionManagerListener2

onHostPrinterSessionFailure

public void onHostPrinterSessionFailure(Throwable exception)
Called when a printer session has had a failure.


logEvent

public void logEvent(int id)
Logs an event for the client.

Specified by:
logEvent in interface ClientSessionInterface

logEvent

public void logEvent(int id,
                     String param)
Logs an event for the client.

Specified by:
logEvent in interface ClientSessionInterface

getWarningTime

public long getWarningTime()
Gets the warning time in milliseconds.


setLastTransactionTime

public void setLastTransactionTime()
Sets the last timestamp for a transaction between the client and the server.


getLastTransactionTime

public long getLastTransactionTime()
The last transaction time in "System.currentTimeMillis()".

Returns:
0 for non Java clients or if not yet set.

dontUpdateLastTime

public void dontUpdateLastTime()
Causes the last client transaction time not to be set after processing of a client event.


checkInactivity

public void checkInactivity(int inactivityWarning,
                            int inactivityTimeout)
Checks if a warning message should be displayed on the client due to inactivity or if the session should be closed.


processCheckInactivity

public void processCheckInactivity(int inactivityWarning,
                                   int inactivityTimeout)
Checks if a warning message should be displayed on the client due to inactivity or if the session should be closed. This method is called by the worker thread.

Specified by:
processCheckInactivity in interface ClientSessionInterface

hasSessionTimedOut

public boolean hasSessionTimedOut(long timeoutMillis)
Checks if a session has been inactive for a certain amount of time.


doClientVerboseTrace

public boolean doClientVerboseTrace()
Checks if client verbose trace is turned on.

Specified by:
doClientVerboseTrace in interface ClientSessionInterface

clientTrace

public void clientTrace(String text)
Performs a trace output (normally after a call to doClientVerboseTrace.

Specified by:
clientTrace in interface ClientSessionInterface

createTransaction

public Transaction createTransaction()
Create Transaction depending on the current codepage for this session.

Specified by:
createTransaction in interface ClientSessionInterface

hasJavaClient

public boolean hasJavaClient()
Checks if this session is connected to a NetPhantom Java Client.

Specified by:
hasJavaClient in interface ClientSessionInterface

getClientCommunicationListener

public ClientCommunicationListener getClientCommunicationListener()
Gets the non-Java client listener.


grabSessionFromPool

public boolean grabSessionFromPool(String[] runtimeIDs,
                                   int hostID)
Checks if there is a session pooling handler that can be used for this client session.

This function will change the hostSessionManager in the case of a successful grab or a session in the session pool.

Returns:
true if one is found, false otherwise.

onHostSessionChange

public void onHostSessionChange(HostSession hostSession,
                                boolean isNewSession)
Called when the current host session is changed. This call is done before the actual change, and then afterwards when the change has been done. The flag "isNewSession" is true when the "session-to-be" becomes the active one.

Specified by:
onHostSessionChange in interface HostSessionManagerListener

onHostDataStreamProcessing

public void onHostDataStreamProcessing(boolean isEntering)
Called when entering or exiting data stream processing.

Specified by:
onHostDataStreamProcessing in interface HostSessionManagerListener

invokeLater

public void invokeLater(ServerAction serverAction)
Invokes the server action in the client worker thread later and doesn't wait for a reply.


invokeAndWait

public Object invokeAndWait(ServerAction serverAction)
Invokes the server action in the client worker thread and waits for a reply. This call is working also for the AWT thread for the NetPhantom Editor when the DirectInterface is used. If the client or the system closes the client process, a ClientSessionDisposed is thrown. If this method is invoked from the client worker thread, an InternalError is thrown.

Returns:
the return code from the server action or null if the client process is closed by the user or the system.

getClientJar

public se.entra.phantom.server.ClientJar getClientJar(String fn)
Gets a Client JAR from a file request.

Returns:
null if not found.


Phantom® and NetPhantom® are registered trademarks of Codectica Systems SARL.
© Copyright Codectica Systems SARL, 2008. All rights reserved.