Package org.jivesoftware.smackx.caps
Class EntityCapsManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.caps.EntityCapsManager
-
public final class EntityCapsManager extends 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EntityCapsManager.NodeVerHash
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
areEntityCapsSupported(Jid jid)
Returns true if Entity Caps are supported by a given JID.boolean
areEntityCapsSupportedByServer()
Returns true if Entity Caps are supported by the local service/server.static void
clearMemoryCache()
Clears the memory cache.void
disableEntityCaps()
void
enableEntityCaps()
boolean
entityCapsEnabled()
CapsVersionAndHash
getCapsVersionAndHash()
Get our own caps version ornull
if none is yet set.static DiscoverInfo
getDiscoverInfoByUser(Jid user)
Get the discover info given a user name.static DiscoverInfo
getDiscoveryInfoByNodeVer(String nodeVer)
Retrieve DiscoverInfo for a specific node.static EntityCapsManager
getInstanceFor(XMPPConnection connection)
String
getLocalNodeVer()
Returns the local entity's NodeVer (e.g.static EntityCapsManager.NodeVerHash
getNodeVerHashByJid(Jid jid)
static String
getNodeVersionByJid(Jid jid)
Get the Node version (node#ver) of a JID.static void
removeUserCapsNode(Jid user)
Remove a record telling what entity caps node a user has.static void
setDefaultEntityNode(String entityNode)
Set the default entity node that will be used for new EntityCapsManagers.static void
setMaxsCacheSizes(int maxJidToNodeVerSize, int maxCapsCacheSize)
Sets the maximum cache sizes.static void
setPersistentCache(EntityCapsPersistentCache cache)
Set the persistent cache implementation.static boolean
verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info)
Verify DiscoverInfo and Caps Node as defined in XEP-0115 5.4 Processing Method.-
Methods inherited from class org.jivesoftware.smack.Manager
connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
-
-
-
-
Field Detail
-
NAMESPACE
public static final String NAMESPACE
- See Also:
- Constant Field Values
-
ELEMENT
public static final String ELEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setDefaultEntityNode
public static void setDefaultEntityNode(String entityNode)
Set the default entity node that will be used for new EntityCapsManagers.- Parameters:
entityNode
- TODO javadoc me please
-
getNodeVersionByJid
public static String getNodeVersionByJid(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
-
getNodeVerHashByJid
public static EntityCapsManager.NodeVerHash getNodeVerHashByJid(Jid jid)
-
getDiscoverInfoByUser
public static DiscoverInfo getDiscoverInfoByUser(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(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 pleasemaxCapsCacheSize
- TODO javadoc me please
-
clearMemoryCache
public static void clearMemoryCache()
Clears the memory cache.
-
getInstanceFor
public static EntityCapsManager getInstanceFor(XMPPConnection connection)
-
enableEntityCaps
public void enableEntityCaps()
-
disableEntityCaps
public void disableEntityCaps()
-
entityCapsEnabled
public boolean entityCapsEnabled()
-
removeUserCapsNode
public static void removeUserCapsNode(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 ornull
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 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(Jid jid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, 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:
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.InterruptedException
- if the calling thread was interrupted.
-
areEntityCapsSupportedByServer
public boolean areEntityCapsSupportedByServer() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
Returns true if Entity Caps are supported by the local service/server.- Returns:
- true if the user's server supports Entity Capabilities.
- 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.InterruptedException
- if the calling thread was interrupted.
-
verifyDiscoverInfoVersion
public static boolean verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info)
Verify DiscoverInfo and Caps Node as defined in XEP-0115 5.4 Processing Method.- Parameters:
ver
- TODO javadoc me pleasehash
- TODO javadoc me pleaseinfo
- 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
-
-