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";
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"));
}
}
- public void qcmd(Command cmd) {
+ public void qcmd(Command... cmds) {
synchronized(queue) {
- queue.offer(cmd);
+ for(Command cmd : cmds)
+ queue.offer(cmd);
queue.notifyAll();
}
}
notifyAll();
}
};
+ qcmd(cmd);
synchronized(l) {
while(!donep[0]) {
l.wait();
out.append(' ');
out.append(quote(s));
}
+ out.append("\r\n");
w.write(out.toString());
+ w.flush();
}
} catch(IOException e) {
throw(new StopCondition(e, false));
queue.notifyAll();
}
resp.cmd.done(resp);
+ } else {
+ synchronized(notls) {
+ for(NotifyListener l : notls) {
+ l.notified(resp);
+ }
+ }
}
}
code = Integer.parseInt(ct.toString());
ct.setLength(0);
state = "start";
- continue eat;
} else {
ct.append(c);
}