Class 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidconnect()
      Connects to the WebSocket URI with or without SSL.
      voidconnect​(boolean noTimeouts)
      Connects to the WebSocket URI with or without SSL.
      booleandispose()
      Disposes of this instance and closes the communication session (if opened).
      java.lang.StringgetInfoString()
      Gets the info string of this session.
      SessionInfogetSessionInfo()
      Gets the session information instance.
      java.lang.StringgetState()
      Gets the state as a String.
      booleanisConnected()
      Checks if connected.
      booleanisDisconnected()
      Checks if disconnected.
      booleanisVerbose()
      Gets the verbose flag.
      intsendBinaryData​(int id, java.lang.String descr, byte[] data)
      Sends a block of binary data to the remote party.
      voidsetVerbose​(boolean isVerbose)
      Sets the verbose flag, also used for new clients.
      voidsetWriteCacheParams​(int minLength, int maxLength, int cacheCount)
      Sets the parameters for the write cache: minLength, maxLength, cacheCount.
      java.lang.StringtoString()
      The String representation as "host:port - description".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 class java.lang.Object
        Returns:
        Same as SessionInfo.getConnectionIDString(info).