diff --git a/src/java/org/jivesoftware/multiplexer/ClientSession.java b/src/java/org/jivesoftware/multiplexer/ClientSession.java index 8fd4bc6..a7354b8 100644 --- a/src/java/org/jivesoftware/multiplexer/ClientSession.java +++ b/src/java/org/jivesoftware/multiplexer/ClientSession.java @@ -27,6 +27,17 @@ private static final String ETHERX_NAMESPACE = "http://etherx.jabber.org/streams"; private static final String FLASH_NAMESPACE = "http://www.jabber.com/streams/flash"; + private static ConnectionCloseListener closeListener; + + static { + closeListener = new ConnectionCloseListener() { + public void onConnectionClose(Object handback) { + ClientSession session = (ClientSession) handback; + // Mark the session as closed + session.close(false); + } + }; + } public static Session createSession(String serverName, XmlPullParser xpp, Connection connection) throws XmlPullParserException { @@ -106,13 +117,7 @@ // Set the stream ID that identifies the client when forwarding traffic to a client fails ((ClientFailoverDeliverer) connection.getPacketDeliverer()).setStreamID(streamID); // Listen when the connection is closed - connection.registerCloseListener(new ConnectionCloseListener() { - public void onConnectionClose(Object handback) { - ClientSession session = (ClientSession) handback; - // Mark the session as closed - session.close(false); - } - }, session); + connection.registerCloseListener(closeListener, session); // Register that the new session is associated with the specified stream ID Session.addSession(streamID, session); // Send to the server that a new client session has been created