1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-15 20:12:04 +01:00

SMACK-462 Use getInstace() ConnectionCreationListener

Prevent duplicate instances of a manager by using it's getInstance()
method instead of the manager's constructor.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_2@13800 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2013-11-03 21:49:58 +00:00 committed by flow
parent 0e6817dc4f
commit 49573866ab
5 changed files with 10 additions and 8 deletions

View file

@ -58,7 +58,7 @@ public class PrivacyListManager {
// instance when the connection is closed. // instance when the connection is closed.
Connection.addConnectionCreationListener(new ConnectionCreationListener() { Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) { public void connectionCreated(Connection connection) {
new PrivacyListManager(connection); getInstanceFor(connection);
} }
}); });
} }
@ -129,8 +129,10 @@ public class PrivacyListManager {
* @param connection the connection used to look for the proper PrivacyListManager. * @param connection the connection used to look for the proper PrivacyListManager.
* @return the PrivacyListManager associated with a given Connection. * @return the PrivacyListManager associated with a given Connection.
*/ */
public static PrivacyListManager getInstanceFor(Connection connection) { public static synchronized PrivacyListManager getInstanceFor(Connection connection) {
return instances.get(connection); PrivacyListManager plm = instances.get(connection);
if (plm == null) plm = new PrivacyListManager(connection);
return plm;
} }
/** /**

View file

@ -59,7 +59,7 @@ public class KeepAliveManager {
if (SmackConfiguration.getKeepAliveInterval() > 0) { if (SmackConfiguration.getKeepAliveInterval() > 0) {
Connection.addConnectionCreationListener(new ConnectionCreationListener() { Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) { public void connectionCreated(Connection connection) {
new KeepAliveManager(connection); getInstanceFor(connection);
} }
}); });
} }

View file

@ -83,7 +83,7 @@ public class AdHocCommandManager {
static { static {
Connection.addConnectionCreationListener(new ConnectionCreationListener() { Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) { public void connectionCreated(Connection connection) {
new AdHocCommandManager(connection); getAddHocCommandsManager(connection);
} }
}); });
} }

View file

@ -60,7 +60,7 @@ public class PingManager {
static { static {
Connection.addConnectionCreationListener(new ConnectionCreationListener() { Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) { public void connectionCreated(Connection connection) {
new PingManager(connection); getInstanceFor(connection);
} }
}); });
} }

View file

@ -47,7 +47,7 @@ public class DeliveryReceiptManager implements PacketListener {
static { static {
Connection.addConnectionCreationListener(new ConnectionCreationListener() { Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) { public void connectionCreated(Connection connection) {
new DeliveryReceiptManager(connection); getInstanceFor(connection);
} }
}); });
} }
@ -74,7 +74,7 @@ public class DeliveryReceiptManager implements PacketListener {
* *
* @return the DeliveryReceiptManager instance for the given connection * @return the DeliveryReceiptManager instance for the given connection
*/ */
synchronized public static DeliveryReceiptManager getInstanceFor(Connection connection) { public static synchronized DeliveryReceiptManager getInstanceFor(Connection connection) {
DeliveryReceiptManager receiptManager = instances.get(connection); DeliveryReceiptManager receiptManager = instances.get(connection);
if (receiptManager == null) { if (receiptManager == null) {