Class ServiceDiscoveryManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.disco.ServiceDiscoveryManager
-
public final class ServiceDiscoveryManager extends Manager
Manages discovery of services in XMPP entities. This class provides:- A registry of supported features in this XMPP entity.
- Automatic response when this XMPP entity is queried for information.
- Ability to discover items and information of remote XMPP entities.
- Ability to publish publicly available items.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServiceDiscoveryManager.Stats
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
accountSupportsFeatures(java.lang.CharSequence... features)
Check if the given features are supported by the connection account.boolean
accountSupportsFeatures(java.util.Collection<? extends java.lang.CharSequence> features)
Check if the given collection of features are supported by the connection account.static void
addDiscoInfoLookupShortcutMechanism(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)
void
addDiscoverInfoTo(DiscoverInfoBuilder response)
Add discover info response data.boolean
addEntityCapabilitiesChangedListener(EntityCapabilitiesChangedListener entityCapabilitiesChangedListener)
DataForm
addExtendedInfo(DataForm extendedInfo)
Registers extended discovery information of this XMPP entity.void
addFeature(java.lang.String feature)
Registers that a new feature is supported by this XMPP entity.void
addIdentity(DiscoverInfo.Identity identity)
Add an further identity to the client.DiscoverInfo
discoverInfo(Jid entityID)
Returns the discovered information of a given XMPP entity addressed by its JID.DiscoverInfo
discoverInfo(Jid entityID, java.lang.String node)
Returns the discovered information of a given XMPP entity addressed by its JID and note attribute.DiscoverItems
discoverItems(Jid entityID)
Returns the discovered items of a given XMPP entity addressed by its JID.DiscoverItems
discoverItems(Jid entityID, java.lang.String node)
Returns the discovered items of a given XMPP entity addressed by its JID and note attribute.DomainBareJid
findService(java.lang.String feature, boolean useCache)
DomainBareJid
findService(java.lang.String feature, boolean useCache, java.lang.String category, java.lang.String type)
java.util.List<DomainBareJid>
findServices(java.lang.String feature, boolean stopOnFirst, boolean useCache)
Find all services under the users service that provide a given feature.java.util.List<DiscoverInfo>
findServicesDiscoverInfo(java.lang.String feature, boolean stopOnFirst, boolean useCache)
Find all services under the users service that provide a given feature.java.util.List<DiscoverInfo>
findServicesDiscoverInfo(java.lang.String feature, boolean stopOnFirst, boolean useCache, java.util.Map<? super Jid,java.lang.Exception> encounteredExceptions)
Find all services under the users service that provide a given feature.java.util.List<DiscoverInfo>
findServicesDiscoverInfo(DomainBareJid serviceName, java.lang.String feature, boolean stopOnFirst, boolean useCache, java.util.Map<? super Jid,java.lang.Exception> encounteredExceptions)
Find all services under a given service that provide a given feature.java.util.List<DataForm>
getExtendedInfo()
Returns the data form as List of PacketExtensions, or null if no data form is set.java.util.List<DataForm>
getExtendedInfoAsList()
Deprecated.usegetExtendedInfo()
instead.java.util.List<java.lang.String>
getFeatures()
Returns the supported features by this XMPP entity.java.util.Set<DiscoverInfo.Identity>
getIdentities()
Returns all identities of this client as unmodifiable Collection.DiscoverInfo.Identity
getIdentity()
Return the default identity of the client.java.lang.String
getIdentityName()
Returns the name of the client that will be returned when asked for the client identity in a disco request.java.lang.String
getIdentityType()
Returns the type of client that will be returned when asked for the client identity in a disco request.static ServiceDiscoveryManager
getInstanceFor(XMPPConnection connection)
Returns the ServiceDiscoveryManager instance associated with a given XMPPConnection.ServiceDiscoveryManager.Stats
getStats()
boolean
includesFeature(java.lang.String feature)
Returns true if the specified feature is registered in the ServiceDiscoveryManager.static void
removeDiscoInfoLookupShortcutMechanism(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)
void
removeExtendedInfo()
Removes the data form containing extended service discovery information from the information returned by this XMPP entity.void
removeExtendedInfo(java.lang.String formType)
Remove the extended discovery information of the given form type.void
removeFeature(java.lang.String feature)
Removes the specified feature from the supported features by this XMPP entity.boolean
removeIdentity(DiscoverInfo.Identity identity)
Remove an identity from the client.void
removeNodeInformationProvider(java.lang.String node)
Removes the NodeInformationProvider responsible for providing information (ie items) related to a given node.boolean
serverSupportsFeature(java.lang.CharSequence feature)
Returns true if the server supports the given feature.boolean
serverSupportsFeatures(java.lang.CharSequence... features)
boolean
serverSupportsFeatures(java.util.Collection<? extends java.lang.CharSequence> features)
static void
setDefaultIdentity(DiscoverInfo.Identity identity)
Set the default identity all new connections will have.void
setExtendedInfo(DataForm info)
Deprecated.useaddExtendedInfo(DataForm)
instead.void
setIdentity(DiscoverInfo.Identity identity)
Sets the default identity the client will report.void
setNodeInformationProvider(java.lang.String node, NodeInformationProvider listener)
Sets the NodeInformationProvider responsible for providing information (ie items) related to a given node.boolean
supportsFeature(Jid jid, java.lang.CharSequence feature)
Queries the remote entity for it's features and returns true if the given feature is found.boolean
supportsFeatures(Jid jid, java.lang.CharSequence... features)
boolean
supportsFeatures(Jid jid, java.util.Collection<? extends java.lang.CharSequence> features)
-
Methods inherited from class org.jivesoftware.smack.Manager
connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
-
-
-
-
Method Detail
-
setDefaultIdentity
public static void setDefaultIdentity(DiscoverInfo.Identity identity)
Set the default identity all new connections will have. If unchanged the default identity is an identity where category is set to 'client', type is set to 'pc' and name is set to 'Smack'.- Parameters:
identity
- TODO javadoc me please
-
getIdentityName
public java.lang.String getIdentityName()
Returns the name of the client that will be returned when asked for the client identity in a disco request. The name could be any value you need to identity this client.- Returns:
- the name of the client that will be returned when asked for the client identity in a disco request.
-
setIdentity
public void setIdentity(DiscoverInfo.Identity identity)
Sets the default identity the client will report.- Parameters:
identity
- TODO javadoc me please
-
getIdentity
public DiscoverInfo.Identity getIdentity()
Return the default identity of the client.- Returns:
- the default identity.
-
getIdentityType
public java.lang.String getIdentityType()
Returns the type of client that will be returned when asked for the client identity in a disco request. The valid types are defined by the category client. Follow this link to learn the possible types: XMPP Registry for Service Discovery Identities- Returns:
- the type of client that will be returned when asked for the client identity in a disco request.
-
addIdentity
public void addIdentity(DiscoverInfo.Identity identity)
Add an further identity to the client.- Parameters:
identity
- TODO javadoc me please
-
removeIdentity
public boolean removeIdentity(DiscoverInfo.Identity identity)
Remove an identity from the client. Note that the client needs at least one identity, the default identity, which can not be removed.- Parameters:
identity
- TODO javadoc me please- Returns:
- true, if successful. Otherwise the default identity was given.
-
getIdentities
public java.util.Set<DiscoverInfo.Identity> getIdentities()
Returns all identities of this client as unmodifiable Collection.- Returns:
- all identies as set
-
getInstanceFor
public static ServiceDiscoveryManager getInstanceFor(XMPPConnection connection)
Returns the ServiceDiscoveryManager instance associated with a given XMPPConnection.- Parameters:
connection
- the connection used to look for the proper ServiceDiscoveryManager.- Returns:
- the ServiceDiscoveryManager associated with a given XMPPConnection.
-
addDiscoverInfoTo
public void addDiscoverInfoTo(DiscoverInfoBuilder response)
Add discover info response data.- Parameters:
response
- the discover info response packet- See Also:
- XEP-30 Basic Protocol; Example 2
-
setNodeInformationProvider
public void setNodeInformationProvider(java.lang.String node, NodeInformationProvider listener)
Sets the NodeInformationProvider responsible for providing information (ie items) related to a given node. Every time this client receives a disco request regarding the items of a given node, the provider associated to that node will be the responsible for providing the requested information.In MUC, a node could be 'http://jabber.org/protocol/muc#rooms' which means that the NodeInformationProvider will provide information about the rooms where the user has joined.
- Parameters:
node
- the node whose items will be provided by the NodeInformationProvider.listener
- the NodeInformationProvider responsible for providing items related to the node.
-
removeNodeInformationProvider
public void removeNodeInformationProvider(java.lang.String node)
Removes the NodeInformationProvider responsible for providing information (ie items) related to a given node. This means that no more information will be available for the specified node. In MUC, a node could be 'http://jabber.org/protocol/muc#rooms' which means that the NodeInformationProvider will provide information about the rooms where the user has joined.- Parameters:
node
- the node to remove the associated NodeInformationProvider.
-
getFeatures
public java.util.List<java.lang.String> getFeatures()
Returns the supported features by this XMPP entity.The result is a copied modifiable list of the original features.
- Returns:
- a List of the supported features by this XMPP entity.
-
addFeature
public void addFeature(java.lang.String feature)
Registers that a new feature is supported by this XMPP entity. When this client is queried for its information the registered features will be answered.Since no stanza is actually sent to the server it is safe to perform this operation before logging to the server. In fact, you may want to configure the supported features before logging to the server so that the information is already available if it is required upon login.
- Parameters:
feature
- the feature to register as supported.
-
removeFeature
public void removeFeature(java.lang.String feature)
Removes the specified feature from the supported features by this XMPP entity.Since no stanza is actually sent to the server it is safe to perform this operation before logging to the server.
- Parameters:
feature
- the feature to remove from the supported features.
-
includesFeature
public boolean includesFeature(java.lang.String feature)
Returns true if the specified feature is registered in the ServiceDiscoveryManager.- Parameters:
feature
- the feature to look for.- Returns:
- a boolean indicating if the specified featured is registered or not.
-
setExtendedInfo
@Deprecated public void setExtendedInfo(DataForm info)
Deprecated.useaddExtendedInfo(DataForm)
instead.Registers extended discovery information of this XMPP entity. When this client is queried for its information this data form will be returned as specified by XEP-0128.Since no stanza is actually sent to the server it is safe to perform this operation before logging to the server. In fact, you may want to configure the extended info before logging to the server so that the information is already available if it is required upon login.
- Parameters:
info
- the data form that contains the extend service discovery information.
-
addExtendedInfo
public DataForm addExtendedInfo(DataForm extendedInfo)
Registers extended discovery information of this XMPP entity. When this client is queried for its information this data form will be returned as specified by XEP-0128.Since no stanza is actually sent to the server it is safe to perform this operation before logging to the server. In fact, you may want to configure the extended info before logging to the server so that the information is already available if it is required upon login.
- Parameters:
extendedInfo
- the data form that contains the extend service discovery information.- Returns:
- the old data form which got replaced (if any)
- Since:
- 4.4.0
-
removeExtendedInfo
public void removeExtendedInfo(java.lang.String formType)
Remove the extended discovery information of the given form type.- Parameters:
formType
- the type of the data form with the extended discovery information to remove.- Since:
- 4.4.0
-
getExtendedInfo
public java.util.List<DataForm> getExtendedInfo()
Returns the data form as List of PacketExtensions, or null if no data form is set. This representation is needed by some classes (e.g. EntityCapsManager, NodeInformationProvider)- Returns:
- the data form as List of PacketExtensions
-
getExtendedInfoAsList
@Deprecated public java.util.List<DataForm> getExtendedInfoAsList()
Deprecated.usegetExtendedInfo()
instead.Returns the data form as List of PacketExtensions, or null if no data form is set. This representation is needed by some classes (e.g. EntityCapsManager, NodeInformationProvider)- Returns:
- the data form as List of PacketExtensions
-
removeExtendedInfo
public void removeExtendedInfo()
Removes the data form containing extended service discovery information from the information returned by this XMPP entity.Since no stanza is actually sent to the server it is safe to perform this operation before logging to the server.
-
discoverInfo
public DiscoverInfo discoverInfo(Jid entityID) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Returns the discovered information of a given XMPP entity addressed by its JID. Use null as entityID to query the server- Parameters:
entityID
- the address of the XMPP entity or null.- Returns:
- the discovered information.
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
discoverInfo
public DiscoverInfo discoverInfo(Jid entityID, java.lang.String node) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Returns the discovered information of a given XMPP entity addressed by its JID and note attribute. Use this message only when trying to query information which is not directly addressable.- Parameters:
entityID
- the address of the XMPP entity.node
- the optional attribute that supplements the 'jid' attribute.- Returns:
- the discovered information.
- Throws:
XMPPException.XMPPErrorException
- if the operation failed for some reason.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- See Also:
- XEP-30 Basic Protocol, XEP-30 Info Nodes
-
discoverItems
public DiscoverItems discoverItems(Jid entityID) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Returns the discovered items of a given XMPP entity addressed by its JID.- Parameters:
entityID
- the address of the XMPP entity.- Returns:
- the discovered information.
- Throws:
XMPPException.XMPPErrorException
- if the operation failed for some reason.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
discoverItems
public DiscoverItems discoverItems(Jid entityID, java.lang.String node) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Returns the discovered items of a given XMPP entity addressed by its JID and note attribute. Use this message only when trying to query information which is not directly addressable.- Parameters:
entityID
- the address of the XMPP entity.node
- the optional attribute that supplements the 'jid' attribute.- Returns:
- the discovered items.
- Throws:
XMPPException.XMPPErrorException
- if the operation failed for some reason.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
serverSupportsFeature
public boolean serverSupportsFeature(java.lang.CharSequence feature) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Returns true if the server supports the given feature.- Parameters:
feature
- TODO javadoc me please- Returns:
- true if the server supports the given feature.
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.1
-
serverSupportsFeatures
public boolean serverSupportsFeatures(java.lang.CharSequence... features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
serverSupportsFeatures
public boolean serverSupportsFeatures(java.util.Collection<? extends java.lang.CharSequence> features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
accountSupportsFeatures
public boolean accountSupportsFeatures(java.lang.CharSequence... features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Check if the given features are supported by the connection account. This means that the discovery information lookup will be performed on the bare JID of the connection managed by this ServiceDiscoveryManager.- Parameters:
features
- the features to check- Returns:
true
if all features are supported by the connection account,false
otherwise- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.2.2
-
accountSupportsFeatures
public boolean accountSupportsFeatures(java.util.Collection<? extends java.lang.CharSequence> features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Check if the given collection of features are supported by the connection account. This means that the discovery information lookup will be performed on the bare JID of the connection managed by this ServiceDiscoveryManager.- Parameters:
features
- a collection of features- Returns:
true
if all features are supported by the connection account,false
otherwise- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.2.2
-
supportsFeature
public boolean supportsFeature(Jid jid, java.lang.CharSequence feature) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Queries the remote entity for it's features and returns true if the given feature is found.- Parameters:
jid
- the JID of the remote entityfeature
- TODO javadoc me please- Returns:
- true if the entity supports the feature, false otherwise
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
supportsFeatures
public boolean supportsFeatures(Jid jid, java.lang.CharSequence... features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
supportsFeatures
public boolean supportsFeatures(Jid jid, java.util.Collection<? extends java.lang.CharSequence> features) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
findServicesDiscoverInfo
public java.util.List<DiscoverInfo> findServicesDiscoverInfo(java.lang.String feature, boolean stopOnFirst, boolean useCache) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Find all services under the users service that provide a given feature.- Parameters:
feature
- the feature to search forstopOnFirst
- if true, stop searching after the first service was founduseCache
- if true, query a cache first to avoid network I/O- Returns:
- a possible empty list of services providing the given feature
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
findServicesDiscoverInfo
public java.util.List<DiscoverInfo> findServicesDiscoverInfo(java.lang.String feature, boolean stopOnFirst, boolean useCache, java.util.Map<? super Jid,java.lang.Exception> encounteredExceptions) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Find all services under the users service that provide a given feature.- Parameters:
feature
- the feature to search forstopOnFirst
- if true, stop searching after the first service was founduseCache
- if true, query a cache first to avoid network I/OencounteredExceptions
- an optional map which will be filled with the exceptions encountered- Returns:
- a possible empty list of services providing the given feature
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.2.2
-
findServicesDiscoverInfo
public java.util.List<DiscoverInfo> findServicesDiscoverInfo(DomainBareJid serviceName, java.lang.String feature, boolean stopOnFirst, boolean useCache, java.util.Map<? super Jid,java.lang.Exception> encounteredExceptions) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Find all services under a given service that provide a given feature.- Parameters:
serviceName
- the service to queryfeature
- the feature to search forstopOnFirst
- if true, stop searching after the first service was founduseCache
- if true, query a cache first to avoid network I/OencounteredExceptions
- an optional map which will be filled with the exceptions encountered- Returns:
- a possible empty list of services providing the given feature
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.3.0
-
findServices
public java.util.List<DomainBareJid> findServices(java.lang.String feature, boolean stopOnFirst, boolean useCache) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Find all services under the users service that provide a given feature.- Parameters:
feature
- the feature to search forstopOnFirst
- if true, stop searching after the first service was founduseCache
- if true, query a cache first to avoid network I/O- Returns:
- a possible empty list of services providing the given feature
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
findService
public DomainBareJid findService(java.lang.String feature, boolean useCache, java.lang.String category, java.lang.String type) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
findService
public DomainBareJid findService(java.lang.String feature, boolean useCache) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
- Throws:
SmackException.NoResponseException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
java.lang.InterruptedException
-
addEntityCapabilitiesChangedListener
public boolean addEntityCapabilitiesChangedListener(EntityCapabilitiesChangedListener entityCapabilitiesChangedListener)
-
addDiscoInfoLookupShortcutMechanism
public static void addDiscoInfoLookupShortcutMechanism(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)
-
removeDiscoInfoLookupShortcutMechanism
public static void removeDiscoInfoLookupShortcutMechanism(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)
-
getStats
public ServiceDiscoveryManager.Stats getStats()
-
-