1
package org.jboss.remoting;
3
import java.util.Collections;
4
import java.util.Iterator;
6
import java.util.ArrayList;
8
import org.jboss.logging.Logger;
11
* This class is used on the server side to notify any connection listeners when a client connection
12
* has been terminated (either by loss of lease or by normal disconnect).
14
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
16
public class ConnectionNotifier
18
private List listeners = Collections.synchronizedList(new ArrayList());
20
private static final Logger log = Logger.getLogger(ConnectionNotifier.class);
22
public void addListener(ConnectionListener listener)
24
listeners.add(listener);
27
public void addListenerFirst(ConnectionListener listener)
29
listeners.add(0, listener);
32
public void removeListener(ConnectionListener listener)
34
listeners.remove(listener);
39
return listeners.size();
42
public void connectionLost(String locatorurl, String clientSessionId, Map requestPayload)
46
log.debug(this + " Server connection lost to client (session id = " + clientSessionId);
47
Client client = new Client(new InvokerLocator(locatorurl), requestPayload);
48
client.setSessionId(clientSessionId);
50
ArrayList localListeners = null;
51
synchronized (listeners)
53
localListeners = new ArrayList(listeners);
56
Iterator it = localListeners.iterator();
59
ConnectionListener listener = (ConnectionListener) it.next();
60
listener.handleConnectionException(null, client);
61
log.debug(this + " notified " + listener + " of connection lost to: " + clientSessionId);
66
log.error("Error notifying connection listeners of lost client connection.", e);
70
public void connectionTerminated(String locatorURL, String clientSessionId, Map requestPayload)
74
if(log.isTraceEnabled())
76
log.trace(this + " Client disconnected (session id = " + clientSessionId);
78
Client client = new Client(new InvokerLocator(locatorURL), requestPayload);
79
client.setSessionId(clientSessionId);
80
ClientDisconnectedException ex = new ClientDisconnectedException();
82
ArrayList localListeners = null;
83
synchronized (listeners)
85
localListeners = new ArrayList(listeners);
88
Iterator it = localListeners.iterator();
91
((ConnectionListener) it.next()).handleConnectionException(ex, client);
96
log.error("Error notifying connection listeners of disconnected client connection.", e);