From 1505a392760fb7941871183ea9e7c9be90ee2273 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 27 Jan 2008 22:22:17 +0100 Subject: [PATCH] Java: Added NotifyListeners. --- lib/java/dolda/dolcon/protocol/Connection.java | 21 ++++++++++++++++++++- lib/java/dolda/dolcon/protocol/NotifyListener.java | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/java/dolda/dolcon/protocol/NotifyListener.java diff --git a/lib/java/dolda/dolcon/protocol/Connection.java b/lib/java/dolda/dolcon/protocol/Connection.java index 31bb172..03152bc 100644 --- a/lib/java/dolda/dolcon/protocol/Connection.java +++ b/lib/java/dolda/dolcon/protocol/Connection.java @@ -14,13 +14,14 @@ public class Connection { private String aspec; private String state; private Set connls = new HashSet(); + private Set notls = new HashSet(); 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 index 0000000..79c958a --- /dev/null +++ b/lib/java/dolda/dolcon/protocol/NotifyListener.java @@ -0,0 +1,5 @@ +package dolda.dolcon.protocol; + +public interface NotifyListener { + public void notified(Response resp) throws Exception; +} -- 2.11.0