From 0e6817dc4fed1109afe2b4664ecaab3883296622 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 3 Nov 2013 21:49:39 +0000 Subject: [PATCH] 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 --- documentation/extensions/caps.html | 4 ++-- .../smackx/entitycaps/EntityCapsManager.java | 15 ++------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/documentation/extensions/caps.html b/documentation/extensions/caps.html index 71e0e2f77..f22fa2ce3 100644 --- a/documentation/extensions/caps.html +++ b/documentation/extensions/caps.html @@ -33,7 +33,7 @@ Enable Entity Capabilities
       // Get an instance of entity caps manager for the specified connection
-      Entity CapabilitiesManager mgr = new EntityCapsManager.getInstanceFor(con);
+      EntityCapsManager mgr = EntityCapsManager.getInstanceFor(connection);
 
       // Enable entity capabilities
       mgr.enableEntityCaps();
@@ -45,7 +45,7 @@ Configure a persistent cache for Entity Capabilities
 
       // Get an instance of entity caps manager for the specified connection
-      Entity CapabilitiesManager mgr = new EntityCapsManager.getInstanceFor(con);
+      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"));
diff --git a/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java b/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java
index 1893288ab..afce78bbe 100644
--- a/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java
+++ b/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java
@@ -99,8 +99,7 @@ public class EntityCapsManager {
     static {
         Connection.addConnectionCreationListener(new ConnectionCreationListener() {
             public void connectionCreated(Connection connection) {
-                if (connection instanceof XMPPConnection)
-                    new EntityCapsManager(connection);
+                getInstanceFor(connection);
             }
         });
 
@@ -225,11 +224,6 @@ public class EntityCapsManager {
     private EntityCapsManager(Connection connection) {
         this.weakRefConnection = new WeakReference(connection);
         this.sdm = ServiceDiscoveryManager.getInstanceFor(connection);
-        init();
-    }
-
-    private void init() {
-        Connection connection = weakRefConnection.get();
         instances.put(connection, this);
 
         connection.addConnectionListener(new ConnectionListener() {
@@ -326,13 +320,8 @@ public class EntityCapsManager {
     }
 
     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)
-            return null;
+            throw new IllegalStateException("No supported hashes for EntityCapsManager");
 
         EntityCapsManager entityCapsManager = instances.get(connection);