Class PresenceUpdateHandler
- java.lang.Object
-
- org.jivesoftware.openfire.container.BasicModule
-
- org.jivesoftware.openfire.handler.PresenceUpdateHandler
-
- All Implemented Interfaces:
ChannelHandler
,ClusterEventListener
,Module
public class PresenceUpdateHandler extends BasicModule implements ChannelHandler, ClusterEventListener
Implements the presence protocol. Clients use this protocol to update presence and roster information.The handler must properly detect the presence type, update the user's roster, and inform presence subscribers of the session's updated presence status. Presence serves many purposes in Jabber so this handler will likely be the most complex of all handlers in the server.
There are four basic types of presence updates:
- Simple presence updates - addressed to the server (or to address), these updates are properly addressed by the server, and multicast to interested subscribers on the user's roster. An empty, missing, or "unavailable" type attribute indicates a simple update (there is no "available" type although it should be accepted by the server.
- Directed presence updates - addressed to particular jabber entities, these presence updates are properly addressed and directly delivered to the entity without broadcast to roster subscribers. Any update type is possible except those reserved for subscription requests.
- Subscription requests - these updates request presence subscription
status changes. Such requests always affect the roster. The server must:
- update the roster with the proper subscriber info
- push the roster changes to the user
- forward the update to the correct parties.
- XMPPServer probes - Provides a mechanism for servers to query the presence status of users on another server. This allows users to immediately know the presence status of users when they come online rather than way for a presence update broadcast from the other server or tracking them as they are received. Requires S2S capabilities.
- Author:
- Iain Shigeoka
-
-
Field Summary
Fields Modifier and Type Field Description static String
PRESENCE_CACHE_NAME
-
Constructor Summary
Constructors Constructor Description PresenceUpdateHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.xmpp.packet.Presence
createSubscribePresence(org.xmpp.packet.JID senderAddress, org.xmpp.packet.JID targetJID, boolean isSubscribe)
void
directedPresenceSent(org.xmpp.packet.Presence update, org.xmpp.packet.JID handlerJID, String jid)
Notification method sent to this handler when a user has sent a directed presence to an entity.boolean
hasDirectPresence(org.xmpp.packet.JID ownerJID, org.xmpp.packet.JID recipientJID)
void
initialize(XMPPServer server)
Initializes the basic module.static boolean
isPresenceUpdateReflection(org.xmpp.packet.Packet packet)
Checks if the packet is a presence stanza that intends to reflect an update back to the client from which the update originated.void
joinedCluster()
Notification event indicating that this JVM is now part of a cluster.void
joinedCluster(byte[] nodeID)
Notification event indicating that another JVM is now part of a cluster.void
leftCluster()
Notification event indicating that this JVM is no longer part of the cluster.void
leftCluster(byte[] nodeID)
Notification event indicating that another JVM is no longer part of the cluster.void
markedAsSeniorClusterMember()
Notification event indicating that this JVM is now the senior cluster member.void
process(org.xmpp.packet.Packet packet)
Process an XMPP packet.void
process(org.xmpp.packet.Presence presence)
Handle presence updates that affect roster subscriptions.void
removedExpiredPresences()
Removes directed presences sent to entities that are no longer available.void
removeDirectPresence(org.xmpp.packet.JID ownerJID, org.xmpp.packet.JID recipientJID)
-
Methods inherited from class org.jivesoftware.openfire.container.BasicModule
destroy, getName, start, stop
-
-
-
-
Field Detail
-
PRESENCE_CACHE_NAME
public static final String PRESENCE_CACHE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
process
public void process(org.xmpp.packet.Packet packet) throws UnauthorizedException, PacketException
Description copied from interface:ChannelHandler
Process an XMPP packet.- Specified by:
process
in interfaceChannelHandler
- Parameters:
packet
- a packet to process.- Throws:
UnauthorizedException
- if not allowed to process the packet.PacketException
- thrown if the packet is malformed (results in the sender's session being shutdown).
-
process
public void process(org.xmpp.packet.Presence presence) throws PacketException
Handle presence updates that affect roster subscriptions.- Parameters:
presence
- The presence presence to handle- Throws:
PacketException
- if the packet is null or the packet could not be routed.
-
createSubscribePresence
public org.xmpp.packet.Presence createSubscribePresence(org.xmpp.packet.JID senderAddress, org.xmpp.packet.JID targetJID, boolean isSubscribe)
-
directedPresenceSent
public void directedPresenceSent(org.xmpp.packet.Presence update, org.xmpp.packet.JID handlerJID, String jid)
Notification method sent to this handler when a user has sent a directed presence to an entity. If the sender of the presence is local (to this server) and the target entity does not belong to the user's roster then update the registry of sent directed presences by the user.- Parameters:
update
- the directed Presence sent by the user to an entity.handlerJID
- the JID of the handler that will receive/handle/process the sent packet.jid
- the receipient specified in the packet to handle.
-
hasDirectPresence
public boolean hasDirectPresence(org.xmpp.packet.JID ownerJID, org.xmpp.packet.JID recipientJID)
-
removeDirectPresence
public void removeDirectPresence(org.xmpp.packet.JID ownerJID, org.xmpp.packet.JID recipientJID)
-
removedExpiredPresences
public void removedExpiredPresences()
Removes directed presences sent to entities that are no longer available.
-
isPresenceUpdateReflection
public static boolean isPresenceUpdateReflection(org.xmpp.packet.Packet packet)
Checks if the packet is a presence stanza that intends to reflect an update back to the client from which the update originated.- Parameters:
packet
- The stanza (cannot be null.- Returns:
- true if the packet is presence reflection, otherwise false.
-
initialize
public void initialize(XMPPServer server)
Description copied from class:BasicModule
Initializes the basic module.
Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.
- Specified by:
initialize
in interfaceModule
- Overrides:
initialize
in classBasicModule
- Parameters:
server
- the server hosting this module.
-
joinedCluster
public void joinedCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now part of a cluster. At this point theXMPPServer.getNodeID()
holds the new nodeID value.When joining the cluster as the senior cluster member the
ClusterEventListener.markedAsSeniorClusterMember()
event will be sent right after this event.At this point the CacheFactory holds clustered caches. That means that modifications to the caches will be reflected in the cluster. The clustered caches were just obtained from the cluster and no local cached data was automatically moved.
It is generally advisable that implementations of this method:- enrich clustered cache data, by (re)adding data from this JVM/cluster node to relevant caches
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
joinedCluster
in interfaceClusterEventListener
-
joinedCluster
public void joinedCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is now part of a cluster.At this point the CacheFactory of the new node holds clustered caches. That means that modifications to the caches of this JVM will be reflected in the cluster and in particular in the new node.
- Specified by:
joinedCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that joined the cluster.
-
leftCluster
public void leftCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were this JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where this JVM was the senior cluster member and when the islands met again then this JVM stopped being the senior member.At this point the CacheFactory holds local caches. That means that modifications to the caches will only affect this JVM. It is generally advisable that implementations of this method:
- restore relevant caches content, by repopulating the caches with data from this JVM/cluster node
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
leftCluster
in interfaceClusterEventListener
-
leftCluster
public void leftCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were the other JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where the other JVM was the senior cluster member and when the islands met again then the other JVM stopped being the senior member.At this point the CacheFactory of the leaving node holds local caches. That means that modifications to the caches of this JVM will not affect the leaving node but other cluster members. It is generally advisable that implementations of this method invoke applicable event listeners, to reflect changes in availability of data (related to the node that left). Often, this action is orchestrated by only one of the remaining cluster nodes: the senior member.
- Specified by:
leftCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that is left the cluster.
-
markedAsSeniorClusterMember
public void markedAsSeniorClusterMember()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now the senior cluster member. This could either happen when initially joining the cluster or when the senior cluster member node left the cluster and this JVM was marked as the new senior cluster member.Moreover, in the case of a "split brain" scenario (ie. separated cluster islands) each island will have its own senior cluster member. However, when the islands meet again there could only be one senior cluster member so one of the senior cluster members will stop playing that role. When that happens the JVM no longer playing that role will receive the
ClusterEventListener.leftCluster()
andClusterEventListener.joinedCluster()
events.- Specified by:
markedAsSeniorClusterMember
in interfaceClusterEventListener
-
-