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 java.lang.String
ONLINE_PRESENCE_CACHE_PROP_KEY
static java.lang.String
REQUEST_SYNCONLINE_CMD
static java.lang.String
RESPOND_SYNCONLINE_CMD
static java.lang.String
STRATEGY_STATS_CMD
static java.lang.String
USER_CONN_ID_CHANGED_CMD
static java.lang.String
USER_CONNECTED_CMD
static java.lang.String
USER_DISCONNECTED_CMD
static java.lang.String
USER_PRESENCE_CMD
-
Constructor Summary
Constructors Constructor Description OnlineUsersCachingStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsJid(tigase.xmpp.jid.BareJID jid)
void
everyMinute()
CacheContenerIfc
getCacheContener()
RetrievesCacheContener
instance used by this ACS instance.tigase.cluster.api.ClusterControllerIfc
getCluster()
Method returns implementationClusterControllerIfc
currently used.tigase.xmpp.jid.JID[]
getConnectionIdsForJid(tigase.xmpp.jid.BareJID jid)
ConnectionRecordExt
getConnectionRecord(tigase.xmpp.jid.JID jid)
ConnectionRecordExt
getConnectionRecordInstance()
java.util.Set<ConnectionRecordExt>
getConnectionRecords(tigase.xmpp.jid.BareJID bareJID)
java.util.List<ConnectionRecordExt>
getConnectionRecordsByCreationTime(tigase.xmpp.jid.BareJID bareJID)
java.util.Map<java.lang.String,java.lang.Object>
getDefaults(java.util.Map<java.lang.String,java.lang.Object> params)
java.lang.String
getInfo()
java.util.List<tigase.xmpp.jid.JID>
getNodesForPacketForward(tigase.xmpp.jid.JID fromNode, java.util.Set<tigase.xmpp.jid.JID> visitedNodes, tigase.server.Packet packet)
java.util.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.java.util.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 particularSessionManagerClusteredIfc
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 java.util.Map<java.lang.String,java.lang.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(java.util.Map<java.lang.String,java.lang.Object> props)
java.lang.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
-
-
-
-
Field Detail
-
ONLINE_PRESENCE_CACHE_PROP_KEY
public static final java.lang.String ONLINE_PRESENCE_CACHE_PROP_KEY
- See Also:
- Constant Field Values
-
REQUEST_SYNCONLINE_CMD
public static final java.lang.String REQUEST_SYNCONLINE_CMD
- See Also:
- Constant Field Values
-
RESPOND_SYNCONLINE_CMD
public static final java.lang.String RESPOND_SYNCONLINE_CMD
- See Also:
- Constant Field Values
-
STRATEGY_STATS_CMD
public static final java.lang.String STRATEGY_STATS_CMD
- See Also:
- Constant Field Values
-
USER_CONNECTED_CMD
public static final java.lang.String USER_CONNECTED_CMD
- See Also:
- Constant Field Values
-
USER_CONN_ID_CHANGED_CMD
public static final java.lang.String USER_CONN_ID_CHANGED_CMD
- See Also:
- Constant Field Values
-
USER_DISCONNECTED_CMD
public static final java.lang.String USER_DISCONNECTED_CMD
- See Also:
- Constant Field Values
-
USER_PRESENCE_CMD
public static final java.lang.String USER_PRESENCE_CMD
- See Also:
- Constant Field Values
-
licenceChecker
protected static tigase.licence.LicenceChecker licenceChecker
-
-
Method Detail
-
containsJid
public boolean containsJid(tigase.xmpp.jid.BareJID jid)
- Specified by:
containsJid
in interfacetigase.sys.OnlineJidsReporter
- Overrides:
containsJid
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
handleLocalPacket
public void handleLocalPacket(tigase.server.Packet packet, tigase.xmpp.XMPPResourceConnection conn)
- Specified by:
handleLocalPacket
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
handleLocalPacket
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
handleLocalUserLogout
public void handleLocalUserLogout(tigase.xmpp.jid.BareJID userId, tigase.xmpp.XMPPResourceConnection conn)
- Specified by:
handleLocalUserLogout
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
handleLocalUserLogout
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
handleLocalResourceBind
public void handleLocalResourceBind(tigase.xmpp.XMPPResourceConnection conn)
- Specified by:
handleLocalResourceBind
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
handleLocalResourceBind
in classtigase.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 interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
handleLocalUserChangedConnId
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
nodeConnected
public void nodeConnected(tigase.xmpp.jid.JID node)
- Specified by:
nodeConnected
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
nodeConnected
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
nodeDisconnected
public void nodeDisconnected(tigase.xmpp.jid.JID node)
- Specified by:
nodeDisconnected
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
nodeDisconnected
in classtigase.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 informationrec
-ConnectionRecordExt
for which presence should be updated
-
toString
public java.lang.String toString()
- Overrides:
toString
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
userDisconnected
public void userDisconnected(ConnectionRecordExt rec)
Method responsible for user disconnection events. CallsuserDisconnected()
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. CallsusersConnected()
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 useroldConnectionId
- - connection id which was changednewConnectionId
- - connection id which replaced old connection id
-
getCluster
public tigase.cluster.api.ClusterControllerIfc getCluster()
Method returns implementationClusterControllerIfc
currently used.- Returns:
- a value of
ClusterControllerIfc
-
getConnectionIdsForJid
public tigase.xmpp.jid.JID[] getConnectionIdsForJid(tigase.xmpp.jid.BareJID jid)
- Specified by:
getConnectionIdsForJid
in interfacetigase.sys.OnlineJidsReporter
- Overrides:
getConnectionIdsForJid
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getConnectionRecord
public ConnectionRecordExt getConnectionRecord(tigase.xmpp.jid.JID jid)
- Specified by:
getConnectionRecord
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getConnectionRecord
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getConnectionRecordInstance
public ConnectionRecordExt getConnectionRecordInstance()
- Specified by:
getConnectionRecordInstance
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getConnectionRecordInstance
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getConnectionRecords
public java.util.Set<ConnectionRecordExt> getConnectionRecords(tigase.xmpp.jid.BareJID bareJID)
- Specified by:
getConnectionRecords
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getConnectionRecords
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getConnectionRecordsByCreationTime
public java.util.List<ConnectionRecordExt> getConnectionRecordsByCreationTime(tigase.xmpp.jid.BareJID bareJID)
- Specified by:
getConnectionRecordsByCreationTime
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
-
getDefaults
public java.util.Map<java.lang.String,java.lang.Object> getDefaults(java.util.Map<java.lang.String,java.lang.Object> params)
- Specified by:
getDefaults
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getDefaults
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getInfo
public java.lang.String getInfo()
- Specified by:
getInfo
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getInfo
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getCacheContener
public CacheContenerIfc getCacheContener()
RetrievesCacheContener
instance used by this ACS instance.- Returns:
CacheContener
instance used by this ACS instance.
-
getNodesForPacketForward
public java.util.List<tigase.xmpp.jid.JID> getNodesForPacketForward(tigase.xmpp.jid.JID fromNode, java.util.Set<tigase.xmpp.jid.JID> visitedNodes, tigase.server.Packet packet)
- Overrides:
getNodesForPacketForward
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getNodesForUserConnect
public java.util.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 nodesJID
to which information about user connecting should be sent.
-
getNodesForUserDisconnect
public java.util.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 nodJID
to which information about user disconnecting should be sent.
-
getSM
public tigase.cluster.api.SessionManagerClusteredIfc getSM()
Method allows retrieval of a particularSessionManagerClusteredIfc
implementation currently used.- Overrides:
getSM
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
- Returns:
SessionManagerClusteredIfc
implementation currently used.
-
everyMinute
public void everyMinute()
- Specified by:
everyMinute
in interfacetigase.stats.StatisticHolder
- Overrides:
everyMinute
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
getStatistics
public void getStatistics(tigase.stats.StatisticsList list)
- Specified by:
getStatistics
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
getStatistics
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
hasCompleteJidsInfo
public boolean hasCompleteJidsInfo()
- Specified by:
hasCompleteJidsInfo
in interfacetigase.sys.OnlineJidsReporter
- Overrides:
hasCompleteJidsInfo
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.Object> props)
- Specified by:
setProperties
in interfacetigase.cluster.strategy.ClusteringStrategyIfc<ConnectionRecordExt>
- Overrides:
setProperties
in classtigase.cluster.strategy.DefaultClusteringStrategyAbstract<ConnectionRecordExt>
-
prepareConnectionParams
protected java.util.Map<java.lang.String,java.lang.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.
-
-