X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fjava%2Fdolda%2Fdolcon%2Fprotocol%2FConnection.java;h=43cf5a350a866c030c00a7635400e975b0e25015;hb=59b214d63f3e51473177f573bdc4c8edaa08f9ea;hp=31bb172c8712cbbddf2c1214f09a3639f39f427d;hpb=6bc193f2ce2a87a667e2a83aac01135520fdee26;p=doldaconnect.git diff --git a/lib/java/dolda/dolcon/protocol/Connection.java b/lib/java/dolda/dolcon/protocol/Connection.java index 31bb172..43cf5a3 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")); @@ -199,6 +212,7 @@ public class Connection { notifyAll(); } }; + qcmd(cmd); synchronized(l) { while(!donep[0]) { l.wait(); @@ -271,7 +285,9 @@ public class Connection { out.append(' '); out.append(quote(s)); } + out.append("\r\n"); w.write(out.toString()); + w.flush(); } } catch(IOException e) { throw(new StopCondition(e, false)); @@ -299,6 +315,12 @@ public class Connection { queue.notifyAll(); } resp.cmd.done(resp); + } else { + synchronized(notls) { + for(NotifyListener l : notls) { + l.notified(resp); + } + } } }