~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/ConnectionNotifier.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jboss.remoting;
 
2
 
 
3
import java.util.Collections;
 
4
import java.util.Iterator;
 
5
import java.util.List;
 
6
import java.util.ArrayList;
 
7
import java.util.Map;
 
8
import org.jboss.logging.Logger;
 
9
 
 
10
/**
 
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).
 
13
 *
 
14
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
 
15
 */
 
16
public class ConnectionNotifier
 
17
{
 
18
   private List listeners = Collections.synchronizedList(new ArrayList());
 
19
 
 
20
   private static final Logger log = Logger.getLogger(ConnectionNotifier.class);
 
21
 
 
22
   public void addListener(ConnectionListener listener)
 
23
   {
 
24
      listeners.add(listener);
 
25
   }
 
26
   
 
27
   public void addListenerFirst(ConnectionListener listener)
 
28
   {
 
29
      listeners.add(0, listener);
 
30
   }
 
31
 
 
32
   public void removeListener(ConnectionListener listener)
 
33
   {
 
34
      listeners.remove(listener);
 
35
   }
 
36
 
 
37
   public int size()
 
38
   {
 
39
      return listeners.size();
 
40
   }
 
41
 
 
42
   public void connectionLost(String locatorurl, String clientSessionId, Map requestPayload)
 
43
   {
 
44
      try
 
45
      {
 
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);
 
49
         
 
50
         ArrayList localListeners = null;
 
51
         synchronized (listeners)
 
52
         {
 
53
            localListeners = new ArrayList(listeners);
 
54
         }
 
55
         
 
56
         Iterator it = localListeners.iterator();
 
57
         while (it.hasNext())
 
58
         {
 
59
            ConnectionListener listener = (ConnectionListener) it.next();
 
60
            listener.handleConnectionException(null, client);
 
61
            log.debug(this + " notified " + listener + " of connection lost to: " + clientSessionId);
 
62
         }
 
63
      }
 
64
      catch(Exception e)
 
65
      {
 
66
         log.error("Error notifying connection listeners of lost client connection.", e);
 
67
      }
 
68
   }
 
69
 
 
70
   public void connectionTerminated(String locatorURL, String clientSessionId, Map requestPayload)
 
71
   {
 
72
      try
 
73
      {
 
74
         if(log.isTraceEnabled())
 
75
         {
 
76
            log.trace(this + " Client disconnected (session id = " + clientSessionId);
 
77
         }
 
78
         Client client = new Client(new InvokerLocator(locatorURL), requestPayload);
 
79
         client.setSessionId(clientSessionId);
 
80
         ClientDisconnectedException ex = new ClientDisconnectedException();
 
81
         
 
82
         ArrayList localListeners = null;
 
83
         synchronized (listeners)
 
84
         {
 
85
            localListeners = new ArrayList(listeners);
 
86
         }
 
87
         
 
88
         Iterator it = localListeners.iterator();
 
89
         while (it.hasNext())
 
90
         {
 
91
            ((ConnectionListener) it.next()).handleConnectionException(ex, client);
 
92
         }
 
93
      }
 
94
      catch(Exception e)
 
95
      {
 
96
         log.error("Error notifying connection listeners of disconnected client connection.", e);
 
97
      }
 
98
   }
 
99
}