Class NonUIClient
- All Implemented Interfaces:
GManagementConstants
,ISessionStatistics
,ISessionTransMgr
,TransactionCommListener
,EventListener
,GConstants
,IPropMgrOwner
- Author:
- Christopher Mindus
Field Summary
Fields inherited from interface com.iizix.GConstants
TRANS_ATOM, TRANS_BINARY_DATA, TRANS_BUSY, TRANS_CLIENT_LOCK, TRANS_CREATE, TRANS_DISPLAYTERMINAL, TRANS_DOWNLOAD_RESOURCES, TRANS_HOSTPRINT, TRANS_INIT, TRANS_INSTALL_RESOURCE, TRANS_LOG, TRANS_MANAGEMENT, TRANS_MESSAGE, TRANS_RELOAD, TRANS_REMOTE_CALL, TRANS_REMOTE_EVENT, TRANS_REMOTE_REPLY, TRANS_REMOVETERMINAL, TRANS_TERMINALUPDATE, TRANS_UPDATE
Fields inherited from interface com.iizix.comm.GManagementConstants
MT_CONNECTION, MT_DISPOSE_WHEN_CLOSED, MT_NEXT_SERIAL, MT_PING, MT_PONG, MT_PW, MT_RECONNECTION, MT_RESEND_TRANS
Constructor Summary
ConstructorDescriptionNonUIClient
(ClientManager manager, String name, DestinationServer... destinations) Constructor.Method Summary
Modifier and TypeMethodDescriptionfinal boolean
addDestination
(DestinationServer destination) Adds a new destination server.protected void
configureSSLProps
(SSLCommProps sslProps, DestinationServer destination) Configures the SSL properties for the destination server.final void
connect()
Connects to one of the destination servers in turn.protected SSLCommProps
createSSLProps
(DestinationServer destination) The SSL properties, null for plain communication.final void
dispose()
Disposes of the client manager.final void
doDispose
(boolean doAbort) Called when the session ID has been disposed of by a call to its dispose method.final BusyState
Gets the client busy state.getClientContextMenuReference
(UIContextMenu contextMenu) Gets the reference to use for a context menu.final DestinationServer[]
Gets the destination servers.final PropCnr
Gets the root property.final SessionMode
Gets the session mode.final SessionStatistics
Gets the statistics instance of the session.protected final SSLCommProps
Gets the SSL properties for this instance.final boolean
Checks if client is disposed of.final boolean
Gets the verbose flag.protected void
Called to perform verbose logging.protected void
onBusyChanged
(BusyState busy) Perform a client lock/unlock.final void
onCommClosed
(TransactionComm comm, int code, String reason) Called when the communication link is closed.final void
onCommClosing
(TransactionComm comm) Called when the communication link is closing.final void
Called when the communication link is connected.final void
onCommData
(TransactionComm comm, ReadTransaction trans, int size) Called when the communication link has received data.final void
onCommError
(TransactionComm comm, Throwable e) Called when the communication link is closed.final void
onCommHeartBeat
(TransactionComm comm, long duration) Called when the communication link has received data.final void
onCommTimeout
(TransactionComm comm, boolean isReadTimeout) Called when the communication link has timed out on a read or write operation.final void
Called to process an event due to a change in the some property in the UI root tree.protected void
onPaused
(long remainingTime) Called when the session enters pause mode.protected void
onPong
(long received, long duration) Pong transaction received.final void
Called when a RemoteEvent has been added and needs sending (along with all properties, etc).protected void
Called to inform a subclass that the session mode has changed.protected void
processDisplayMessage
(int severity, String head, String msg) Displays a message, or removes it.protected void
Processes "download resources": only for iiziApp, but only performed for iiziRun.protected void
Processes "install resource".protected void
Processes "reload page".final void
Connects to the last connected destination server.boolean
Requests a ping transaction.final void
setRequestedApp
(String appID, String language, String userID, String password) Sets the Application ID to run, the User ID and Password to use for the connection.protected final void
setSSLProperties
(SSLCommProps sslProps) Assigns the SSL properties.final void
setVerbose
(boolean isVerbose) Sets the verbose flag, also used for new clients.final void
setWriteCacheParams
(int minLength, int maxLength, int cacheCount) Sets the parameters for the write cache: minLength, maxLength, cacheCount.protected final void
Triggers a remote event to check checked for e.g.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.iizix.comm.session.ISessionStatistics
getLastConnectionTime, getProperties, getProperty, setProperty
Constructor Details
NonUIClient
public NonUIClient(ClientManager manager, String name, DestinationServer... destinations) throws IOException Constructor.- Parameters:
manager
- The client manager.name
- The name of the client, null for default.- Throws:
IOException
- If the worker cannot be created.
Method Details
isVerbose
public final boolean isVerbose()Gets the verbose flag.- Returns:
- The verbose output flag on console.
setVerbose
public final void setVerbose(boolean isVerbose) Sets the verbose flag, also used for new clients.By default, these settings are taken from the
ClientManager
instance when the client session is created.- Parameters:
isVerbose
- The verbose output flag on console.
isDisposed
public final boolean isDisposed()Checks if client is disposed of.- Returns:
- true if disposed of, false otherwise.
dispose
public final void dispose()Disposes of the client manager. Calling this method will cause all client connections to be disposed of.This method is the equivalent of calling
doDispose(false)
.doDispose
public final void doDispose(boolean doAbort) Called when the session ID has been disposed of by a call to its dispose method.- Specified by:
doDispose
in interfaceISessionTransMgr
- Parameters:
doAbort
- Abort-flag, if true pending transaction are not sent.
log
Called to perform verbose logging. This method can be overridden to e.g. store the output in separate files. Note that the method is called regardless of the verbose setting.- Parameters:
level
- The level of the event:{@link ILog#SEVERE}
to{@link ILog#FINEST}
.msg
- The message.params
- Optional parameters (could be aThrowable
, anArray
, aCollection
, etc.).
onPaused
protected void onPaused(long remainingTime) Called when the session enters pause mode. Subclasses can override this method to perform reconnection at some point in time...- Parameters:
remainingTime
- Time that remains to reconnect in milliseconds.
getSessionStatistics
Gets the statistics instance of the session.- Specified by:
getSessionStatistics
in interfaceISessionStatistics
- Returns:
- The SessionStatistics instance.
getDestinations
Gets the destination servers.- Returns:
- The destination servers.
addDestination
Adds a new destination server.- Parameters:
destination
- The destination.- Returns:
- true if added, false if destination was already present.
setWriteCacheParams
public final void setWriteCacheParams(int minLength, int maxLength, int cacheCount) Sets the parameters for the write cache: minLength, maxLength, cacheCount. This call must be done prior to connecting the client.By default, these settings are taken from the
ClientManager
instance when the client session is created.- Parameters:
minLength
- The minimum length for caching, 7 is the smallest value.maxLength
- The maximum length for caching, normally 80 or so (maximum 1024).cacheCount
- The count should normally be larger than 200 and smaller than 1000 (maximum 2048), if zero, cache is disabled.- Throws:
IllegalArgumentException
- If arguments are not valid.
setSSLProperties
Assigns the SSL properties.- Parameters:
sslProps
- The SSL properties, null for defaults or for plain connection.
getSSLProperties
Gets the SSL properties for this instance.- Returns:
- The SSL properties, or null for plain connections or defaults.
createSSLProps
The SSL properties, null for plain communication.- Parameters:
destination
- The destination server.- Returns:
- The initialized SSL communication properties.
configureSSLProps
Configures the SSL properties for the destination server.- Parameters:
sslProps
- The SSL properties to reconfigure.destination
- The destination server.- Throws:
IllegalArgumentException
- If the SocketCommProps cannot be found.
setRequestedApp
Sets the Application ID to run, the User ID and Password to use for the connection.- Parameters:
appID
- The application ID (leading and trailing whitespaces are removed).language
- The language code (or null for none). Must be a valid language code. Please note that the language code used for the client session is changed usingLocale.forLanguageTag(language).getDisplayLanguage().replace('_','-')
.userID
- The user ID (leading and trailing whitespaces are removed).password
- The password.- Throws:
NullPointerException
- If any parameter is null.IllegalArgumentException
- If any string is empty.
onSessionModeChanged
Called to inform a subclass that the session mode has changed.Subclasses can override this method to process it.
- Parameters:
mode
- The new mode.
getSessionMode
Gets the session mode.- Returns:
- The current mode.
onBusyChanged
Perform a client lock/unlock. When client is unlocked, the component focus is set.Subclasses can override this method to process it.
- Parameters:
busy
- The busy state, or null for none. Note that the busy state may contain a progress indicator value in percent (0-100%).
getBusyState
Gets the client busy state. This state can also contain a progress indicator value.- Returns:
- The busy state, or null if not busy.
processReloadPage
protected void processReloadPage()Processes "reload page".Subclasses can override this method to process it.
This would mean to reset and reload session entirely, skipping reconnect!
The current processing is to log a warning message: "Reload page requested from server".
connect
public final void connect() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, NoSuchProviderException, IOExceptionConnects to one of the destination servers in turn.- Throws:
KeyStoreException
- If no Provider supports a KeyStoreSpi implementation for the PKCS#12 type.NoSuchAlgorithmException
- If the algorithm used to check the integrity of the key store cannot be found.CertificateException
- If any of the certificates in the key store could not be loaded.UnrecoverableKeyException
- If the key cannot be recovered (e.g. the given password is wrong).NoSuchProviderException
- TLS provider not found.KeyManagementException
- Key management problems.IOException
- If there is an I/O or format problem with the key store data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException.IllegalStateException
- If no destination servers are not defined, or if disposed of, or the client manager is disposed of, or if the session already is connected.
reconnect
public final void reconnect() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException, NoSuchProviderException, IOExceptionConnects to the last connected destination server.- Throws:
KeyStoreException
- If no Provider supports a KeyStoreSpi implementation for the PKCS#12 type.NoSuchAlgorithmException
- If the algorithm used to check the integrity of the key store cannot be found.CertificateException
- If any of the certificates in the key store could not be loaded.UnrecoverableKeyException
- If the key cannot be recovered (e.g. the given password is wrong).NoSuchProviderException
- TLS provider not found.KeyManagementException
- Key management problems.IOException
- If there is an I/O or format problem with the key store data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException.IllegalStateException
- If reconnection is not possible because the session is disposed of or is not in reconnectable state.
onEvent
Called to process an event due to a change in the some property in the UI root tree.- Specified by:
onEvent
in interfaceEventListener
- Parameters:
event
- The event.
getRootProp
Gets the root property.- Returns:
- The root property, or
null
if not yet created.
triggerPostEventProcessing
protected final void triggerPostEventProcessing()Triggers a remote event to check checked for e.g. new data or queued events. This method is called fromonEvent(GEvent)
when the event is locally induced (i.e. not remote induced).onRemoteEventQueued
public final void onRemoteEventQueued()Called when a RemoteEvent has been added and needs sending (along with all properties, etc).- Specified by:
onRemoteEventQueued
in interfaceIPropMgrOwner
getClientContextMenuReference
Gets the reference to use for a context menu.- Specified by:
getClientContextMenuReference
in interfaceIPropMgrOwner
- Parameters:
contextMenu
- The context menu.- Returns:
- The reference to use, empty string for none (never null).
onCommConnected
Called when the communication link is connected.- Specified by:
onCommConnected
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.
onCommData
Called when the communication link has received data.- Specified by:
onCommData
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.trans
- The transaction received.size
- The size of the data received, as it may have been uncompressed.
onCommHeartBeat
Called when the communication link has received data.- Specified by:
onCommHeartBeat
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.duration
- The duration of the heart-beat in milliseconds.
onCommTimeout
Called when the communication link has timed out on a read or write operation.- Specified by:
onCommTimeout
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.isReadTimeout
- Flag indicating read timeout when true, false indicates write timeout.
onCommError
Called when the communication link is closed.- Specified by:
onCommError
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.e
- The exception.
onCommClosing
Called when the communication link is closing.- Specified by:
onCommClosing
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.
onCommClosed
Called when the communication link is closed.- Specified by:
onCommClosed
in interfaceTransactionCommListener
- Parameters:
comm
- The transaction communication instance.
requestPingPong
public boolean requestPingPong()Requests a ping transaction. When this is sent, the other party will reply with a pong transaction, and the start time will be used to measure the duration of the round-trip. Please note a potential logging overhead.- Returns:
- true for success, false for failure.
onPong
protected void onPong(long received, long duration) Pong transaction received.Subclasses can override this method to process it.
- Parameters:
received
- The time the transaction was received, milliseconds since the epoch.duration
- Milliseconds it took to send PING and receive back PONG.
processInstallResource
Processes "install resource".Subclasses can override this method to process it.
- Parameters:
trans
- The read transaction.
processDownloadResources
Processes "download resources": only for iiziApp, but only performed for iiziRun.Subclasses can override this method to process it.
- Parameters:
trans
- The read transaction.
processDisplayMessage
Displays a message, or removes it.Subclasses can override this method to process it.
- Parameters:
severity
- The message severity:- 0: INFORMATION
- 1: WARNING
- 2: ERROR
- 255: "None"
head
- Message heading, could be empty string.msg
- The message: if empty string, the message is removed on the client side.