Author: baranowb
Date: Mon May 11 10:53:38 2009
New Revision: 5914

Modified:
trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/ConnectionImpl.java

Log:
change:
 - add basic listener support.

Modified: trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/ConnectionImpl.java
==============================================================================
--- trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/ConnectionImpl.java (original) +++ trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/ConnectionImpl.java Mon May 11 10:53:38 2009
@@ -15,6 +15,8 @@
 import org.mobicents.media.server.spi.Endpoint;
 import org.mobicents.media.server.spi.NotificationListener;

+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+
 /**
  *
  * @author kulikov
@@ -31,6 +33,9 @@
     protected Channel txChannel;
     protected Channel rxChannel;

+
+ protected ConcurrentHashMap connectionListeners = new ConcurrentHashMap();
+
     public ConnectionImpl(EndpointImpl endpoint, ConnectionMode mode) {
         this.id = genID();
         this.endpoint = endpoint;
@@ -60,7 +65,18 @@
     }

     protected void setState(ConnectionState state) {
+       ConnectionState oldState = this.state;
         this.state = state;
+
+        if(oldState!=this.state)
+        {
+               //FIXME: does this require sync, maybe we should add here tasks?
+               for(Object ocl: this.connectionListeners.keySet())
+               {
+                       ConnectionListener cl = (ConnectionListener) ocl;
+                       cl.onStateChange(this, oldState);
+               }
+        }
     }

     public int getLifeTime() {
@@ -95,11 +111,11 @@


     public void addListener(ConnectionListener listener) {
-        throw new UnsupportedOperationException("Not supported yet.");
+        this.connectionListeners.put(listener, listener);
     }

     public void removeListener(ConnectionListener listener) {
-        throw new UnsupportedOperationException("Not supported yet.");
+        this.connectionListeners.remove(listener);
     }

     public Component getComponent(int resourceID) {

Reply via email to