mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42:06 +01:00
SMACK-361 Minor EntityCapsManager fixes
Don't use the constructor in ConnectionCreationListener to prevent duplicate instances for the same connection. Fixed EntityCaps documentation. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_2@13799 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
84e1f32284
commit
0e6817dc4f
2 changed files with 4 additions and 15 deletions
|
@ -33,7 +33,7 @@ Enable Entity Capabilities
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
<font color="#3f7f5f">// Get an instance of entity caps manager for the specified connection</font>
|
<font color="#3f7f5f">// Get an instance of entity caps manager for the specified connection</font>
|
||||||
Entity CapabilitiesManager mgr = new EntityCapsManager.getInstanceFor(con);
|
EntityCapsManager mgr = EntityCapsManager.getInstanceFor(connection);
|
||||||
|
|
||||||
<font color="#3f7f5f">// Enable entity capabilities</font>
|
<font color="#3f7f5f">// Enable entity capabilities</font>
|
||||||
mgr.enableEntityCaps();
|
mgr.enableEntityCaps();
|
||||||
|
@ -45,7 +45,7 @@ Configure a persistent cache for Entity Capabilities
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
<font color="#3f7f5f">// Get an instance of entity caps manager for the specified connection</font>
|
<font color="#3f7f5f">// Get an instance of entity caps manager for the specified connection</font>
|
||||||
Entity CapabilitiesManager mgr = new EntityCapsManager.getInstanceFor(con);
|
EntityCapsManager mgr = EntityCapsManager.getInstanceFor(connection);
|
||||||
|
|
||||||
<font color="#3f7f5f">// Create an cache, see smackx.entitycaps.cache for pre-defined cache implementations</font>
|
<font color="#3f7f5f">// Create an cache, see smackx.entitycaps.cache for pre-defined cache implementations</font>
|
||||||
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(new File("/foo/cachedir"));
|
EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(new File("/foo/cachedir"));
|
||||||
|
|
|
@ -99,8 +99,7 @@ public class EntityCapsManager {
|
||||||
static {
|
static {
|
||||||
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
|
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||||
public void connectionCreated(Connection connection) {
|
public void connectionCreated(Connection connection) {
|
||||||
if (connection instanceof XMPPConnection)
|
getInstanceFor(connection);
|
||||||
new EntityCapsManager(connection);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -225,11 +224,6 @@ public class EntityCapsManager {
|
||||||
private EntityCapsManager(Connection connection) {
|
private EntityCapsManager(Connection connection) {
|
||||||
this.weakRefConnection = new WeakReference<Connection>(connection);
|
this.weakRefConnection = new WeakReference<Connection>(connection);
|
||||||
this.sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
this.sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
Connection connection = weakRefConnection.get();
|
|
||||||
instances.put(connection, this);
|
instances.put(connection, this);
|
||||||
|
|
||||||
connection.addConnectionListener(new ConnectionListener() {
|
connection.addConnectionListener(new ConnectionListener() {
|
||||||
|
@ -326,13 +320,8 @@ public class EntityCapsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized EntityCapsManager getInstanceFor(Connection connection) {
|
public static synchronized EntityCapsManager getInstanceFor(Connection connection) {
|
||||||
// For testing purposed forbid EntityCaps for non XMPPConnections
|
|
||||||
// it may work on BOSH connections too
|
|
||||||
if (!(connection instanceof XMPPConnection))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (SUPPORTED_HASHES.size() <= 0)
|
if (SUPPORTED_HASHES.size() <= 0)
|
||||||
return null;
|
throw new IllegalStateException("No supported hashes for EntityCapsManager");
|
||||||
|
|
||||||
EntityCapsManager entityCapsManager = instances.get(connection);
|
EntityCapsManager entityCapsManager = instances.get(connection);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue