Class IQDiscoInfoHandler
- java.lang.Object
-
- org.jivesoftware.openfire.container.BasicModule
-
- org.jivesoftware.openfire.handler.IQHandler
-
- org.jivesoftware.openfire.disco.IQDiscoInfoHandler
-
- All Implemented Interfaces:
ChannelHandler,ClusterEventListener,Module
public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListener
IQDiscoInfoHandler is responsible for handling disco#info requests. This class holds a map with the main entities and the associated DiscoInfoProvider. We are considering the host of the recipient JIDs as main entities. It's the DiscoInfoProvider responsibility to provide information about the JID's name together with any possible requested node.For example, let's have in the entities map the following entries: "localhost" and "conference.localhost". Associated with each entry we have different DiscoInfoProviders. Now we receive a disco#info request for the following JID: "room@conference.localhost" which is a disco request for a MUC room. So IQDiscoInfoHandler will look for the DiscoInfoProvider associated with the JID's host which in this case is "conference.localhost". Once we have located the provider we will delegate to the provider the responsibility to provide the info specific to the JID's name which in this case is "room". Among the information that a room could provide we could find its identity and the features it supports (e.g. 'muc_passwordprotected', 'muc_unmoderated', etc.). Finally, after we have collected all the information provided by the provider we will add it to the reply. On the other hand, if no provider was found or the provider has no information for the requested name/node then a not-found error will be returned.
- Author:
- Gaston Dombiak
-
-
Field Summary
Fields Modifier and Type Field Description static SystemProperty<Boolean>ENABLEDstatic StringNAMESPACE_DISCO_INFO-
Fields inherited from class org.jivesoftware.openfire.handler.IQHandler
deliverer, sessionManager
-
-
Constructor Summary
Constructors Constructor Description IQDiscoInfoHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddServerFeature(String namespace)Adds one specific feature to the information returned whenever a disco for information is made against the server.voidaddServerFeaturesProvider(ServerFeaturesProvider provider)Adds the features provided by the new service that implements the ServerFeaturesProvider interface.voidaddServerIdentitiesProvider(ServerIdentitiesProvider provider)Adds the "discoverable" identities provided by the provider whenever a disco for info is made against the server.voidaddUserFeaturesProvider(UserFeaturesProvider provider)Adds the "discoverable" user features provided by the provider whenever a disco for info is made against users of the server.voidaddUserIdentitiesProvider(UserIdentitiesProvider provider)Adds the "discoverable" user identities provided by the provider whenever a disco for info is made against users of the server.static org.xmpp.forms.DataFormgetFirstDataForm(Set<org.xmpp.forms.DataForm> dataForms)return the first DataForm for a Collections of Set DataFormsIQHandlerInfogetInfo()Returns the handler information to help generically handle IQ packets.org.xmpp.packet.IQhandleIQ(org.xmpp.packet.IQ packet)Handles the received IQ packet.voidinitialize(XMPPServer server)Initializes the basic module.voidjoinedCluster()Notification event indicating that this JVM is now part of a cluster.voidjoinedCluster(byte[] nodeID)Notification event indicating that another JVM is now part of a cluster.voidleftCluster()Notification event indicating that this JVM is no longer part of the cluster.voidleftCluster(byte[] nodeID)Notification event indicating that another JVM is no longer part of the cluster.voidmarkedAsSeniorClusterMember()Notification event indicating that this JVM is now the senior cluster member.protected voidremoveProvider(String name)Removes the DiscoInfoProvider related to a given entity.voidremoveServerFeature(String namespace)Removes a feature from the information returned whenever a disco for information is made against the server.voidremoveServerIdentitiesProvider(ServerIdentitiesProvider provider)Removes this provider of identities.voidremoveServerNodeInfoProvider(String node)Removes the DiscoInfoProvider to use when a disco#info packet is sent to the server itself and the specified node.voidremoveUserFeaturesProvider(UserFeaturesProvider provider)Removes this provider of user features.voidremoveUserIdentitiesProvider(UserIdentitiesProvider provider)Removes this provider of user identities.protected voidsetProvider(String name, DiscoInfoProvider provider)Sets that a given DiscoInfoProvider will provide information about a given entity.voidsetServerNodeInfoProvider(String node, DiscoInfoProvider provider)Sets the DiscoInfoProvider to use when a disco#info packet is sent to the server itself and the specified node.static voidsetSoftwareVersionDataFormFromDiscoInfo(org.dom4j.Element query, LocalSession session)Set all Software Version data responsed by the peer for the Software information request Service Discovery (XEP-0232)-
Methods inherited from class org.jivesoftware.openfire.container.BasicModule
destroy, getName, start, stop
-
-
-
-
Field Detail
-
NAMESPACE_DISCO_INFO
public static final String NAMESPACE_DISCO_INFO
- See Also:
- Constant Field Values
-
ENABLED
public static final SystemProperty<Boolean> ENABLED
-
-
Method Detail
-
getInfo
public IQHandlerInfo getInfo()
Description copied from class:IQHandlerReturns the handler information to help generically handle IQ packets. IQHandlers that aren't local server iq handlers (e.g. chatbots, transports, etc) returnnull.
-
handleIQ
public org.xmpp.packet.IQ handleIQ(org.xmpp.packet.IQ packet)
Description copied from class:IQHandlerHandles the received IQ packet.
-
setServerNodeInfoProvider
public void setServerNodeInfoProvider(String node, DiscoInfoProvider provider)
Sets the DiscoInfoProvider to use when a disco#info packet is sent to the server itself and the specified node. For instance, if node matches "http://jabber.org/protocol/offline" then a special DiscoInfoProvider should be use to return information about offline messages.- Parameters:
node- the node that the provider will handle.provider- the DiscoInfoProvider that will handle disco#info packets sent with the specified node.
-
removeServerNodeInfoProvider
public void removeServerNodeInfoProvider(String node)
Removes the DiscoInfoProvider to use when a disco#info packet is sent to the server itself and the specified node.- Parameters:
node- the node that the provider was handling.
-
setProvider
protected void setProvider(String name, DiscoInfoProvider provider)
Sets that a given DiscoInfoProvider will provide information about a given entity. This message must be used when new modules (e.g. MUC) are implemented and need to provide information about them.- Parameters:
name- the name of the entity.provider- the DiscoInfoProvider that will provide the entity's information.
-
removeProvider
protected void removeProvider(String name)
Removes the DiscoInfoProvider related to a given entity.- Parameters:
name- the name of the entity.
-
addServerFeaturesProvider
public void addServerFeaturesProvider(ServerFeaturesProvider provider)
Adds the features provided by the new service that implements the ServerFeaturesProvider interface. This information will be used whenever a disco for information is made against the server (i.e. the packet's target is the server). Example of features are: jabber:iq:agents, jabber:iq:time, etc.- Parameters:
provider- the ServerFeaturesProvider that provides new server features.
-
addServerIdentitiesProvider
public void addServerIdentitiesProvider(ServerIdentitiesProvider provider)
Adds the "discoverable" identities provided by the provider whenever a disco for info is made against the server.- Parameters:
provider- The provider of identities.
-
removeServerIdentitiesProvider
public void removeServerIdentitiesProvider(ServerIdentitiesProvider provider)
Removes this provider of identities.- Parameters:
provider- The provider of identities.
-
addUserIdentitiesProvider
public void addUserIdentitiesProvider(UserIdentitiesProvider provider)
Adds the "discoverable" user identities provided by the provider whenever a disco for info is made against users of the server.- Parameters:
provider- The provider of user identities.
-
removeUserIdentitiesProvider
public void removeUserIdentitiesProvider(UserIdentitiesProvider provider)
Removes this provider of user identities.- Parameters:
provider- The provider of identities.
-
addUserFeaturesProvider
public void addUserFeaturesProvider(UserFeaturesProvider provider)
Adds the "discoverable" user features provided by the provider whenever a disco for info is made against users of the server.- Parameters:
provider- The provider of user features.
-
removeUserFeaturesProvider
public void removeUserFeaturesProvider(UserFeaturesProvider provider)
Removes this provider of user features.- Parameters:
provider- The provider of features.
-
addServerFeature
public void addServerFeature(String namespace)
Adds one specific feature to the information returned whenever a disco for information is made against the server.- Parameters:
namespace- the namespace identifying the new server feature.
-
removeServerFeature
public void removeServerFeature(String namespace)
Removes a feature from the information returned whenever a disco for information is made against the server.- Parameters:
namespace- the namespace of the feature to be removed.
-
initialize
public void initialize(XMPPServer server)
Description copied from class:BasicModuleInitializes the basic module.
Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.
- Specified by:
initializein interfaceModule- Overrides:
initializein classIQHandler- Parameters:
server- the server hosting this module.
-
joinedCluster
public void joinedCluster()
Description copied from interface:ClusterEventListenerNotification 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:
joinedClusterin interfaceClusterEventListener
-
joinedCluster
public void joinedCluster(byte[] nodeID)
Description copied from interface:ClusterEventListenerNotification 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:
joinedClusterin interfaceClusterEventListener- Parameters:
nodeID- ID of the node that joined the cluster.
-
leftCluster
public void leftCluster()
Description copied from interface:ClusterEventListenerNotification 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 eventandjoined 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:
leftClusterin interfaceClusterEventListener
-
leftCluster
public void leftCluster(byte[] nodeID)
Description copied from interface:ClusterEventListenerNotification 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 eventandjoined 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:
leftClusterin interfaceClusterEventListener- Parameters:
nodeID- ID of the node that is left the cluster.
-
markedAsSeniorClusterMember
public void markedAsSeniorClusterMember()
Description copied from interface:ClusterEventListenerNotification 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:
markedAsSeniorClusterMemberin interfaceClusterEventListener
-
getFirstDataForm
public static org.xmpp.forms.DataForm getFirstDataForm(Set<org.xmpp.forms.DataForm> dataForms)
return the first DataForm for a Collections of Set DataForms- Parameters:
dataForms- collection from which to return the first element (cannot be null, can be an empty collection).- Returns:
- first dataform from the collection. Null if the collection was empty.
-
setSoftwareVersionDataFormFromDiscoInfo
public static void setSoftwareVersionDataFormFromDiscoInfo(org.dom4j.Element query, LocalSession session)Set all Software Version data responsed by the peer for the Software information request Service Discovery (XEP-0232)- Parameters:
query- represented on the response of the peersession- represented the LocalSession with peer
-
-