Java: Added NotifyListeners.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 27 Jan 2008 21:22:17 +0000 (22:22 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 27 Jan 2008 21:22:17 +0000 (22:22 +0100)
lib/java/dolda/dolcon/protocol/Connection.java
lib/java/dolda/dolcon/protocol/NotifyListener.java [new file with mode: 0644]

index 31bb172..03152bc 100644 (file)
@@ -14,13 +14,14 @@ public class Connection {
     private String aspec;
     private String state;
     private Set<ConnectListener> connls = new HashSet<ConnectListener>();
+    private Set<NotifyListener> notls = new HashSet<NotifyListener>();
     private Exception error;
     
     public interface ConnectListener {
        public void connected() throws Exception;
        public void error(Exception cause);
     }
-
+    
     public Connection(String aspec) {
        this.aspec = aspec;
        state = "idle";
@@ -162,6 +163,18 @@ public class Connection {
        return(error);
     }
 
+    public void addNotifyListener(NotifyListener l) {
+       synchronized(notls) {
+           notls.add(l);
+       }
+    }
+
+    public void removeNotifyListener(NotifyListener l) {
+       synchronized(notls) {
+           notls.remove(l);
+       }
+    }
+
     public synchronized void addConnectListener(ConnectListener l) {
        if((state != "idle") && (state != "connecting"))
            throw(new IllegalStateException("Already connected"));
@@ -299,6 +312,12 @@ public class Connection {
                    queue.notifyAll();
                }
                resp.cmd.done(resp);
+           } else {
+               synchronized(notls) {
+                   for(NotifyListener l : notls) {
+                       l.notified(resp);
+                   }
+               }
            }
        }
 
diff --git a/lib/java/dolda/dolcon/protocol/NotifyListener.java b/lib/java/dolda/dolcon/protocol/NotifyListener.java
new file mode 100644 (file)
index 0000000..79c958a
--- /dev/null
@@ -0,0 +1,5 @@
+package dolda.dolcon.protocol;
+
+public interface NotifyListener {
+    public void notified(Response resp) throws Exception;
+}