Package tigase.server.cluster.strategy

# Class OnlineUsersCachingStrategy

java.lang.Object
tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
tigase.server.cluster.strategy.OnlineUsersCachingStrategy

All Implemented Interfaces:
  `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`, `tigase.licence.LicencedComponent`, `tigase.stats.StatisticHolder`, `tigase.sys.OnlineJidsReporter`

public class OnlineUsersCachingStrategy extends tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt> implements tigase.licence.LicencedComponent
Created: Jun 27, 2009 9:42:40 PM

Version:
  $Rev$
Author:
  Artur Hefczyc

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static tigase.licence.LicenceChecker`
  `licenceChecker`
  `static final String`
  `ONLINE_PRESENCE_CACHE_PROP_KEY`
  `static final String`
  `REQUEST_SYNCONLINE_CMD`
  `static final String`
  `RESPOND_SYNCONLINE_CMD`
  `static final String`
  `STRATEGY_STATS_CMD`
  `static final String`
  `USER_CONN_ID_CHANGED_CMD`
  `static final String`
  `USER_CONNECTED_CMD`
  `static final String`
  `USER_DISCONNECTED_CMD`
  `static final String`
  `USER_PRESENCE_CMD`

  ### Fields inherited from class tigase.cluster.strategy.DefaultClusteringStrategyAbstract

  `cluster, comp, eventBus, prefix, sm`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OnlineUsersCachingStrategy()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `containsJid(tigase.xmpp.jid.BareJID jid)`
  `void`
  `everyMinute()`
  `CacheContenerIfc`
  `getCacheContener()`
  Retrieves `CacheContener` instance used by this ACS instance.
  `tigase.cluster.api.ClusterControllerIfc`
  `getCluster()`
  Method returns implementation `ClusterControllerIfc` currently used.
  `tigase.xmpp.jid.JID[]`
  `getConnectionIdsForJid(tigase.xmpp.jid.BareJID jid)`
  `ConnectionRecordExt`
  `getConnectionRecord(tigase.xmpp.jid.JID jid)`
  `ConnectionRecordExt`
  `getConnectionRecordInstance()`
  `Set<ConnectionRecordExt>`
  `getConnectionRecords(tigase.xmpp.jid.BareJID bareJID)`
  `List<ConnectionRecordExt>`
  `getConnectionRecordsByCreationTime(tigase.xmpp.jid.BareJID bareJID)`
  `Map<String,Object>`
  `getDefaults(Map<String,Object> params)`
  `String`
  `getInfo()`
  `List<tigase.xmpp.jid.JID>`
  `getNodesForPacketForward(tigase.xmpp.jid.JID fromNode, Set<tigase.xmpp.jid.JID> visitedNodes, tigase.server.Packet packet)`
  `List<tigase.xmpp.jid.JID>`
  `getNodesForUserConnect(tigase.xmpp.jid.JID jid)`
  Method returns list of all nodes to which information about user connecting should be sent.
  `List<tigase.xmpp.jid.JID>`
  `getNodesForUserDisconnect(tigase.xmpp.jid.JID jid)`
  Method returns list of all nodes to which information about user disconnecting should be sent.
  `tigase.cluster.api.SessionManagerClusteredIfc`
  `getSM()`
  Method allows retrieval of a particular `SessionManagerClusteredIfc` implementation currently used.
  `void`
  `getStatistics(tigase.stats.StatisticsList list)`
  `void`
  `handleLocalPacket(tigase.server.Packet packet, tigase.xmpp.XMPPResourceConnection conn)`
  `void`
  `handleLocalResourceBind(tigase.xmpp.XMPPResourceConnection conn)`
  `void`
  `handleLocalUserChangedConnId(tigase.xmpp.jid.BareJID userId, tigase.xmpp.XMPPResourceConnection conn, tigase.xmpp.jid.JID oldConnId, tigase.xmpp.jid.JID newConnId)`
  `void`
  `handleLocalUserLogout(tigase.xmpp.jid.BareJID userId, tigase.xmpp.XMPPResourceConnection conn)`
  `boolean`
  `hasCompleteJidsInfo()`
  `void`
  `nodeConnected(tigase.xmpp.jid.JID node)`
  `void`
  `nodeDisconnected(tigase.xmpp.jid.JID node)`
  `protected Map<String,String>`
  `prepareConnectionParams(tigase.xmpp.XMPPResourceConnection conn)`
  A utility method used to prepare a Map of data with user session data before it can be sent over to another cluster node.
  `protected boolean`
  `presenceStatusUpdate(tigase.server.Packet packet)`
  Method evaluates whether given packet is a valid presence update, i.e. is of correct type and has proper addressing.
  `void`
  `presenceUpdate(tigase.xml.Element presence, ConnectionRecordExt rec)`
  If presence caching is enabled method updates given connection in the cache with the information about presence for the given connection.
  `protected void`
  `requestSync(tigase.xmpp.jid.JID node)`
  Send synchronization request to a given cluster node.
  `void`
  `setProperties(Map<String,Object> props)`
  `String`
  `toString()`
  `void`
  `userChangedConnId(tigase.xmpp.jid.BareJID userId, tigase.xmpp.jid.JID oldConnectionId, tigase.xmpp.jid.JID newConnectionId)`
  Method responsible for changing connection id for session for which connection id was changed, ie. due to stream resumption.
  `void`
  `userDisconnected(ConnectionRecordExt rec)`
  Method responsible for user disconnection events.
  `void`
  `usersConnected(ConnectionRecordExt... recs)`
  Method responsible for user connection events.

  ### Methods inherited from class tigase.cluster.strategy.DefaultClusteringStrategyAbstract

  `addCommandListener, containsJidLocally, containsJidLocally, everyHour, everySecond, fireEvent, getNodesConnected, getNodesForIqResponse, getStatistics, handleLocalPresenceSet, handleLocalUserLogin, isIqResponseToNode, isSuitableForForward, processPacket, sendToNextNode, setClusterController, setStatisticsPrefix, statisticExecutedIn`

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

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

- ## Field Details

  - ### ONLINE_PRESENCE_CACHE_PROP_KEY

    public static final String ONLINE_PRESENCE_CACHE_PROP_KEY
    See Also:
      - Constant Field Values

  - ### REQUEST_SYNCONLINE_CMD

    public static final String REQUEST_SYNCONLINE_CMD
    See Also:
      - Constant Field Values

  - ### RESPOND_SYNCONLINE_CMD

    public static final String RESPOND_SYNCONLINE_CMD
    See Also:
      - Constant Field Values

  - ### STRATEGY_STATS_CMD

    public static final String STRATEGY_STATS_CMD
    See Also:
      - Constant Field Values

  - ### USER_CONNECTED_CMD

    public static final String USER_CONNECTED_CMD
    See Also:
      - Constant Field Values

  - ### USER_CONN_ID_CHANGED_CMD

    public static final String USER_CONN_ID_CHANGED_CMD
    See Also:
      - Constant Field Values

  - ### USER_DISCONNECTED_CMD

    public static final String USER_DISCONNECTED_CMD
    See Also:
      - Constant Field Values

  - ### USER_PRESENCE_CMD

    public static final String USER_PRESENCE_CMD
    See Also:
      - Constant Field Values

  - ### licenceChecker

    protected static tigase.licence.LicenceChecker licenceChecker

- ## Constructor Details

  - ### OnlineUsersCachingStrategy

    public OnlineUsersCachingStrategy()

- ## Method Details

  - ### containsJid

    public boolean containsJid(tigase.xmpp.jid.BareJID jid)
    Specified by:
      `containsJid` in interface `tigase.sys.OnlineJidsReporter`
    Overrides:
      `containsJid` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### handleLocalPacket

    public void handleLocalPacket(tigase.server.Packet packet, tigase.xmpp.XMPPResourceConnection conn)
    Specified by:
      `handleLocalPacket` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `handleLocalPacket` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### handleLocalUserLogout

    public void handleLocalUserLogout(tigase.xmpp.jid.BareJID userId, tigase.xmpp.XMPPResourceConnection conn)
    Specified by:
      `handleLocalUserLogout` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `handleLocalUserLogout` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### handleLocalResourceBind

    public void handleLocalResourceBind(tigase.xmpp.XMPPResourceConnection conn)
    Specified by:
      `handleLocalResourceBind` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `handleLocalResourceBind` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### handleLocalUserChangedConnId

    public void handleLocalUserChangedConnId(tigase.xmpp.jid.BareJID userId, tigase.xmpp.XMPPResourceConnection conn, tigase.xmpp.jid.JID oldConnId, tigase.xmpp.jid.JID newConnId)
    Specified by:
      `handleLocalUserChangedConnId` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `handleLocalUserChangedConnId` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### nodeConnected

    public void nodeConnected(tigase.xmpp.jid.JID node)
    Specified by:
      `nodeConnected` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `nodeConnected` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### nodeDisconnected

    public void nodeDisconnected(tigase.xmpp.jid.JID node)
    Specified by:
      `nodeDisconnected` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `nodeDisconnected` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### presenceUpdate

    public void presenceUpdate(tigase.xml.Element presence, ConnectionRecordExt rec)
    If presence caching is enabled method updates given connection in the cache with the information about presence for the given connection.
    Parameters:
      `presence` - `Element` containing presence information
      `rec` - `ConnectionRecordExt` for which presence should be updated

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### userDisconnected

    public void userDisconnected(ConnectionRecordExt rec)
    Method responsible for user disconnection events. Calls `userDisconnected()` on particular cache implementation.
    Parameters:
      `rec` - `ConnectionRecordExt` for which presence should be updated

  - ### usersConnected

    public void usersConnected(ConnectionRecordExt... recs)
    Method responsible for user connection events. Calls `usersConnected()` on particular cache implementation.
    Parameters:
      `recs` - `ConnectionRecordExt` for which presence should be updated

  - ### userChangedConnId

    public void userChangedConnId(tigase.xmpp.jid.BareJID userId, tigase.xmpp.jid.JID oldConnectionId, tigase.xmpp.jid.JID newConnectionId)
    Method responsible for changing connection id for session for which connection id was changed, ie. due to stream resumption.
    Parameters:
      `userId` - - bare jid of user
      `oldConnectionId` - - connection id which was changed
      `newConnectionId` - - connection id which replaced old connection id

  - ### getCluster

    public tigase.cluster.api.ClusterControllerIfc getCluster()
    Method returns implementation `ClusterControllerIfc` currently used.
    Returns:
      a value of `ClusterControllerIfc`

  - ### getConnectionIdsForJid

    public tigase.xmpp.jid.JID[] getConnectionIdsForJid(tigase.xmpp.jid.BareJID jid)
    Specified by:
      `getConnectionIdsForJid` in interface `tigase.sys.OnlineJidsReporter`
    Overrides:
      `getConnectionIdsForJid` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getConnectionRecord

    public ConnectionRecordExt getConnectionRecord(tigase.xmpp.jid.JID jid)
    Specified by:
      `getConnectionRecord` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getConnectionRecord` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getConnectionRecordInstance

    public ConnectionRecordExt getConnectionRecordInstance()
    Specified by:
      `getConnectionRecordInstance` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getConnectionRecordInstance` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getConnectionRecords

    public Set<ConnectionRecordExt> getConnectionRecords(tigase.xmpp.jid.BareJID bareJID)
    Specified by:
      `getConnectionRecords` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getConnectionRecords` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getConnectionRecordsByCreationTime

    public List<ConnectionRecordExt> getConnectionRecordsByCreationTime(tigase.xmpp.jid.BareJID bareJID)
    Specified by:
      `getConnectionRecordsByCreationTime` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`

  - ### getDefaults

    public Map<String,Object> getDefaults(Map<String,Object> params)
    Specified by:
      `getDefaults` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getDefaults` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getInfo

    public String getInfo()
    Specified by:
      `getInfo` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getInfo` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getCacheContener

    public CacheContenerIfc getCacheContener()
    Retrieves `CacheContener` instance used by this ACS instance.
    Returns:
      `CacheContener` instance used by this ACS instance.

  - ### getNodesForPacketForward

    public List<tigase.xmpp.jid.JID> getNodesForPacketForward(tigase.xmpp.jid.JID fromNode, Set<tigase.xmpp.jid.JID> visitedNodes, tigase.server.Packet packet)
    Overrides:
      `getNodesForPacketForward` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getNodesForUserConnect

    public List<tigase.xmpp.jid.JID> getNodesForUserConnect(tigase.xmpp.jid.JID jid)
    Method returns list of all nodes to which information about user connecting should be sent.
    Parameters:
      `jid` - `JID` of user that has connected
    Returns:
      a `List` of all nodes `JID` to which information about user connecting should be sent.

  - ### getNodesForUserDisconnect

    public List<tigase.xmpp.jid.JID> getNodesForUserDisconnect(tigase.xmpp.jid.JID jid)
    Method returns list of all nodes to which information about user disconnecting should be sent.
    Parameters:
      `jid` - `JID` of user that has disconnected
    Returns:
      a `List` of all nod `JID` to which information about user disconnecting should be sent.

  - ### getSM

    public tigase.cluster.api.SessionManagerClusteredIfc getSM()
    Method allows retrieval of a particular `SessionManagerClusteredIfc` implementation currently used.
    Overrides:
      `getSM` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`
    Returns:
      `SessionManagerClusteredIfc` implementation currently used.

  - ### everyMinute

    public void everyMinute()
    Specified by:
      `everyMinute` in interface `tigase.stats.StatisticHolder`
    Overrides:
      `everyMinute` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### getStatistics

    public void getStatistics(tigase.stats.StatisticsList list)
    Specified by:
      `getStatistics` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `getStatistics` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### hasCompleteJidsInfo

    public boolean hasCompleteJidsInfo()
    Specified by:
      `hasCompleteJidsInfo` in interface `tigase.sys.OnlineJidsReporter`
    Overrides:
      `hasCompleteJidsInfo` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### setProperties

    public void setProperties(Map<String,Object> props)
    Specified by:
      `setProperties` in interface `tigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>`
    Overrides:
      `setProperties` in class `tigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>`

  - ### prepareConnectionParams

    protected Map<String,String> prepareConnectionParams(tigase.xmpp.XMPPResourceConnection conn) throws tigase.xmpp.NotAuthorizedException, tigase.xmpp.NoConnectionIdException
    A utility method used to prepare a Map of data with user session data before it can be sent over to another cluster node. This is supposed to contain all the user's session essential information which directly identify user's resource and network connection. This information allows to detect two different user's connection made for the same resource. This may happen if both connections are established to different nodes.
    Parameters:
      `conn` - is user's XMPPResourceConnection for which Map structure is prepare.

      a Map structure with all user's connection essential data.

    Returns:
      a value of `Map<String,String>`
    Throws:
      `tigase.xmpp.NotAuthorizedException`
      `tigase.xmpp.NoConnectionIdException`

  - ### presenceStatusUpdate

    protected boolean presenceStatusUpdate(tigase.server.Packet packet)
    Method evaluates whether given packet is a valid presence update, i.e. is of correct type and has proper addressing.
    Parameters:
      `packet` - to be validated
    Returns:
      `true` if the packet is a valid presence update, `false` otherwise

  - ### requestSync

    protected void requestSync(tigase.xmpp.jid.JID node)
    Send synchronization request to a given cluster node. In a response the remote node should return a list of JIDs for online users on this node.
    Parameters:
      `node` - is a JID of the target cluster node.