Class ClientManager


  • public class ClientManager
    extends java.lang.Object
    Class to manage clients connections.
    Author:
    Christopher Mindus
    • Method Detail

      • getInstance

        public static ClientManager getInstance()
        Gets the client manager singleton instance.
        Returns:
        The client manager instance.
      • getCurrentNonUIClient

        public static NonUIClient getCurrentNonUIClient()
        Gets the NonUIClient instance or its subclass from the current thread.
        Returns:
        The NonUIClient instance or null if thread does not belong to the any client instance.
      • getPropFactory

        public PropFactory getPropFactory()
        Gets the property factory.
        Returns:
        The PropFactory instance initialized as CLIENT.
      • 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 creating a new client.
        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.
      • getCacheMinLength

        public int getCacheMinLength()
        Gets the minimum length for string caching.
        Returns:
        The minimum length.
      • getCacheMaxLength

        public int getCacheMaxLength()
        Gets the maximum length for string caching.
        Returns:
        The maximum length.
      • getCacheCount

        public int getCacheCount()
        Gets the count for the write cache.
        Returns:
        The count of cached strings in the write cache.
      • setMaxTransactionQueueSize

        public void setMaxTransactionQueueSize​(int size)
        Sets the maximum queued transaction to keep. This method must be called prior to creating a client.
        Parameters:
        size - The size, default is 10.
        Throws:
        java.lang.IllegalArgumentException - If less than 2 and more than 100.
      • getMaxTransactionQueueSize

        public int getMaxTransactionQueueSize()
        Gets the maximum queued transactions to keep.
        Returns:
        The size, range between 2 and 100, default is 10.
      • setRequestedApp

        public void setRequestedApp​(java.lang.String appID,
                                    java.lang.String language,
                                    java.lang.String userID,
                                    java.lang.String password)
        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 using Locale.forLanguageTag(language).getDisplayLanguage().replace('_','-').
        userID - The user ID (leading and trailing whitespaces are removed).
        password - The password.
        Throws:
        java.lang.NullPointerException - If any parameter is null.
        java.lang.IllegalArgumentException - If any string is empty.
      • createDefaultClient

        public NonUIClient createDefaultClient​(DestinationServer... destinations)
                                        throws java.io.IOException
        Creates a new DefaultClient.
        Parameters:
        destinations - The destinations.
        Throws:
        java.io.IOException - If the worker cannot be created.
        java.lang.IllegalStateException - If client manager is disposed of.
      • getClients

        public NonUIClient[] getClients()
        Gets all the clients.
        Returns:
        The clients array.
      • isDisposed

        public boolean isDisposed()
        Checks if client manager is disposed of.
        Returns:
        true if disposed of, false otherwise.
      • dispose

        public int dispose​(long timeout)
        Disposes of the client manager. Calling this method will cause all client connections to be disposed of.
        Parameters:
        timeout - The maximum time to wait for clients to complete, -1L for indefinite timeout. The timeout wait can be interrupted if you call the thread's interrupt() method.
        Returns:
        zero for success, otherwise the remaining disposed but still not terminated client sessions. If called when already disposed of, -1 is returned.