X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fjava%2Fdolda%2Fdolcon%2Fprotocol%2FConnection.java;h=b596639cce4c3f2c87f1a8a07d90978371afff2c;hb=java;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..b596639 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")); @@ -170,9 +183,10 @@ public class Connection { } } - public void qcmd(Command cmd) { + public void qcmd(Command... cmds) { synchronized(queue) { - queue.offer(cmd); + for(Command cmd : cmds) + queue.offer(cmd); queue.notifyAll(); } } @@ -199,6 +213,7 @@ public class Connection { notifyAll(); } }; + qcmd(cmd); synchronized(l) { while(!donep[0]) { l.wait(); @@ -271,7 +286,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 +316,12 @@ public class Connection { queue.notifyAll(); } resp.cmd.done(resp); + } else { + synchronized(notls) { + for(NotifyListener l : notls) { + l.notified(resp); + } + } } } @@ -359,7 +382,6 @@ public class Connection { code = Integer.parseInt(ct.toString()); ct.setLength(0); state = "start"; - continue eat; } else { ct.append(c); }