Java: Added ecmd to the connection manager.
[doldaconnect.git] / lib / java / dolda / dolcon / protocol / Command.java
1 package dolda.dolcon.protocol;
2
3 import java.util.*;
4
5 public class Command {
6     List<String> tokens;
7     Set<Listener> listeners = new HashSet<Listener>();
8     Response resp;
9     
10     public abstract class Listener {
11         public Listener() {
12             addlst(this);
13         }
14         
15         public abstract void done(Response resp) throws Exception;
16         public abstract void error(Exception cause);
17     }
18
19     public Command(List<String> tokens) {
20         this.tokens = tokens;
21     }
22     
23     public Command(String... tokens) {
24         this(Arrays.asList(tokens));
25     }
26     
27     private synchronized void addlst(Listener l) {
28         listeners.add(l);
29     }
30     
31     public synchronized void done(Response resp) throws Exception {
32         this.resp = resp;
33         for(Listener l : listeners)
34             l.done(resp);
35     }
36     
37     public synchronized void error(Exception cause) {
38         for(Listener l : listeners)
39             l.error(cause);
40     }
41 }