public class DefaultSessionPoolingHandler extends HostSessionManagerAdapter
Each session pool can have a Phantom Runtime file associated with it. This eases the interaction with the host system, to check for matching screens, use host fields, etc. The Runtime file is only used for screen identification and host field processing, i.e. no panels or objects (REXX or other) are used.
Note: In the JavaDoc of the class, tags are written as (tagname [params]/) or (/tagname) for better readability in the code, instead of <tagname [params]/> or </tagname>.
File Format
The file must have the following format (note that XML is case sensitive as opposed to HTML):
(?xml version="1.0"?) (SessionPoolingScript version="1.00" implclass="se.entra.phantom.server.DefaultSessionPoolingHandler" runtimefile="samples/tutor/TUTOR.NPR") (extensions) (function name="SaveGlobalHostData" method="saveGlobalHostData" class="com.acme.SessionPool"/) (function name="YourHostCheck" method="yourHostCheck"/) (/extensions) (actions) (action name="START" maxtime="seconds") (script) ... the script here ... (/script) (/action) (action name="PING" maxtime="seconds") (script) ... the script here ... (/script) (/action) (action name="CHECK" maxtime="seconds") (script) ... the script here ... (/script) (/action) (action name="RECLAIM" maxtime="seconds") (script) ... the script here ... (/script) (/action) (action name="DISPOSE" maxtime="seconds") (script) ... the script here ... (/script) (/action) (/actions) (/SessionPoolingScript)Any main tags not recognized are not processed. The action tag must contain a script tag describing what "instructions" are to be processed. For the action tag, a parameter maxtime can be specified in seconds. If the script has not completed within this time limit, the session is considered invalid and is disposed of (not calling the script of the dispose action).
The DefaultSessionPoolingHandler
is a class provided as a default handler
for the session pooling. It provides by default the option to add external
functions in new classes (using the extensions section in the XML file). This is
done using Custom Method Calls (see the documentation in PDF form).
An extending Java class can also override it in order to provide a higher or more specialized functionality. For more advanced processing, the script tag handling can be overridden.
Modifier and Type | Field and Description |
---|---|
protected ClientConnectionData |
clientConnectionData
The client connection data for this session.
|
protected long |
completeTime
The time in milliseconds when an action completed,
i.e.
|
protected PhantomHostScreen |
currentScreen
The screen that currently matches (null when none single-matches).
|
protected int |
currentState
The state variable, by default STATE_STARTING.
|
protected SessionPoolingData |
globalPoolData
The pool data shared by all sessions in the same pool.
|
protected boolean |
hasHostChanged
Flag indicating that any host change has occured.
|
protected boolean |
hasHostCursorChanged
Flag indicating that the host cursor position has changed.
|
protected boolean |
hasHostFieldsChanged
Flag indicating that the host fields has changed.
|
protected boolean |
hasHostScreenChanged
Flag indicating that the host screen has changed.
|
protected HostSessionManager |
hostSessionManager
The host session manager can handle multiple host sessions,
but only one is the current one that notifies the listener
of events.
|
protected JInternalFrame |
iframe
The internal frame window.
|
protected boolean |
isDisposed
Flag set if session is disposed by the system and should
abort any scripting thread executing.
|
static int |
STATE_CHECK
State indicating that the Check script is executing.
|
static int |
STATE_DISPOSED
State indicating that the session is disposed.
|
static int |
STATE_DISPOSING
State indicating that the session is about to be disposed
(i.e.
|
static int |
STATE_INUSE
State indicating that this session is in use by an application.
|
static int |
STATE_PING
State indicating that the Ping script is executing.
|
static int |
STATE_PINGING
State indicating that the thread that will perform the Ping script
is about to start executing.
|
static int |
STATE_READY
State indicating that the session is started and ready (since last
Start, Ping or Reclaim).
|
static int |
STATE_RECLAIM
State indicating that the Reclaim script is executing.
|
static int |
STATE_RECLAIMING
State indicating that the thread that will perform the Reclaim script
is about to start executing.
|
static int |
STATE_START
State indicating that the Start script is executing.
|
static int |
STATE_STARTING
State indicating that the thread that will perform the Start script
is about to start executing.
|
static String[] |
stringStates
The string represenation of the numerical STATE_nnn in english.
|
protected int |
timeoutValue
The current timeout in milliseconds.
|
Constructor and Description |
---|
DefaultSessionPoolingHandler()
The constructor does nothing at all.
|
Modifier and Type | Method and Description |
---|---|
void |
attachSession(ClientSession cs)
Attaches this session to a started client session.
|
void |
checkDisposed()
Sets the disposed flag and throws the SessionPoolingDisposed exception.
|
boolean |
checkPingRequired()
Checks if a session ping is required for this session
and if so this operation is initiated.
|
protected void |
createHostSessionManager()
Creates the host session manager and a GUI window (if server
runs with GUI).
|
static SessionPoolingData |
createSessionPoolingData(SessionPoolingData original)
Creates and initializes a pool.
|
void |
detachSession(ClientSession cs)
Detaches a client session from this pooled session.
|
void |
dispose()
Call to dispose promptly of the session, without executing scripts, etc.
|
void |
disposeFatal()
Disposes of the session due to a fatal error.
|
void |
disposeNow()
Disposes of the session (e.g.
|
void |
disposeNow(String exceptionMsg)
Disposes of the session (e.g.
|
boolean |
doesScreenMatch(PhantomHostScreen phantomScreen)
Checks if a host screen currently matches.
|
ClientConnectionData |
getClientConnectionData()
Gets the client connection data for this session.
|
HostSession |
getCurrentClearedHostSession()
This function clears any outstanding errors and returns the current
host session.
|
int |
getCurrentState()
Gets the current state.
|
String |
getCurrentStringState()
Gets the string representation of the current state as set
by the
stringStates string array. |
SessionPoolingData |
getGlobalPoolData()
Gets the global pooling data.
|
Object |
getLockObject()
Gets a lock object that is used by all threads modifying
the host screen.
|
Method |
getScriptTagMethod(String name)
Gets a method from a script tag in the global pool data.
|
PhantomHostScreen |
getSingleMatchingScreen()
Rematches the current matching screens and returns the single matching screen.
|
boolean |
hostWait(SessionPoolingScriptData data,
boolean hostlock,
boolean hoststable,
int time,
int timeout)
Waits a certain time for a condition to be true.
|
void |
initialize(SessionPoolingData globalPoolData,
ClientConnectionData clientConnectionData)
Called to initialize this instance with the global
pool data.
|
boolean |
isDisposed()
Checks if the session is disposed of.
|
boolean |
isValidAndCheckSession()
Checks if this session is valid and the check script has just completed successfully.
|
void |
logError(String txt)
Logs an session pooling error event in the event log.
|
void |
logInfo(String txt)
Logs an session pooling informational event in the event log.
|
void |
logWarning(String txt)
Logs an session pooling warning event in the event log.
|
void |
onHostConnectChange(boolean connected)
Informs that the current host session had a connection change.
|
void |
onHostCursorPositionChange(int x,
int y)
Informs that the cursor position has changed.
|
void |
onHostFieldChange()
Informs that the current host session had a field change.
|
void |
onHostScreenChange()
Informs that the current host session had a screen change.
|
void |
onHostSessionFailure(String description)
Informs that the current host session had a failure.
|
void |
onHostStateChange()
Informs that the current host session had a state change.
|
void |
runDisposeScript()
Runs the dispose script for the session.
|
void |
runPingScript()
Runs the ping script.
|
void |
runReclaimScript()
Runs the reclaim script.
|
void |
runStartScript()
Runs the starts script for the session.
|
void |
scriptBREAK(SessionPoolingScriptData data)
Breaks out of a while loop.
|
void |
scriptCONDITIONS(SessionPoolingScriptData data)
The conditions tag should normally be used together with the if,
elseif and the while tags.
|
void |
scriptDISPOSE(SessionPoolingScriptData data)
Immediately disposes of this pooled session without executing a single additional tag.
|
void |
scriptHOSTERROR(SessionPoolingScriptData data)
An error state is typically set if data is input in a protected field,
there is some communications failure or, for 5250, if a "System Message"
is present.
|
void |
scriptIF(SessionPoolingScriptData data)
Processes an
if begin tag (and the else or elseif tags that follows). |
void |
scriptLOG(SessionPoolingScriptData data)
Logs an event in the NetPhantom Event Log.
|
void |
scriptONERROR(SessionPoolingScriptData data)
When an error condition occurs in a script, the next on error tag
instructions are executed.
|
void |
scriptRESET(SessionPoolingScriptData data)
This tag resets any error condition present in host session,
after e.g.
|
void |
scriptRETURN(SessionPoolingScriptData data)
Stops execution in a script with the specified return code.
|
void |
scriptSCREEN(SessionPoolingScriptData data)
The instructions inside the block are executed if the current host screen name
matches uniquely.
|
void |
scriptSEND(SessionPoolingScriptData data)
This tag is used to send a series of keystrokes to the terminal session formatted
according to EHLLAPI codes (e.g.
|
void |
scriptSET(SessionPoolingScriptData data)
This tag can be used to set data in a host field of the currently matching
host screen.
|
void |
scriptTRACE(SessionPoolingScriptData data)
Adds text to the trace file.
|
void |
scriptWAIT(SessionPoolingScriptData data)
The wait tag is used to wait a specified time in milliseconds or a maximum
time in milliseconds (default 60000 milliseconds, or changed by the set timeout tag).
|
void |
scriptWHILE(SessionPoolingScriptData data)
The while instructions are executed as long as the conditions are true.
|
void |
setCompleteTime()
Sets the time for completion of a start or ping action.
|
void |
startDisposeThread(DefaultSessionPoolingHandler handler)
Starts execution of the Dispose thread.
|
void |
startReclaimThread()
Starts execution of the Reclaim thread.
|
void |
trace(String txt)
Adds a trace output for session pooling if client verbose trace is turned on.
|
void |
trace(String txt,
String[] moreTxt)
Adds a trace output for session pooling if client verbose trace is turned on.
|
void |
waitInitialScreen(SessionPoolingScriptData data)
Waits for some data on a screen after a new connection.
|
onHostDataStreamProcessing, onHostSessionChange, onHostSessionFailure, soundAlarm
public static final int STATE_STARTING
public static final int STATE_START
public static final int STATE_READY
public static final int STATE_PINGING
public static final int STATE_PING
public static final int STATE_CHECK
public static final int STATE_INUSE
public static final int STATE_RECLAIMING
public static final int STATE_RECLAIM
public static final int STATE_DISPOSING
public static final int STATE_DISPOSED
public static String[] stringStates
protected boolean isDisposed
protected SessionPoolingData globalPoolData
protected ClientConnectionData clientConnectionData
protected int currentState
protected JInternalFrame iframe
protected long completeTime
protected HostSessionManager hostSessionManager
protected PhantomHostScreen currentScreen
protected boolean hasHostScreenChanged
protected boolean hasHostCursorChanged
protected boolean hasHostFieldsChanged
protected boolean hasHostChanged
protected int timeoutValue
public DefaultSessionPoolingHandler()
public static SessionPoolingData createSessionPoolingData(SessionPoolingData original)
This method is overridable in order to create an instance
of an extended class of SessionPoolingData
.
If an error occurs in e.g. the script file, the calling party is responsible for logging the event.
SessionPoolingData
class instance.public void initialize(SessionPoolingData globalPoolData, ClientConnectionData clientConnectionData)
public ClientConnectionData getClientConnectionData()
public SessionPoolingData getGlobalPoolData()
public Method getScriptTagMethod(String name)
Method
instance.public final void checkDisposed() throws SessionPoolingDisposed
SessionPoolingDisposed
- if the session has been disposed of.public final boolean isDisposed()
public void disposeFatal() throws SessionPoolingDisposed
SessionPoolingDisposed
- always.public void disposeNow() throws SessionPoolingDisposed
SessionPoolingDisposed
exception.SessionPoolingDisposed
- always.public void disposeNow(String exceptionMsg) throws SessionPoolingDisposed
SessionPoolingDisposed
exception with the
message exceptionMsg
.SessionPoolingDisposed
- always.public void dispose()
This method MUST call the SessionPoolingData
sessionDisposed
method.
If the session already is disposed of, nothing will happen.
public int getCurrentState()
public String getCurrentStringState()
stringStates
string array.public boolean isValidAndCheckSession()
public void attachSession(ClientSession cs)
public void detachSession(ClientSession cs)
public void startReclaimThread()
currentState
variable should be set to STATE_RECLAIMING.public void startDisposeThread(DefaultSessionPoolingHandler handler)
public void trace(String txt)
public void trace(String txt, String[] moreTxt)
public void logError(String txt)
public void logWarning(String txt)
public void logInfo(String txt)
public void setCompleteTime()
public boolean checkPingRequired()
This will not be performed if there is no Ping script defined in the XML file.
If the session is busy or in use by an application, false is returned.
protected void createHostSessionManager()
public HostSession getCurrentClearedHostSession() throws SessionPoolingScriptHostError
SessionPoolingScriptHostError
- if there is no current host session
or if there is a host error.public void waitInitialScreen(SessionPoolingScriptData data) throws SessionPoolingDisposed
data
parameter is null,
disposal of script is not checked, but disposal of the session is.SessionPoolingDisposed
- when the connection fails.public PhantomHostScreen getSingleMatchingScreen()
public boolean hostWait(SessionPoolingScriptData data, boolean hostlock, boolean hoststable, int time, int timeout) throws SessionPoolingDisposed
If the parameter data
is non-null, the following parameters are
extracted from the data.currentElement
tag:
screen="SCREENNAME" [multiple] [negate]or
hosttext="text" [nocase] [negate] column="xx" row="yy" [relative] [width="nn" [wildcard]]or
hostfield="NAME" text="text" [nocase] [negate] [line="nn"] [wildcard]Any of the combinations of the above parameters are allowed, e.g. waiting for a screen and a host field, a screen and a host text.
The wildcard match option enables text to be matched with Windows-like wildcards:
? is any character,
* is any number of characters,
^ is the escape character, i.e. the meaning of '?' and '*' becomes the
actual character that directly follows,
^^ two escape characters becomes the escape character itself ('^').
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptHostError
- when a host error is encountered.public Object getLockObject()
getLockObject
in interface HostSessionManagerListener
getLockObject
in class HostSessionManagerAdapter
public void onHostConnectChange(boolean connected)
onHostConnectChange
in interface HostSessionManagerListener
onHostConnectChange
in class HostSessionManagerAdapter
public void onHostScreenChange()
onHostScreenChange
in interface HostSessionManagerListener
onHostScreenChange
in class HostSessionManagerAdapter
public void onHostCursorPositionChange(int x, int y)
onHostCursorPositionChange
in interface HostSessionManagerListener
onHostCursorPositionChange
in class HostSessionManagerAdapter
public void onHostFieldChange()
onHostFieldChange
in interface HostSessionManagerListener
onHostFieldChange
in class HostSessionManagerAdapter
public void onHostStateChange()
onHostStateChange
in interface HostSessionManagerListener
onHostStateChange
in class HostSessionManagerAdapter
public void onHostSessionFailure(String description)
onHostSessionFailure
in interface HostSessionManagerListener
onHostSessionFailure
in class HostSessionManagerAdapter
public boolean doesScreenMatch(PhantomHostScreen phantomScreen)
doesScreenMatch
in interface HostSessionManagerListener
doesScreenMatch
in class HostSessionManagerAdapter
public void runStartScript() throws SessionPoolingDisposed
Called when a session is started in the pool. The start time is set before the terminal session is created. The script is called once the host session is unlocked and has a non-empty host screen. Typically, the script would navigate in the host so as to reach the "starting point screen".
SessionPoolingDisposed
- if the session is disposed.public void runPingScript() throws SessionPoolingDisposed
Called periodically by the session pool manager (optional setting). This enables, for example, the script to perform some action in the host in order to make sure it is not going to be disconnected by or logged from the host. The script should also verify that the host is at the "starting point screen".
SessionPoolingDisposed
- if the session is disposed.public void runReclaimScript() throws SessionPoolingDisposed
Called when a client session is closed in order to reclaim the host session into the pool. This enables the script to, for example, back out from a series of host screens to a starting point. When the reclaim action is called, the user who owned the host session could have navigated "deep down" in the host system.
SessionPoolingDisposed
- if the session is disposed.public void runDisposeScript() throws SessionPoolingDisposed
Called prior to disposing of the terminal session. Typically, the script would logoff from the host system in a controlled way. Note that the current host screen could be "anywhere" in the host system.
SessionPoolingDisposed
- if the session is disposed.public void scriptIF(SessionPoolingScriptData data) throws SessionPoolingDisposed
if
begin tag (and the else or elseif tags that follows).
Syntax:
(if) (conditions [negate]) ... conditions ... (/conditions) ... instructions ... (/if) (elseif) (conditions [negate]) ... conditions ... (/conditions) ... instructions ... (/elseif) (else) ... instructions ... (/else)The elseif block can be repeated any number of times or not specified at all. The else block may only be specified once and can also be omitted.
Return code: true if there was an if or elseif condition that was true, false otherwise. This applies when no instructions have been executed. The return code is otherwise the return code of the last executed instruction (i.e. tag).
SessionPoolingDisposed
- when a script has been disposed.public void scriptCONDITIONS(SessionPoolingScriptData data) throws SessionPoolingDisposed
The negate option logically negates each condition tag processed before the logical and operation is performed. That is, a return code of true in a condition tag stops execution of the remaining tags, returning a value of false.
Syntax:
(conditions [negate]) ... conditions ... (/conditions)Return code: true if all tags inside the "conditions" block are true, false otherwise. Processing of execution of the tags inside the block is immediately stopped if one of the tags returns false (or true for the negate option).
SessionPoolingDisposed
- when a script has been disposed.public void scriptWHILE(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(while) (conditions [negate]) ... conditions ... (/conditions) ... instructions ... (/while)or the do-while style:
(while) ... instructions ... (conditions [negate]) ... conditions ... (/conditions) (/while)Return code: The return code of the last executed instruction (i.e. tag).
SessionPoolingDisposed
- when a script has been disposed.public void scriptRESET(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(reset/)Return code: true if the function was successful or no error state existed for the session, false otherwise (host was not in an error state that could not be reset due to e.g. communications failure).
SessionPoolingDisposed
- when a script has been disposed.public void scriptHOSTERROR(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(hosterror/)Return code: true if the host is presently in an error state. If no error condition is present, false is returned.
SessionPoolingDisposed
- when a script has been disposed.public void scriptONERROR(SessionPoolingScriptData data) throws SessionPoolingDisposed
SessionPoolingDisposed
- when a script has been disposed.public void scriptLOG(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(log [level="nn"] text="text" [lasterror]/)The value nn can be 0=informational (default), 1=warning, 2=error, 3=critical. It can also be the first character, i.e. I, W, E or C.
If the lasterror parameter is specified, the last encountered error message for the terminal session is added. Note for 5250 sessions: a system error message always begins with the text "last error 5250:".
Return code: always true.
SessionPoolingDisposed
- when a script has been disposed.public void scriptTRACE(SessionPoolingScriptData data) throws SessionPoolingDisposed
If the lasterror parameter is specified, the last encountered error message for the terminal session is added.
Note: for 5250 sessions, a system error message always begins with the text "last error 5250:".
If the parameter dumpscreen is present, the host screen character data is appended.
(/trace text="text" [lasterror] [dumpscreen]/)Return code: always true.
SessionPoolingDisposed
- when a script has been disposed.public void scriptBREAK(SessionPoolingScriptData data) throws SessionPoolingDisposed
If not inside a while loop, this tag would have the same processing as a return tag, optionally setting the return code to true or false.
If the return code is not set, the last return code is used.
Syntax:
(break [true]/) (break [false]/)Return code: true or false options if the parameters are set, otherwise the return code of the last instruction (i.e. tag).
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptBreak
- always.public void scriptRETURN(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(return true/) (return false/)Return code: true or false depending on the parameter.
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptReturn
- always.public void scriptDISPOSE(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(dispose/)This tag does not return a value, an exception is thrown and the script is terminated.
SessionPoolingDisposed
- when a script has been disposed.public void scriptSEND(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(send string="string"/) (send userid="USERID"/)The
userid
option will send the password for the "USERID"
that is specified in the NetPhantom Users using the Server Administration program.
The send tag always waits for the session to be unlocked (due to e.g. sending an
AID key such as Enter). The maximum wait time is the default timeout (60 seconds)
or if it is changed using the set
function.
An error with this function will resume execution at the next onerror tag.
Note that the type-ahead of keystrokes is enabled only if this option is enabled for host sessions using the Server Administration program.
Return code: always true.
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptHostError
- when a host error is encountered.public void scriptWAIT(SessionPoolingScriptData data) throws SessionPoolingDisposed
It is also used to wait for the host lock state, the host session to be stabilized within the timeout value, a screen to match or a host text to be present (using absolute or relative screen position, also including hidden/non-display text as an option). When the time option is defined with waiting functions for the host (e.g. screen and/or the host locked or host stable options), this function will wait an additional time before returning, e.g. if the host screen is changed or the cursor moved during this time, the wait time is reset to zero.
The option negate is used to invert this result.
Note that the (optional) parameters column, row and line are "one-based" numerical values.
The wildcard match option enables text to be matched with Windows-like wildcards:
? is any character,
* is any number of characters,
^ is the escape character, i.e. the meaning of '?' and '*' becomes the
actual character that directly follows,
^^ two escape characters becomes the escape character itself ('^').
This tag is also used as a condition tag.
Syntax:
(wait time="milliseconds" [hostlocked] [cursorstable]/) (wait screen="SCREENNAME" [multiple] [negate] [hostlocked] [hoststable] [time="milliseconds"] [timeout="milliseconds"]/) (wait hosttext="text" [nocase] [negate] column="xx" row="yy" [relative] [width="nn" [wildcard]] [hostlocked] [hoststable] [time="milliseconds"] [timeout="milliseconds"]/) (wait hostfield="NAME" text="text" [nocase] [negate] [line="nn"] [wildcard] [hostlocked] [hoststable] [time="milliseconds"] [timeout="milliseconds"]/)Return code: true when the condition is reached within the timeout time or false if not.
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptHostError
- when a host error is encountered.public void scriptSCREEN(SessionPoolingScriptData data) throws SessionPoolingDisposed
If the screen does not match, execution continues at the tag below.
Syntax:
(screen name="ABC" [multiple] [negate]) ... instructions ... (/screen)Return code: true if the screen matches (uniquely), false otherwise. The negate option inverts this result.
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptHostError
- when a host error is encountered.public void scriptSET(SessionPoolingScriptData data) throws SessionPoolingDisposed
Syntax:
(set hostfield="NAME" [line="nn"] text="text"/)or
(set hostfield="NAME" [line="nn"] userid="USERID"/)or
(set cursor [relative] column="xx" row="yy"/)or
(set cursor hostfield="NAME" [line="nn"] [pos="charpos"]/)or
(set timeout="milliseconds"/)
The userid option will set the password for the "USERID" that is specified in the NetPhantom Users using the Server Administration program.
Note: all numeric parameters are "one-based" for line, pos, column, row.
Note: the currently matching screen is only set when the screen or wait screen tag has been executed prior to this tag (this also applies to host pop-up window recognition only executed with these tags).
An error with this function will resume execution at the next onerror tag.
Return code: true if the function caused a change, false otherwise (i.e. cursor didn't move, timeout didn't change, host field already contained the text to set).
SessionPoolingDisposed
- when a script has been disposed.SessionPoolingScriptHostError
- when a host error is encountered.Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.