Package com.iizix.comm.client
Class ClientInstance
- java.lang.Object
- com.iizix.comm.client.ClientInstance
public class ClientInstance extends java.lang.Object
The client class for communication with a remote server over (secured) WebSocket using the IIZI reconnectable transactional processing.- Author:
- Christopher Mindus
Constructor Summary
Constructors Constructor Description ClientInstance(PropFactory propFactory, java.lang.String host, int port, java.lang.String wsURI, SSLCommProps sslProps, boolean isVerbose, IClientInstanceListener clientListener)
Constructor.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
Connects to the WebSocket URI with or without SSL.void
connect(boolean noTimeouts)
Connects to the WebSocket URI with or without SSL.boolean
dispose()
Disposes of this instance and closes the communication session (if opened).java.lang.String
getInfoString()
Gets the info string of this session.SessionInfo
getSessionInfo()
Gets the session information instance.java.lang.String
getState()
Gets the state as a String.boolean
isConnected()
Checks if connected.boolean
isDisconnected()
Checks if disconnected.boolean
isVerbose()
Gets the verbose flag.int
sendBinaryData(int id, java.lang.String descr, byte[] data)
Sends a block of binary data to the remote party.void
setVerbose(boolean isVerbose)
Sets the verbose flag, also used for new clients.void
setWriteCacheParams(int minLength, int maxLength, int cacheCount)
Sets the parameters for the write cache: minLength, maxLength, cacheCount.java.lang.String
toString()
The String representation as "host:port - description".
Constructor Detail
ClientInstance
public ClientInstance(PropFactory propFactory, java.lang.String host, int port, java.lang.String wsURI, SSLCommProps sslProps, boolean isVerbose, IClientInstanceListener clientListener) throws java.io.IOException, java.security.UnrecoverableKeyException, java.security.KeyManagementException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.security.KeyStoreException, java.security.NoSuchProviderException
Constructor.- Parameters:
propFactory
- The property factory.host
- The host name or address.port
- The port number.wsURI
- The relative WebSocket URI starting with "/" (normally ending with .ws [unsecure] or .wss [secure]).sslProps
- The SSL properties, null for not secure.isVerbose
- The verbose flag.clientListener
- The client listener.- Throws:
java.io.IOException
- For I/O errors.java.security.NoSuchProviderException
java.security.KeyStoreException
java.security.cert.CertificateException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
java.security.UnrecoverableKeyException
Method Detail
isVerbose
public boolean isVerbose()
Gets the verbose flag.- Returns:
- The verbose output flag on console.
setVerbose
public void setVerbose(boolean isVerbose)
Sets the verbose flag, also used for new clients.- Parameters:
isVerbose
- The verbose output flag on console.
setWriteCacheParams
public void setWriteCacheParams(int minLength, int maxLength, int cacheCount)
Sets the parameters for the write cache: minLength, maxLength, cacheCount. This call must be done before connecting.- 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 (range is 10 to 2048), if zero, cache is disabled.- Throws:
java.lang.IllegalArgumentException
- If arguments are not valid.
isConnected
public boolean isConnected()
Checks if connected.- Returns:
- true if connected, false otherwise.
isDisconnected
public boolean isDisconnected()
Checks if disconnected.- Returns:
- true if disconnected, false otherwise.
getState
public java.lang.String getState()
Gets the state as a String.- Returns:
- "Connecting", "Connected", "Disconnecting" or "Disconnected".
connect
public void connect() throws java.io.IOException
Connects to the WebSocket URI with or without SSL.- Throws:
java.lang.IllegalStateException
- If already connected or connecting.java.io.IOException
- For communication problems.
connect
public void connect(boolean noTimeouts) throws java.io.IOException
Connects to the WebSocket URI with or without SSL.- Parameters:
noTimeouts
- Connect with debug = no timeouts! This way we can set breakpoints in Eclipse.- Throws:
java.lang.IllegalStateException
- If already connected or connecting.java.io.IOException
- For communication problems.
dispose
public boolean dispose()
Disposes of this instance and closes the communication session (if opened). The web socket connection is closed with the close code "1000" = "Normal close". This root property is disposed of.- Returns:
- true for success, false if already disposed of.
sendBinaryData
public int sendBinaryData(int id, java.lang.String descr, byte[] data) throws java.io.IOException
Sends a block of binary data to the remote party.- Parameters:
id
- The ID of the reply local ID for error or success reply.descr
- Short description of the data.data
- The data.- Returns:
- The byte size sent.
- Throws:
java.io.EOFException
- If connection is closed.java.io.IOException
- For send failures.
getSessionInfo
public SessionInfo getSessionInfo()
Gets the session information instance.- Returns:
- The SessionInfo.
getInfoString
public java.lang.String getInfoString()
Gets the info string of this session.- Returns:
- Same as
SessionInfo.getConnectionIDString(info)
.
toString
public java.lang.String toString()
The String representation as "host:port - description".- Overrides:
toString
in classjava.lang.Object
- Returns:
- Same as
SessionInfo.getConnectionIDString(info)
.