Package tigase.server

Class ConnectionManager<IO extends XMPPIOService<?>>

    • Field Detail

      • HT_TRAFFIC_THROTTLING_PROP_KEY

        public static final java.lang.String HT_TRAFFIC_THROTTLING_PROP_KEY
        See Also:
        Constant Field Values
      • HT_TRAFFIC_THROTTLING_PROP_VAL

        public static final java.lang.String HT_TRAFFIC_THROTTLING_PROP_VAL
        See Also:
        Constant Field Values
      • NET_BUFFER_HT_PROP_KEY

        public static final java.lang.String NET_BUFFER_HT_PROP_KEY
        See Also:
        Constant Field Values
      • NET_BUFFER_ST_PROP_KEY

        public static final java.lang.String NET_BUFFER_ST_PROP_KEY
        See Also:
        Constant Field Values
      • PORT_LOCAL_HOST_PROP_KEY

        public static final java.lang.String PORT_LOCAL_HOST_PROP_KEY
        See Also:
        Constant Field Values
      • ST_TRAFFIC_THROTTLING_PROP_KEY

        public static final java.lang.String ST_TRAFFIC_THROTTLING_PROP_KEY
        See Also:
        Constant Field Values
      • ST_TRAFFIC_THROTTLING_PROP_VAL

        public static final java.lang.String ST_TRAFFIC_THROTTLING_PROP_VAL
        See Also:
        Constant Field Values
      • TRAFFIC_THROTTLING_PROP_KEY

        public static final java.lang.String TRAFFIC_THROTTLING_PROP_KEY
        See Also:
        Constant Field Values
      • ELEMENTS_NUMBER_LIMIT_PROP_KEY

        public static final java.lang.String ELEMENTS_NUMBER_LIMIT_PROP_KEY
        Key name of the system property for configuration protection from system overload and DOS attack.
        See Also:
        Constant Field Values
      • LAST_MINUTE_BIN_LIMIT_PROP_VAL

        public static final long LAST_MINUTE_BIN_LIMIT_PROP_VAL
        See Also:
        Constant Field Values
      • LAST_MINUTE_PACKETS_LIMIT_PROP_VAL

        public static final long LAST_MINUTE_PACKETS_LIMIT_PROP_VAL
        See Also:
        Constant Field Values
      • MAX_INACTIVITY_TIME

        public static final java.lang.String MAX_INACTIVITY_TIME
        See Also:
        Constant Field Values
      • MAX_RECONNECTS_PROP_KEY

        public static final java.lang.String MAX_RECONNECTS_PROP_KEY
        See Also:
        Constant Field Values
      • NET_BUFFER_LIMIT_HT_PROP_VAL

        public static final int NET_BUFFER_LIMIT_HT_PROP_VAL
        See Also:
        Constant Field Values
      • NET_BUFFER_LIMIT_ST_PROP_VAL

        public static final int NET_BUFFER_LIMIT_ST_PROP_VAL
        See Also:
        Constant Field Values
      • PORT_CLASS_PROP_KEY

        public static final java.lang.String PORT_CLASS_PROP_KEY
        See Also:
        Constant Field Values
      • PORT_IFC_PROP_KEY

        public static final java.lang.String PORT_IFC_PROP_KEY
        See Also:
        Constant Field Values
      • PORT_LISTENING_DELAY_KEY

        public static final java.lang.String PORT_LISTENING_DELAY_KEY
        See Also:
        Constant Field Values
      • PORT_LISTENING_DELAY_DEF

        public static final boolean PORT_LISTENING_DELAY_DEF
        See Also:
        Constant Field Values
      • PORT_NEW_CONNECTIONS_THROTTLING_KEY

        public static final java.lang.String PORT_NEW_CONNECTIONS_THROTTLING_KEY
        See Also:
        Constant Field Values
      • PORT_REMOTE_HOST_PROP_KEY

        public static final java.lang.String PORT_REMOTE_HOST_PROP_KEY
        See Also:
        Constant Field Values
      • PORT_REMOTE_HOST_PROP_VAL

        public static final java.lang.String PORT_REMOTE_HOST_PROP_VAL
        See Also:
        Constant Field Values
      • PORT_SOCKET_PROP_KEY

        public static final java.lang.String PORT_SOCKET_PROP_KEY
        See Also:
        Constant Field Values
      • PORT_TYPE_PROP_KEY

        public static final java.lang.String PORT_TYPE_PROP_KEY
        See Also:
        Constant Field Values
      • TOTAL_BIN_LIMIT_PROP_VAL

        public static final long TOTAL_BIN_LIMIT_PROP_VAL
        See Also:
        Constant Field Values
      • TOTAL_PACKETS_LIMIT_PROP_VAL

        public static final long TOTAL_PACKETS_LIMIT_PROP_VAL
        See Also:
        Constant Field Values
      • WHITE_CHAR_ACK_PROP_KEY

        public static final java.lang.String WHITE_CHAR_ACK_PROP_KEY
        See Also:
        Constant Field Values
      • XMPP_ACK_PROP_KEY

        public static final java.lang.String XMPP_ACK_PROP_KEY
        See Also:
        Constant Field Values
      • WHITE_CHAR_ACK_PROP_VAL

        public static final boolean WHITE_CHAR_ACK_PROP_VAL
        See Also:
        Constant Field Values
      • WATCHDOG_TIMEOUT

        public static final java.lang.String WATCHDOG_TIMEOUT
        See Also:
        Constant Field Values
      • WATCHDOG_PING_TYPE_KEY

        public static final java.lang.String WATCHDOG_PING_TYPE_KEY
        See Also:
        Constant Field Values
      • pingElement

        protected static final Element pingElement
      • ELEMENTS_NUMBER_LIMIT_PROP_VAL

        public static int ELEMENTS_NUMBER_LIMIT_PROP_VAL
        Default value for the system property for configuration protection from system overload and DOS attack.
      • PORT_IFC_PROP_VAL

        @ConfigField(desc="Interfaces to listen on",
                     alias="ifc")
        public java.lang.String[] PORT_IFC_PROP_VAL
      • connectionDelay

        @ConfigField(desc="Delay before connection is established")
        protected long connectionDelay
      • delayPortListening

        protected boolean delayPortListening
      • elements_number_limit

        @ConfigField(desc="Limit of elements for single XMPP stanza",
                     alias="elements-number-limit")
        protected int elements_number_limit
        Protection from the system overload and DOS attack. We want to limit number of elements created within a single XMPP stanza.
      • kernel

        protected Kernel kernel
      • net_buffer

        @ConfigField(desc="Default size of a network buffer",
                     alias="net-buffer")
        protected int net_buffer
      • trafficThrottling

        @ConfigField(desc="Traffic throttling")
        protected java.lang.String trafficThrottling
      • watchdogDelay

        @ConfigField(desc="Watchdog delay",
                     alias="watchdog-delay")
        protected long watchdogDelay
      • watchdogTimeout

        @ConfigField(desc="Watchdog timeout",
                     alias="watchdog-timeout")
        protected long watchdogTimeout
      • serviceConnectedTimeout

        @ConfigField(desc="Service connection timeout",
                     alias="service-connected-timeout")
        protected int serviceConnectedTimeout
    • Constructor Detail

      • ConnectionManager

        public ConnectionManager()
    • Method Detail

      • enableServiceConnectedTimeout

        protected boolean enableServiceConnectedTimeout​(IO service)
      • checkTrafficLimits

        public boolean checkTrafficLimits​(IO serv)
      • everyMinute

        public void everyMinute()
        Description copied from class: AbstractMessageReceiver
        Utility method executed precisely every minute. A component can overwrite the method to put own code to be executed at the regular intervals of time.
        Note, no extensive calculations should happen in this method nor long lasting operations. It is essential that the method processing does not exceed 1 minute. The overriding method must call the the super method first and only then run own code.
        Overrides:
        everyMinute in class AbstractMessageReceiver
      • hashCodeForPacket

        public int hashCodeForPacket​(Packet packet)
        Description copied from class: AbstractMessageReceiver
        This method decides how incoming packets are distributed among processing threads. Different components needs different distribution to efficient use all threads and avoid packets re-ordering.
        If there are N processing threads, packets are distributed among threads using following code:
         int threadNo = Math.abs(hashCodeForPacket(packet) % N);
         

        For a PubSub component, for example, a better packets distribution would be based on the PubSub channel name, for SM a better distribution is based on the destination address, etc....
        Overrides:
        hashCodeForPacket in class AbstractMessageReceiver
        Parameters:
        packet - is a Packet which needs to be processed by some thread.
        Returns:
        a hash code generated for the input thread.
      • initBindings

        public void initBindings​(javax.script.Bindings binds)
        Description copied from class: BasicComponent
        Initialize a mapping of key/value pairs which can be used in scripts loaded by the server
        Overrides:
        initBindings in class BasicComponent
        Parameters:
        binds - A mapping of key/value pairs, all of whose keys are Strings.
      • initializationCompleted

        public void initializationCompleted()
        Description copied from interface: ServerComponent
        Method is called by MessageRouter when all the startup components of the server have been loaded and configured through setProperties(...) call. At this point the whole server should be loaded and functional, except initializations taking place in this routine.
        Specified by:
        initializationCompleted in interface ServerComponent
        Overrides:
        initializationCompleted in class BasicComponent
      • processingInThreads

        public int processingInThreads()
        Description copied from class: AbstractMessageReceiver
        Concurrency control method. Returns preferable number of threads set for this component.
        Overrides:
        processingInThreads in class AbstractMessageReceiver
        Returns:
        preferable number of threads set for this component.
      • processingOutThreads

        public int processingOutThreads()
        Description copied from class: AbstractMessageReceiver
        Concurrency control method. Returns preferable number of threads set for this component.
        Overrides:
        processingOutThreads in class AbstractMessageReceiver
        Returns:
        preferable number of threads set for this component.
      • processPacket

        public void processPacket​(Packet packet)
        Description copied from class: AbstractMessageReceiver
        This is the main Packet processing method. It is called concurrently from many threads so implementing it in thread save manner is essential. The method is called for each packet addressed to the component.
        Please note, the Packet instance may be processed by different parts of the server, different components or plugins at the same time. Therefore this is very important to tread the Packet instance as unmodifiable object.
        Processing in this method is asynchronous, therefore there is no result value. If there are some 'result' packets generated during processing, they should be passed back using addOutPacket(Packet) method.
        Specified by:
        processPacket in class AbstractMessageReceiver
        Parameters:
        packet - is an instance of the Packet class passed for processing.
      • processSocketData

        public abstract java.util.Queue<Packet> processSocketData​(IO serv)
      • processUndeliveredPacket

        public abstract boolean processUndeliveredPacket​(Packet packet,
                                                         java.lang.Long stamp,
                                                         java.lang.String errorMessage)
        Processes undelivered packets
        Parameters:
        stamp - - timestamp when packet was received to be written to XMPPIOService
      • reconnectionFailed

        public abstract void reconnectionFailed​(java.util.Map<java.lang.String,​java.lang.Object> port_props)
      • getDefPorts

        public java.util.HashSet<java.lang.Integer> getDefPorts()
      • register

        public void register​(Kernel kernel)
        Description copied from interface: RegistrarBean
        Method called when bean is being registered allowing developer to programatically register other beans.
        Specified by:
        register in interface RegistrarBean
        Parameters:
        kernel - - instance from local scope
      • unregister

        public void unregister​(Kernel kernel)
        Description copied from interface: RegistrarBean
        Method called while bean is being unregistered.
        Specified by:
        unregister in interface RegistrarBean
        Parameters:
        kernel - - instance from local scope
      • serviceConnected

        protected void serviceConnected​(IO service)
      • serviceStarted

        @TODO(note="Do something if service with the same unique ID is already started, possibly kill the old one...")
        public void serviceStarted​(IO service)
      • updateConnectionDetails

        public void updateConnectionDetails​(java.util.Map<java.lang.String,​java.lang.Object> port_props)
      • writePacketsToSocket

        public void writePacketsToSocket​(IO serv,
                                         java.util.Queue<Packet> packets)
      • writePacketToSocket

        public boolean writePacketToSocket​(IO ios,
                                           Packet p)
      • getStatistics

        public void getStatistics​(StatisticsList list)
        Description copied from class: AbstractMessageReceiver
        Method returns component statistics. Please note, the method can be called every second by the server monitoring system therefore no extensive or lengthy calculations are allowed. If there are some statistics requiring lengthy operations like database access they must have Level.FINEST assigned and must be put inside the level guard to prevent generating them by the system monitor. The system monitor does not collect FINEST statistics.
        Level guard code looks like the example below:
         if (list.checkLevel(Level.FINEST)) {
           // Some CPU intensive calculations or lengthy operations
           list.add(getName(), "Statistic description", stat_value, Level.FINEST);
         }
        
         
        This way you make sure your extensive operation is not executed every second by the monitoring system and does not affect the server performance.
        Specified by:
        getStatistics in interface StatisticsContainerIfc
        Overrides:
        getStatistics in class AbstractMessageReceiver
        Parameters:
        list - is a StatistcsList where all statistics are stored.
      • getXMPPIOService

        public IO getXMPPIOService​(java.lang.String serviceId)
      • getFlashCrossDomainPolicy

        public java.lang.String getFlashCrossDomainPolicy()
      • setFlashCrossDomainPolicyFile

        public void setFlashCrossDomainPolicyFile​(java.lang.String file)
      • getNet_buffer_limit

        public int getNet_buffer_limit()
      • setNet_buffer_limit

        public void setNet_buffer_limit​(int value)
      • setProcessors

        public void setProcessors​(XMPPIOProcessor[] processors)
      • getTrafficThrottling

        public java.lang.String getTrafficThrottling()
      • setTrafficThrottling

        public void setTrafficThrottling​(java.lang.String trafficThrottling)
      • connectWaitingTasks

        protected void connectWaitingTasks()
      • setupWatchdogThread

        protected void setupWatchdogThread()
      • addWaitingTask

        protected void addWaitingTask​(java.util.Map<java.lang.String,​java.lang.Object> conn)
      • checkHighThroughputProperty

        protected <T> void checkHighThroughputProperty​(java.lang.String ht_def_key,
                                                       T ht_dev_val,
                                                       java.lang.String st_def_key,
                                                       T st_def_val,
                                                       java.lang.String prop_key,
                                                       java.lang.Class<T> prop_val_class,
                                                       java.util.Map<java.lang.String,​java.lang.Object> params,
                                                       java.util.Map<java.lang.String,​java.lang.Object> props)
      • countIOServices

        protected int countIOServices()
        Returns number of active network connections (IOServices).
        Returns:
        number of active network connections (IOServices).
      • doForAllServices

        protected void doForAllServices​(ServiceChecker<IO> checker)
        Perform a given action defined by ServiceChecker for all active IOService objects (active network connections).
        Parameters:
        checker - is a ServiceChecker instance defining an action to perform for all IOService objects.
      • writePacketToSocket

        protected boolean writePacketToSocket​(Packet p)
      • writePacketToSocket

        protected boolean writePacketToSocket​(Packet p,
                                              java.lang.String serviceId)
      • writeRawData

        protected void writeRawData​(IO ios,
                                    java.lang.String data)
      • getDefPlainPorts

        protected int[] getDefPlainPorts()
      • getDefSSLPorts

        protected int[] getDefSSLPorts()
      • getDefTrafficThrottling

        protected java.lang.String getDefTrafficThrottling()
      • getMaxInactiveTime

        protected abstract long getMaxInactiveTime()
      • getParamsForPort

        protected java.util.Map<java.lang.String,​java.lang.Object> getParamsForPort​(int port)
      • getServiceId

        protected java.lang.String getServiceId​(Packet packet)
      • getServiceId

        protected java.lang.String getServiceId​(JID jid)
      • getUniqueId

        protected java.lang.String getUniqueId​(IO serv)
      • getXMPPIOService

        protected IO getXMPPIOService​(Packet p)
      • getXMPPIOServiceInstance

        protected abstract IO getXMPPIOServiceInstance()
      • isHighThroughput

        protected boolean isHighThroughput()
      • socketAccepted

        protected void socketAccepted​(IO serv,
                                      SocketType type)
      • startService

        protected tigase.server.ConnectionManager.ConnectionListenerImpl startService​(java.util.Map<java.lang.String,​java.lang.Object> port_props)