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