Class ServiceDiscoveryManager


  • public final class ServiceDiscoveryManager
    extends org.jivesoftware.smack.Manager
    Manages discovery of services in XMPP entities. This class provides:
    1. A registry of supported features in this XMPP entity.
    2. Automatic response when this XMPP entity is queried for information.
    3. Ability to discover items and information of remote XMPP entities.
    4. Ability to publish publicly available items.
    • 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​(org.jivesoftware.smack.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.
      • 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.
        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.
        use getExtendedInfo() 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​(org.jxmpp.jid.Jid entityID)
                                  throws org.jivesoftware.smack.SmackException.NoResponseException,
                                         org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                         org.jivesoftware.smack.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • discoverInfo

        public DiscoverInfo discoverInfo​(org.jxmpp.jid.Jid entityID,
                                         java.lang.String node)
                                  throws org.jivesoftware.smack.SmackException.NoResponseException,
                                         org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                         org.jivesoftware.smack.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if the operation failed for some reason.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.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​(org.jxmpp.jid.Jid entityID)
                                    throws org.jivesoftware.smack.SmackException.NoResponseException,
                                           org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                           org.jivesoftware.smack.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if the operation failed for some reason.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • discoverItems

        public DiscoverItems discoverItems​(org.jxmpp.jid.Jid entityID,
                                           java.lang.String node)
                                    throws org.jivesoftware.smack.SmackException.NoResponseException,
                                           org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                           org.jivesoftware.smack.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:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if the operation failed for some reason.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
        org.jivesoftware.smack.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 org.jivesoftware.smack.SmackException.NoResponseException,
                                             org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                             org.jivesoftware.smack.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:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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 org.jivesoftware.smack.SmackException.NoResponseException,
                                              org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                              org.jivesoftware.smack.SmackException.NotConnectedException,
                                              java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • serverSupportsFeatures

        public boolean serverSupportsFeatures​(java.util.Collection<? extends java.lang.CharSequence> features)
                                       throws org.jivesoftware.smack.SmackException.NoResponseException,
                                              org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                              org.jivesoftware.smack.SmackException.NotConnectedException,
                                              java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • accountSupportsFeatures

        public boolean accountSupportsFeatures​(java.lang.CharSequence... features)
                                        throws org.jivesoftware.smack.SmackException.NoResponseException,
                                               org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                               org.jivesoftware.smack.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:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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 org.jivesoftware.smack.SmackException.NoResponseException,
                                               org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                               org.jivesoftware.smack.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:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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​(org.jxmpp.jid.Jid jid,
                                       java.lang.CharSequence feature)
                                throws org.jivesoftware.smack.SmackException.NoResponseException,
                                       org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                       org.jivesoftware.smack.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 entity
        feature - TODO javadoc me please
        Returns:
        true if the entity supports the feature, false otherwise
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • supportsFeatures

        public boolean supportsFeatures​(org.jxmpp.jid.Jid jid,
                                        java.lang.CharSequence... features)
                                 throws org.jivesoftware.smack.SmackException.NoResponseException,
                                        org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                        org.jivesoftware.smack.SmackException.NotConnectedException,
                                        java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • supportsFeatures

        public boolean supportsFeatures​(org.jxmpp.jid.Jid jid,
                                        java.util.Collection<? extends java.lang.CharSequence> features)
                                 throws org.jivesoftware.smack.SmackException.NoResponseException,
                                        org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                        org.jivesoftware.smack.SmackException.NotConnectedException,
                                        java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • findServicesDiscoverInfo

        public java.util.List<DiscoverInfo> findServicesDiscoverInfo​(java.lang.String feature,
                                                                     boolean stopOnFirst,
                                                                     boolean useCache)
                                                              throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                                     org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                     org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                     java.lang.InterruptedException
        Find all services under the users service that provide a given feature.
        Parameters:
        feature - the feature to search for
        stopOnFirst - if true, stop searching after the first service was found
        useCache - if true, query a cache first to avoid network I/O
        Returns:
        a possible empty list of services providing the given feature
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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 org.jxmpp.jid.Jid,​java.lang.Exception> encounteredExceptions)
                                                              throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                                     org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                     org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                     java.lang.InterruptedException
        Find all services under the users service that provide a given feature.
        Parameters:
        feature - the feature to search for
        stopOnFirst - if true, stop searching after the first service was found
        useCache - if true, query a cache first to avoid network I/O
        encounteredExceptions - an optional map which will be filled with the exceptions encountered
        Returns:
        a possible empty list of services providing the given feature
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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​(org.jxmpp.jid.DomainBareJid serviceName,
                                                                     java.lang.String feature,
                                                                     boolean stopOnFirst,
                                                                     boolean useCache,
                                                                     java.util.Map<? super org.jxmpp.jid.Jid,​java.lang.Exception> encounteredExceptions)
                                                              throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                                     org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                     org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                     java.lang.InterruptedException
        Find all services under a given service that provide a given feature.
        Parameters:
        serviceName - the service to query
        feature - the feature to search for
        stopOnFirst - if true, stop searching after the first service was found
        useCache - if true, query a cache first to avoid network I/O
        encounteredExceptions - an optional map which will be filled with the exceptions encountered
        Returns:
        a possible empty list of services providing the given feature
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.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<org.jxmpp.jid.DomainBareJid> findServices​(java.lang.String feature,
                                                                        boolean stopOnFirst,
                                                                        boolean useCache)
                                                                 throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                                        org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                        org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                        java.lang.InterruptedException
        Find all services under the users service that provide a given feature.
        Parameters:
        feature - the feature to search for
        stopOnFirst - if true, stop searching after the first service was found
        useCache - if true, query a cache first to avoid network I/O
        Returns:
        a possible empty list of services providing the given feature
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
        org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • findService

        public org.jxmpp.jid.DomainBareJid findService​(java.lang.String feature,
                                                       boolean useCache,
                                                       java.lang.String category,
                                                       java.lang.String type)
                                                throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                       org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                       org.jivesoftware.smack.SmackException.NotConnectedException,
                                                       java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • findService

        public org.jxmpp.jid.DomainBareJid findService​(java.lang.String feature,
                                                       boolean useCache)
                                                throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                       org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                       org.jivesoftware.smack.SmackException.NotConnectedException,
                                                       java.lang.InterruptedException
        Throws:
        org.jivesoftware.smack.SmackException.NoResponseException
        org.jivesoftware.smack.XMPPException.XMPPErrorException
        org.jivesoftware.smack.SmackException.NotConnectedException
        java.lang.InterruptedException
      • addEntityCapabilitiesChangedListener

        public boolean addEntityCapabilitiesChangedListener​(EntityCapabilitiesChangedListener entityCapabilitiesChangedListener)
      • removeEntityCapabilitiesChangedListener

        public boolean removeEntityCapabilitiesChangedListener​(EntityCapabilitiesChangedListener entityCapabilitiesChangedListener)
      • addDiscoInfoLookupShortcutMechanism

        public static void addDiscoInfoLookupShortcutMechanism​(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)
      • removeDiscoInfoLookupShortcutMechanism

        public static void removeDiscoInfoLookupShortcutMechanism​(DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism)