Java: Added ecmd to the connection manager.
[doldaconnect.git] / lib / java / dolda / dolcon / protocol / Command.java
CommitLineData
1335284e 1package dolda.dolcon.protocol;
e78d9ca3
FT
2
3import java.util.*;
4
5public class Command {
6 List<String> tokens;
7 Set<Listener> listeners = new HashSet<Listener>();
8 Response resp;
9
6bc193f2
FT
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);
e78d9ca3
FT
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
6bc193f2 27 private synchronized void addlst(Listener l) {
e78d9ca3
FT
28 listeners.add(l);
29 }
30
6bc193f2 31 public synchronized void done(Response resp) throws Exception {
e78d9ca3
FT
32 this.resp = resp;
33 for(Listener l : listeners)
34 l.done(resp);
35 }
36
6bc193f2 37 public synchronized void error(Exception cause) {
e78d9ca3
FT
38 for(Listener l : listeners)
39 l.error(cause);
40 }
41}