tigase.cluster.strategy

## Class DefaultClusteringStrategyAbstract<E extends ConnectionRecordIfc>

- java.lang.Object
- - tigase.cluster.strategy.DefaultClusteringStrategyAbstract<E>

- Type Parameters:
    `E` -
  All Implemented Interfaces:
    ClusteringStrategyIfc<E>, OnlineJidsReporter
  Direct Known Subclasses:
    DefaultClusteringStrategy

      public class DefaultClusteringStrategyAbstract<E extends ConnectionRecordIfc>
      extends Object
      implements ClusteringStrategyIfc<E>

  Created: May 13, 2009 9:53:44 AM
  Version:
    $Rev$
  Author:
    Artur Hefczyc

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected CopyOnWriteArrayList<tigase.xmpp.JID>` | `cl_nodes_list` Field description
    `protected ClusterControllerIfc` | `cluster` Field description
    `protected SessionManagerClusteredIfc` | `sm` Field description

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultClusteringStrategyAbstract()` Constructs ...

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCommandListener(CommandListener cmd)` Method description
    `boolean` | `containsJid(tigase.xmpp.BareJID jid)` Checks whether there is an online session for the given user BareJID.
    `List<tigase.xmpp.JID>` | `getAllNodes()` The method returns all cluster nodes currently connected to the cluster.
    `tigase.xmpp.JID[]` | `getConnectionIdsForJid(tigase.xmpp.BareJID jid)` Retrieve all connection IDs (CIDs) for the given user.
    `E` | `getConnectionRecord(tigase.xmpp.JID jid)` Returns a ConnectionRecord object associated with this user's full JID if it exists in the cache or null if it does not.
    `E` | `getConnectionRecordInstance()` Method description
    `Set<E>` | `getConnectionRecords(tigase.xmpp.BareJID bareJID)` Returns a set with all ConnectionRecords found in the cache for a given user ID, that is BareJID.
    `Map<String,Object>` | `getDefaults(Map<String,Object> params)` This method is used for configuration purpose.
    `String` | `getInfo()` Method description
    `Object` | `getInternalCacheData()` Deprecated.
    `List<tigase.xmpp.JID>` | `getNodesForPacketForward(tigase.xmpp.JID fromNode, Set<tigase.xmpp.JID> visitedNodes, Packet packet)` Method description
    `void` | `getStatistics(StatisticsList list)` Add the strategy statistics to the List.
    `void` | `handleLocalPacket(Packet packet, XMPPResourceConnection conn)` Method description
    `void` | `handleLocalPresenceSet(XMPPResourceConnection conn)` Method description
    `void` | `handleLocalResourceBind(XMPPResourceConnection conn)` Method description
    `void` | `handleLocalUserLogin(tigase.xmpp.BareJID userId, XMPPResourceConnection conn)` Method description
    `void` | `handleLocalUserLogout(tigase.xmpp.BareJID userId, XMPPResourceConnection conn)` Method description
    `boolean` | `hasCompleteJidsInfo()` Indicates whether given `OnlineJidsReporter` contains complete information about connected JIDs.
    `protected boolean` | `isSuitableForForward(Packet packet)` Method description
    `void` | `nodeConnected(tigase.xmpp.JID jid)` This is a handler method which is called when a new node connects to the cluster.
    `void` | `nodeDisconnected(tigase.xmpp.JID jid)` This is a handler method which is called when a node disconnects from the cluster.
    `boolean` | `processPacket(Packet packet, XMPPResourceConnection conn)` Method description
    `boolean` | `sendToNextNode(tigase.xmpp.JID fromNode, Set<tigase.xmpp.JID> visitedNodes, Map<String,String> data, Packet packet)` Method attempts to send the packet to the next cluster node.
    `void` | `setClusterController(ClusterControllerIfc clComp)` Method description
    `void` | `setProperties(Map<String,Object> props)` Method used to pass configuration parameters to the class.
    `void` | `setSessionManagerHandler(SessionManagerClusteredIfc sm)` The method allows to obtain SessionManagerHandler object by the strategy.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### cluster

          protected ClusterControllerIfc cluster

      Field description

    - #### sm

          protected SessionManagerClusteredIfc sm

      Field description

    - #### cl_nodes_list

          protected CopyOnWriteArrayList<tigase.xmpp.JID> cl_nodes_list

      Field description

  - ### Constructor Detail

    - #### DefaultClusteringStrategyAbstract

          public DefaultClusteringStrategyAbstract()

      Constructs ...

  - ### Method Detail

    - #### addCommandListener

          public final void addCommandListener(CommandListener cmd)

      Method description
      Parameters:
        `cmd` -

    - #### containsJid

          public boolean containsJid(tigase.xmpp.BareJID jid)

      Description copied from interface: `OnlineJidsReporter`
      Checks whether there is an online session for the given user BareJID.
      Specified by:
        `containsJid` in interface `OnlineJidsReporter`
      Parameters:
        `jid` - id of the user which we want to check.
      Returns:
        `true` if there is user session for the given JID, `false` otherwise.

    - #### handleLocalPacket

          public void handleLocalPacket(Packet packet,
                               XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `handleLocalPacket` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### handleLocalPresenceSet

          public void handleLocalPresenceSet(XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `handleLocalPresenceSet` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### handleLocalResourceBind

          public void handleLocalResourceBind(XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `handleLocalResourceBind` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### handleLocalUserLogin

          public void handleLocalUserLogin(tigase.xmpp.BareJID userId,
                                  XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `handleLocalUserLogin` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### handleLocalUserLogout

          public void handleLocalUserLogout(tigase.xmpp.BareJID userId,
                                   XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `handleLocalUserLogout` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### nodeConnected

          public void nodeConnected(tigase.xmpp.JID jid)

      Description copied from interface: `ClusteringStrategyIfc`
      This is a handler method which is called when a new node connects to the cluster.
      Specified by:
        `nodeConnected` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `jid` - is a cluster node id.

    - #### nodeDisconnected

          public void nodeDisconnected(tigase.xmpp.JID jid)

      Description copied from interface: `ClusteringStrategyIfc`
      This is a handler method which is called when a node disconnects from the cluster.
      Specified by:
        `nodeDisconnected` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `jid` - is a cluster node id.

    - #### processPacket

          public boolean processPacket(Packet packet,
                              XMPPResourceConnection conn)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `processPacket` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Returns:
        a value of `boolean`

    - #### sendToNextNode

          public boolean sendToNextNode(tigase.xmpp.JID fromNode,
                               Set<tigase.xmpp.JID> visitedNodes,
                               Map<String,String> data,
                               Packet packet)

      Method attempts to send the packet to the next cluster node. Returns true on successful attempt and false on failure. The true result does not mean that the packet has been delivered though. Only that it was sent. The send attempt may fail if there is no more cluster nodes to send the packet or if the clustering strategy logic decided that the packet does not have to be sent.
      Parameters:
        `fromNode` -
        `data` -
        `packet` - to be sent to a next cluster node
        `visitedNodes` - a list of nodes already visited by the packet.
      Returns:
        true if the packet was sent to next cluster node and false otherwise.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getAllNodes

          public List<tigase.xmpp.JID> getAllNodes()

      Description copied from interface: `ClusteringStrategyIfc`
      The method returns all cluster nodes currently connected to the cluster.
      Specified by:
        `getAllNodes` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Returns:
        List of all cluster nodes currently connected to the cluster.

    - #### getConnectionIdsForJid

          public tigase.xmpp.JID[] getConnectionIdsForJid(tigase.xmpp.BareJID jid)

      Description copied from interface: `OnlineJidsReporter`
      Retrieve all connection IDs (CIDs) for the given user.
      Specified by:
        `getConnectionIdsForJid` in interface `OnlineJidsReporter`
      Parameters:
        `jid` - id of the user for which we want to retrieve the list.
      Returns:
        an array of `JID` containing all Connection IDs (CIDs) for the given user.

    - #### getConnectionRecord

          public E getConnectionRecord(tigase.xmpp.JID jid)

      Description copied from interface: `ClusteringStrategyIfc`
      Returns a ConnectionRecord object associated with this user's full JID if it exists in the cache or null if it does not. All parts of the user's JID are checked and ConnectionRecord is returned only if there is a match for all parts.
      Specified by:
        `getConnectionRecord` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `jid` - is an instance of the user's full JID.
      Returns:
        ConnectionRecord instance associated with given user's JID or null if there is no ConnectionRecord in the cache.

    - #### getConnectionRecordInstance

          public E getConnectionRecordInstance()

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `getConnectionRecordInstance` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Returns:
        a value of `E`

    - #### getConnectionRecords

          public Set<E> getConnectionRecords(tigase.xmpp.BareJID bareJID)

      Description copied from interface: `ClusteringStrategyIfc`
      Returns a set with all ConnectionRecords found in the cache for a given user ID, that is BareJID. In other words all user's resources/connectionIDs found in the cache associated with user's account.
      Specified by:
        `getConnectionRecords` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `bareJID` - is an instance of the user's BareJID, that is account ID.
      Returns:
        a Set instance with all ConnectionRecords found for a given BareJID. Note, the result may be null or it maybe an empty Set or non-empty set.

    - #### getDefaults

          public Map<String,Object> getDefaults(Map<String,Object> params)

      Description copied from interface: `ClusteringStrategyIfc`
      This method is used for configuration purpose. Following the convention used in the Tigase project this method is supposed to provide configuration defaults. All parameters which exist in configuration file overwrite corresponding default parameters. If some parameters are missing in configuration file defaults are used then. A compiled set of parameters is then passed to `setProperties` method.
      Specified by:
        `getDefaults` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `params` - a `Map` with properties loaded from init.properties file which should be used for generating defaults.
      Returns:
        a `Map` with all the class default configuration parameters.

    - #### getInfo

          public String getInfo()

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `getInfo` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Returns:
        a value of `String`

    - #### getInternalCacheData

          @Deprecated
          public Object getInternalCacheData()

      Deprecated.
      Description copied from interface: `ClusteringStrategyIfc`
      Note! This is not for a common use method. This is for debugging and diagnostic purposes only and maybe removed or changed at any time in the future. It returns a content of an internal cache from the strategy. Regardless of the cache data organization inside the strategy, it is returned here in a common format. It may be a copy or a direct reference to internal data. Therefore this is unmodifiable instance of the cache. Generating results of this structure may be a costly operation, therefore it must not be called frequently.
      Specified by:
        `getInternalCacheData` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Returns:
        an Object with content of an internal cache data.

    - #### getNodesForPacketForward

          public List<tigase.xmpp.JID> getNodesForPacketForward(tigase.xmpp.JID fromNode,
                                                       Set<tigase.xmpp.JID> visitedNodes,
                                                       Packet packet)

      Method description
      Parameters:
        `fromNode` -
        `visitedNodes` -
        `packet` -
      Returns:
        a value of `List`

    - #### getStatistics

          public void getStatistics(StatisticsList list)

      Description copied from interface: `ClusteringStrategyIfc`
      Add the strategy statistics to the List.
      Specified by:
        `getStatistics` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### hasCompleteJidsInfo

          public boolean hasCompleteJidsInfo()

      Description copied from interface: `OnlineJidsReporter`
      Indicates whether given `OnlineJidsReporter` contains complete information about connected JIDs.
      Specified by:
        `hasCompleteJidsInfo` in interface `OnlineJidsReporter`
      Returns:
        `true` if the informations are complete, `false` otherwise.

    - #### setClusterController

          public void setClusterController(ClusterControllerIfc clComp)

      Description copied from interface: `ClusteringStrategyIfc`
      Method description
      Specified by:
        `setClusterController` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`

    - #### setProperties

          public void setProperties(Map<String,Object> props)

      Description copied from interface: `ClusteringStrategyIfc`
      Method used to pass configuration parameters to the class. Parameters are stored in `Map` which contains compiles set of defaults overwritten by parameters loaded from configuration file. If he implementation took a good care of providing defaults for all parameters no parameter should be missing.
      Specified by:
        `setProperties` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `props` - a `Map` with all configuration parameters for the class.

    - #### setSessionManagerHandler

          public void setSessionManagerHandler(SessionManagerClusteredIfc sm)

      Description copied from interface: `ClusteringStrategyIfc`
      The method allows to obtain SessionManagerHandler object by the strategy. The object is mainly used to access local VHosts configuration and check the ID of the local session manager.
      Specified by:
        `setSessionManagerHandler` in interface `ClusteringStrategyIfc<E extends ConnectionRecordIfc>`
      Parameters:
        `sm` - is an instance of the SessionManagerHandler class.

    - #### isSuitableForForward

          protected boolean isSuitableForForward(Packet packet)

      Method description
      Parameters:
        `packet` -
      Returns:
        a value of `boolean`

Copyright © 2014 "Tigase, Inc.". All rights reserved.