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 java.lang.Object implements ClusteringStrategyIfc<E>
Created: May 13, 2009 9:53:44 AM- Author:
- Artur Hefczyc
-
-
Field Summary
Fields Modifier and Type Field Description protected ClusterControllerIfcclusterprotected java.lang.Stringcompprotected EventBuseventBusprotected java.lang.Stringprefixprotected SessionManagerClusteredIfcsm
-
Constructor Summary
Constructors Constructor Description DefaultClusteringStrategyAbstract()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCommandListener(CommandListener cmd)booleancontainsJid(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.booleancontainsJidLocally(BareJID jid)The method checks whether the given JID is known to local cluster node as connected user.booleancontainsJidLocally(JID jid)The method checks whether the given JID is known to local cluster node as connected user.voideveryHour()voideveryMinute()voideverySecond()voidfireEvent(java.lang.Object event)JID[]getConnectionIdsForJid(BareJID jid)Retrieve all connection IDs (CIDs) for the given user.EgetConnectionRecord(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.EgetConnectionRecordInstance()java.util.Set<E>getConnectionRecords(BareJID bareJID)Returns a set with all ConnectionRecords found in the cache for a given user ID, that is BareJID.java.util.Map<java.lang.String,java.lang.Object>getDefaults(java.util.Map<java.lang.String,java.lang.Object> params)This method is used for configuration purpose.java.lang.StringgetInfo()java.util.List<JID>getNodesConnected()The method returns all cluster nodes currently connected to the cluster node.java.util.List<JID>getNodesForIqResponse(Packet packet)java.util.List<JID>getNodesForPacketForward(JID fromNode, java.util.Set<JID> visitedNodes, Packet packet)SessionManagerClusteredIfcgetSM()voidgetStatistics(java.lang.String compName, StatisticsList list)voidgetStatistics(StatisticsList list)Add the strategy statistics to the List.voidhandleLocalPacket(Packet packet, XMPPResourceConnection conn)voidhandleLocalPresenceSet(XMPPResourceConnection conn)voidhandleLocalResourceBind(XMPPResourceConnection conn)voidhandleLocalUserChangedConnId(BareJID userId, XMPPResourceConnection conn, JID oldConnId, JID newConnId)voidhandleLocalUserLogin(BareJID userId, XMPPResourceConnection conn)voidhandleLocalUserLogout(BareJID userId, XMPPResourceConnection conn)booleanhasCompleteJidsInfo()Method checks whether the clustering strategy has a complete JIDs info.booleanisIqResponseToNode(Packet packet)protected booleanisSuitableForForward(Packet packet)voidnodeConnected(JID node)This is a handler method which is called when a new node connects to the cluster.voidnodeDisconnected(JID node)This is a handler method which is called when a node disconnects from the cluster.booleanprocessPacket(Packet packet, XMPPResourceConnection conn)booleansendToNextNode(JID fromNode, java.util.Set<JID> visitedNodes, java.util.Map<java.lang.String,java.lang.String> data, Packet packet)Method attempts to send the packet to the next cluster node.voidsetClusterController(ClusterControllerIfc clComp)voidsetProperties(java.util.Map<java.lang.String,java.lang.Object> props)Method used to pass configuration parameters to the class.voidsetStatisticsPrefix(java.lang.String prefix)voidstatisticExecutedIn(long executionTime)java.lang.StringtoString()-
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 Detail
-
cluster
@Inject protected ClusterControllerIfc cluster
-
comp
protected java.lang.String comp
-
prefix
protected java.lang.String prefix
-
sm
@Inject protected SessionManagerClusteredIfc sm
-
-
Method Detail
-
statisticExecutedIn
public void statisticExecutedIn(long executionTime)
- Specified by:
statisticExecutedInin interfaceStatisticHolder
-
everyHour
public void everyHour()
- Specified by:
everyHourin interfaceStatisticHolder
-
everyMinute
public void everyMinute()
- Specified by:
everyMinutein interfaceStatisticHolder
-
everySecond
public void everySecond()
- Specified by:
everySecondin interfaceStatisticHolder
-
getStatistics
public void getStatistics(java.lang.String compName, StatisticsList list)- Specified by:
getStatisticsin interfaceStatisticHolder
-
setStatisticsPrefix
public void setStatisticsPrefix(java.lang.String prefix)
- Specified by:
setStatisticsPrefixin interfaceStatisticHolder
-
addCommandListener
public final void addCommandListener(CommandListener cmd)
-
containsJid
public boolean containsJid(BareJID jid)
Description copied from interface:OnlineJidsReporterThe 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:
containsJidin 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
public boolean containsJidLocally(BareJID jid)
Description copied from interface:OnlineJidsReporterThe 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:
containsJidLocallyin 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
public boolean containsJidLocally(JID jid)
Description copied from interface:OnlineJidsReporterThe 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:
containsJidLocallyin 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
public void handleLocalPacket(Packet packet, XMPPResourceConnection conn)
- Specified by:
handleLocalPacketin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalPresenceSet
public void handleLocalPresenceSet(XMPPResourceConnection conn)
- Specified by:
handleLocalPresenceSetin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalResourceBind
public void handleLocalResourceBind(XMPPResourceConnection conn)
- Specified by:
handleLocalResourceBindin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserLogin
public void handleLocalUserLogin(BareJID userId, XMPPResourceConnection conn)
- Specified by:
handleLocalUserLoginin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserLogout
public void handleLocalUserLogout(BareJID userId, XMPPResourceConnection conn)
- Specified by:
handleLocalUserLogoutin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
handleLocalUserChangedConnId
public void handleLocalUserChangedConnId(BareJID userId, XMPPResourceConnection conn, JID oldConnId, JID newConnId)
- Specified by:
handleLocalUserChangedConnIdin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
processPacket
public boolean processPacket(Packet packet, XMPPResourceConnection conn)
- Specified by:
processPacketin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
sendToNextNode
public boolean sendToNextNode(JID fromNode, java.util.Set<JID> visitedNodes, java.util.Map<java.lang.String,java.lang.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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getNodesConnected
public java.util.List<JID> getNodesConnected()
Description copied from interface:ClusteringStrategyIfcThe method returns all cluster nodes currently connected to the cluster node.- Specified by:
getNodesConnectedin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>- Returns:
- List of all cluster nodes currently connected to the cluster node.
-
getConnectionIdsForJid
public JID[] getConnectionIdsForJid(BareJID jid)
Description copied from interface:OnlineJidsReporterRetrieve all connection IDs (CIDs) for the given user.- Specified by:
getConnectionIdsForJidin interfaceOnlineJidsReporter- Parameters:
jid- id of the user for which we want to retrieve the list.- Returns:
- an array of
JIDcontaining all Connection IDs (CIDs) for the given user.
-
getConnectionRecord
public E getConnectionRecord(JID jid)
Description copied from interface:ClusteringStrategyIfcReturns 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:
getConnectionRecordin 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
public E getConnectionRecordInstance()
- Specified by:
getConnectionRecordInstancein interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
getConnectionRecords
public java.util.Set<E> getConnectionRecords(BareJID bareJID)
Description copied from interface:ClusteringStrategyIfcReturns 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:
getConnectionRecordsin 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
public java.util.Map<java.lang.String,java.lang.Object> getDefaults(java.util.Map<java.lang.String,java.lang.Object> params)
Description copied from interface:ClusteringStrategyIfcThis 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 tosetPropertiesmethod.- Specified by:
getDefaultsin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>- Parameters:
params- aMapwith properties loaded from init.properties file which should be used for generating defaults.- Returns:
- a
Mapwith all the class default configuration parameters.
-
getInfo
public java.lang.String getInfo()
- Specified by:
getInfoin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
getNodesForPacketForward
public java.util.List<JID> getNodesForPacketForward(JID fromNode, java.util.Set<JID> visitedNodes, Packet packet)
-
isIqResponseToNode
public boolean isIqResponseToNode(Packet packet)
-
getStatistics
public void getStatistics(StatisticsList list)
Description copied from interface:ClusteringStrategyIfcAdd the strategy statistics to the List.- Specified by:
getStatisticsin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
hasCompleteJidsInfo
public boolean hasCompleteJidsInfo()
Description copied from interface:OnlineJidsReporterMethod 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:
hasCompleteJidsInfoin interfaceOnlineJidsReporter- Returns:
- a true boolean value if the strategy has a complete information about all users connected to all cluster nodes.
-
nodeConnected
public void nodeConnected(JID node)
Description copied from interface:ClusteringStrategyIfcThis is a handler method which is called when a new node connects to the cluster.- Specified by:
nodeConnectedin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>- Parameters:
node- is a cluster node id.
-
nodeDisconnected
public void nodeDisconnected(JID node)
Description copied from interface:ClusteringStrategyIfcThis is a handler method which is called when a node disconnects from the cluster.- Specified by:
nodeDisconnectedin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>- Parameters:
node- is a cluster node id.
-
setClusterController
public void setClusterController(ClusterControllerIfc clComp)
- Specified by:
setClusterControllerin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Description copied from interface:ClusteringStrategyIfcMethod used to pass configuration parameters to the class. Parameters are stored inMapwhich 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:
setPropertiesin interfaceClusteringStrategyIfc<E extends ConnectionRecordIfc>- Parameters:
props- aMapwith all configuration parameters for the class.
-
getSM
public SessionManagerClusteredIfc getSM()
-
fireEvent
public void fireEvent(java.lang.Object event)
-
isSuitableForForward
protected boolean isSuitableForForward(Packet packet)
-
-