Package tigase.cluster.strategy
Class DefaultClusteringStrategyAbstract<E extends ConnectionRecordIfc>
java.lang.Object
tigase.cluster.strategy.DefaultClusteringStrategyAbstract<E>
- All Implemented Interfaces:
ClusteringStrategyIfc<E>
,StatisticHolder
,OnlineJidsReporter
- Direct Known Subclasses:
DefaultClusteringStrategy
public abstract class DefaultClusteringStrategyAbstract<E extends ConnectionRecordIfc>
extends Object
implements ClusteringStrategyIfc<E>
Created: May 13, 2009 9:53:44 AM
- Author:
- Artur Hefczyc
-
Field Summary
Modifier and TypeFieldDescriptionprotected ClusterControllerIfc
protected String
protected EventBus
protected String
protected SessionManagerClusteredIfc
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
boolean
containsJid
(BareJID jid) The method checks whether the given JID is known to the installation, either user connected to local machine or any of the cluster nodes.boolean
The method checks whether the given JID is known to local cluster node as connected user.boolean
containsJidLocally
(JID jid) The method checks whether the given JID is known to local cluster node as connected user.void
void
void
void
JID[]
Retrieve all connection IDs (CIDs) for the given user.getConnectionRecord
(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.getConnectionRecords
(BareJID bareJID) Returns a set with all ConnectionRecords found in the cache for a given user ID, that is BareJID.getDefaults
(Map<String, Object> params) This method is used for configuration purpose.getInfo()
The method returns all cluster nodes currently connected to the cluster node.getNodesForIqResponse
(Packet packet) getNodesForPacketForward
(JID fromNode, Set<JID> visitedNodes, Packet packet) getSM()
void
getStatistics
(String compName, StatisticsList list) void
getStatistics
(StatisticsList list) Add the strategy statistics to the List.void
handleLocalPacket
(Packet packet, XMPPResourceConnection conn) void
void
void
handleLocalUserChangedConnId
(BareJID userId, XMPPResourceConnection conn, JID oldConnId, JID newConnId) void
handleLocalUserLogin
(BareJID userId, XMPPResourceConnection conn) void
handleLocalUserLogout
(BareJID userId, XMPPResourceConnection conn) boolean
Method checks whether the clustering strategy has a complete JIDs info.boolean
isIqResponseToNode
(Packet packet) protected boolean
isSuitableForForward
(Packet packet) void
nodeConnected
(JID node) This is a handler method which is called when a new node connects to the cluster.void
nodeDisconnected
(JID node) This is a handler method which is called when a node disconnects from the cluster.boolean
processPacket
(Packet packet, XMPPResourceConnection conn) boolean
Method attempts to send the packet to the next cluster node.void
void
setProperties
(Map<String, Object> props) Method used to pass configuration parameters to the class.void
setStatisticsPrefix
(String prefix) void
statisticExecutedIn
(long executionTime) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface tigase.cluster.strategy.ClusteringStrategyIfc
getConnectionRecordsByCreationTime
-
Field Details
-
cluster
-
comp
-
eventBus
-
prefix
-
sm
-
-
Constructor Details
-
DefaultClusteringStrategyAbstract
public DefaultClusteringStrategyAbstract()
-
-
Method Details
-
statisticExecutedIn
public void statisticExecutedIn(long executionTime) - Specified by:
statisticExecutedIn
in interfaceStatisticHolder
-
everyHour
public void everyHour()- Specified by:
everyHour
in interfaceStatisticHolder
-
everyMinute
public void everyMinute()- Specified by:
everyMinute
in interfaceStatisticHolder
-
everySecond
public void everySecond()- Specified by:
everySecond
in interfaceStatisticHolder
-
getStatistics
- Specified by:
getStatistics
in interfaceStatisticHolder
-
setStatisticsPrefix
- Specified by:
setStatisticsPrefix
in interfaceStatisticHolder
-
addCommandListener
-
containsJid
Description copied from interface:OnlineJidsReporter
The method checks whether the given JID is known to the installation, either user connected to local machine or any of the cluster nodes. False result does not mean the user is not connected. It means the method does not know anything about the JID. Some clustering strategies may not cache online users information.- Specified by:
containsJid
in interfaceOnlineJidsReporter
- Parameters:
jid
- a user's JID for whom we query information.- Returns:
- true if the user is known as online to the installation, false if the method does not know.
-
containsJidLocally
Description copied from interface:OnlineJidsReporter
The method checks whether the given JID is known to local cluster node as connected user. False result means that given JID is not connected to local cluster node but it may be connected to other cluster node. Result of this method should be independent of used clustering strategy.- Specified by:
containsJidLocally
in interfaceOnlineJidsReporter
- Parameters:
jid
- a user's JID for whom we query information- Returns:
- true if user is known as connected to local cluster node, false if it is not connected to local node
-
containsJidLocally
Description copied from interface:OnlineJidsReporter
The method checks whether the given JID is known to local cluster node as connected user. False result means that given JID is not connected to local cluster node but it may be connected to other cluster node. Result of this method should be independent of used clustering strategy.- Specified by:
containsJidLocally
in interfaceOnlineJidsReporter
- Parameters:
jid
- a user's JID for whom we query information- Returns:
- true if user is known as connected to local cluster node, false if it is not connected to local node
-
handleLocalPacket
- Specified by:
handleLocalPacket
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalPresenceSet
- Specified by:
handleLocalPresenceSet
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalResourceBind
- Specified by:
handleLocalResourceBind
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserLogin
- Specified by:
handleLocalUserLogin
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserLogout
- Specified by:
handleLocalUserLogout
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserChangedConnId
public void handleLocalUserChangedConnId(BareJID userId, XMPPResourceConnection conn, JID oldConnId, JID newConnId) - Specified by:
handleLocalUserChangedConnId
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
processPacket
- Specified by:
processPacket
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
sendToNextNode
public boolean sendToNextNode(JID fromNode, Set<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:
packet
- to be sent to a next cluster nodevisitedNodes
- a list of nodes already visited by the packet.- Returns:
- true if the packet was sent to next cluster node and false otherwise.
-
toString
-
getNodesConnected
Description copied from interface:ClusteringStrategyIfc
The method returns all cluster nodes currently connected to the cluster node.- Specified by:
getNodesConnected
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
- Returns:
- List of all cluster nodes currently connected to the cluster node.
-
getConnectionIdsForJid
Description copied from interface:OnlineJidsReporter
Retrieve all connection IDs (CIDs) for the given user.- Specified by:
getConnectionIdsForJid
in interfaceOnlineJidsReporter
- 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
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 interfaceClusteringStrategyIfc<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
- Specified by:
getConnectionRecordInstance
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
getConnectionRecords
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 interfaceClusteringStrategyIfc<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
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 tosetProperties
method.- Specified by:
getDefaults
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
- Parameters:
params
- aMap
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
- Specified by:
getInfo
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
getNodesForPacketForward
-
isIqResponseToNode
-
getNodesForIqResponse
-
getStatistics
Description copied from interface:ClusteringStrategyIfc
Add the strategy statistics to the List.- Specified by:
getStatistics
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
hasCompleteJidsInfo
public boolean hasCompleteJidsInfo()Description copied from interface:OnlineJidsReporter
Method checks whether the clustering strategy has a complete JIDs info. That is whether the strategy knows about all users connected to all nodes. Some strategies may choose not to share this information among nodes, hence the methods returns false. Other may synchronize this information and can provide it to further optimize cluster traffic.- Specified by:
hasCompleteJidsInfo
in interfaceOnlineJidsReporter
- Returns:
- a true boolean value if the strategy has a complete information about all users connected to all cluster nodes.
-
nodeConnected
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 interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
- Parameters:
node
- is a cluster node id.
-
nodeDisconnected
Description copied from interface:ClusteringStrategyIfc
This is a handler method which is called when a node disconnects from the cluster.- Specified by:
nodeDisconnected
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
- Parameters:
node
- is a cluster node id.
-
setClusterController
- Specified by:
setClusterController
in interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
setProperties
Description copied from interface:ClusteringStrategyIfc
Method used to pass configuration parameters to the class. Parameters are stored inMap
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 interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
- Parameters:
props
- aMap
with all configuration parameters for the class.
-
getSM
-
fireEvent
-
isSuitableForForward
-