Commit 11e32674 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Optimization - replaced Map with single listener entry with instance variable...

Optimization - replaced Map with single listener entry with instance variable that keeps the listener. E.g. 30K connections ==> 30K Maps. JM-925

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6655 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7289f363
......@@ -39,8 +39,6 @@ import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.security.KeyStore;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Implementation of {@link Connection} inteface specific for NIO connections when using
......@@ -60,8 +58,7 @@ public class NIOConnection implements Connection {
private Session session;
private IoSession ioSession;
final private Map<ConnectionCloseListener, Object> listeners =
new ConcurrentHashMap<ConnectionCloseListener, Object>();
private ConnectionCloseListener closeListener;
/**
* Deliverer to use when the connection is closed or was closed when delivering
......@@ -100,17 +97,22 @@ public class NIOConnection implements Connection {
return !isClosed();
}
public void registerCloseListener(ConnectionCloseListener listener, Object handbackMessage) {
public void registerCloseListener(ConnectionCloseListener listener, Object ignore) {
if (closeListener != null) {
throw new IllegalStateException("Close listener already configured");
}
if (isClosed()) {
listener.onConnectionClose(handbackMessage);
listener.onConnectionClose(session);
}
else {
listeners.put(listener, handbackMessage);
closeListener = listener;
}
}
public void removeCloseListener(ConnectionCloseListener listener) {
listeners.remove(listener);
if (closeListener == listener) {
closeListener = null;
}
}
public InetAddress getInetAddress() throws UnknownHostException {
......@@ -167,12 +169,11 @@ public class NIOConnection implements Connection {
* Used by subclasses to properly finish closing the connection.
*/
private void notifyCloseListeners() {
for (Map.Entry<ConnectionCloseListener,Object> entry : listeners.entrySet()) {
if (closeListener != null) {
try {
entry.getKey().onConnectionClose(entry.getValue());
}
catch (Exception e) {
Log.error("Error notifying listener: " + entry.getKey(), e);
closeListener.onConnectionClose(session);
} catch (Exception e) {
Log.error("Error notifying listener: " + closeListener, e);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment