Class EntityCapsManager


  • public final class EntityCapsManager
    extends org.jivesoftware.smack.Manager
    Manages own and others Entity Capabilities (XEP-0115).

    Entity Capabilities is an XMPP extension which, in order to minimize network impact, caches the capabilities of remote XMPP entities. Those capabilities are determine with the help of the Service Discovery Protocol (XEP-0030, ServiceDiscoveryManager).

    Usage

    Entity Capabilities work silently in the background when enabled. If the remote XMPP entity does not support XEP-0115 but XEP-0030 then XEP-0030 mechanisms are transparently used.

    The caches used by Smack for Entity Capabilities is non-persisent per default. However, it is is also possible to set a persistent Entity Capabilities cache, which is recommended.

    Examples

    Enable Entity Capabilities

    
     // Get an instance of entity caps manager for the specified connection
     EntityCapsManager mgr = EntityCapsManager.getInstanceFor(connection);
     // Enable entity capabilities
     mgr.enableEntityCaps();
     

    Configure a persistent cache for Entity Capabilities

    
     // Get an instance of entity caps manager for the specified connection
     EntityCapsManager mgr = EntityCapsManager.getInstanceFor(connection);
     // Create an cache, see smackx.entitycaps.cache for pre-defined cache implementations
     EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(new File("/foo/cachedir"));
     // Set the cache
     mgr.setPersistentCache(cache);
     
    See Also:
    XEP-0115: Entity Capabilities
    • Method Detail

      • setDefaultEntityNode

        public static void setDefaultEntityNode​(java.lang.String entityNode)
        Set the default entity node that will be used for new EntityCapsManagers.
        Parameters:
        entityNode - TODO javadoc me please
      • getNodeVersionByJid

        public static java.lang.String getNodeVersionByJid​(org.jxmpp.jid.Jid jid)
        Get the Node version (node#ver) of a JID. Returns a String or null if EntiyCapsManager does not have any information.
        Parameters:
        jid - TODO javadoc me please the user (Full JID)
        Returns:
        the node version (node#ver) or null
      • getDiscoverInfoByUser

        public static DiscoverInfo getDiscoverInfoByUser​(org.jxmpp.jid.Jid user)
        Get the discover info given a user name. The discover info is returned if the user has a node#ver associated with it and the node#ver has a discover info associated with it.
        Parameters:
        user - TODO javadoc me please user name (Full JID)
        Returns:
        the discovered info
      • getDiscoveryInfoByNodeVer

        public static DiscoverInfo getDiscoveryInfoByNodeVer​(java.lang.String nodeVer)
        Retrieve DiscoverInfo for a specific node.
        Parameters:
        nodeVer - TODO javadoc me please The node name (e.g. "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w=").
        Returns:
        The corresponding DiscoverInfo or null if none is known.
      • setPersistentCache

        public static void setPersistentCache​(EntityCapsPersistentCache cache)
        Set the persistent cache implementation.
        Parameters:
        cache - TODO javadoc me please
      • setMaxsCacheSizes

        public static void setMaxsCacheSizes​(int maxJidToNodeVerSize,
                                             int maxCapsCacheSize)
        Sets the maximum cache sizes.
        Parameters:
        maxJidToNodeVerSize - TODO javadoc me please
        maxCapsCacheSize - TODO javadoc me please
      • clearMemoryCache

        public static void clearMemoryCache()
        Clears the memory cache.
      • getInstanceFor

        public static EntityCapsManager getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)
      • enableEntityCaps

        public void enableEntityCaps()
      • disableEntityCaps

        public void disableEntityCaps()
      • entityCapsEnabled

        public boolean entityCapsEnabled()
      • removeUserCapsNode

        public static void removeUserCapsNode​(org.jxmpp.jid.Jid user)
        Remove a record telling what entity caps node a user has.
        Parameters:
        user - TODO javadoc me please the user (Full JID)
      • getCapsVersionAndHash

        public CapsVersionAndHash getCapsVersionAndHash()
        Get our own caps version or null if none is yet set. The version depends on the enabled features. A caps version looks like '66/0NaeaBKkwk85efJTGmU47vXI='
        Returns:
        our own caps version or null.
      • getLocalNodeVer

        public java.lang.String getLocalNodeVer()
        Returns the local entity's NodeVer (e.g. "http://www.igniterealtime.org/projects/smack/#66/0NaeaBKkwk85efJTGmU47vXI= )
        Returns:
        the local NodeVer
      • areEntityCapsSupported

        public boolean areEntityCapsSupported​(org.jxmpp.jid.Jid jid)
                                       throws org.jivesoftware.smack.SmackException.NoResponseException,
                                              org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                              org.jivesoftware.smack.SmackException.NotConnectedException,
                                              java.lang.InterruptedException
        Returns true if Entity Caps are supported by a given JID.
        Parameters:
        jid - TODO javadoc me please
        Returns:
        true if the entity supports Entity Capabilities.
        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.
      • areEntityCapsSupportedByServer

        public boolean areEntityCapsSupportedByServer()
                                               throws org.jivesoftware.smack.SmackException.NoResponseException,
                                                      org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                      org.jivesoftware.smack.SmackException.NotConnectedException,
                                                      java.lang.InterruptedException
        Returns true if Entity Caps are supported by the local service/server.
        Returns:
        true if the user's server supports Entity Capabilities.
        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.
      • verifyDiscoverInfoVersion

        public static boolean verifyDiscoverInfoVersion​(java.lang.String ver,
                                                        java.lang.String hash,
                                                        DiscoverInfo info)
        Verify DiscoverInfo and Caps Node as defined in XEP-0115 5.4 Processing Method.
        Parameters:
        ver - TODO javadoc me please
        hash - TODO javadoc me please
        info - TODO javadoc me please
        Returns:
        true if it's valid and should be cache, false if not
        See Also:
        XEP-0115 5.4 Processing Method