1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mirrormap;
17
18 import java.io.Serializable;
19 import java.util.Map.Entry;
20
21 import mirrormap.commands.ICommand;
22 import mirrormap.nio.IConnectionEndPointReceiver;
23
24
25
26
27
28
29
30 class ClientCommandReceiver extends ServerCommandReceiver implements
31 IConnectionEndPointReceiver
32 {
33 ClientCommandReceiver()
34 {
35 super();
36 }
37
38
39
40
41
42
43
44
45
46
47 public boolean addListener(String mirrorMapName)
48 {
49 synchronized (this.listeners)
50 {
51 if (this.listeners.containsKey(mirrorMapName))
52 {
53 return false;
54 }
55 ConnectionEndPointMapListener listener =
56 new ConnectionEndPointMapListener(this.connectionEndPoint,
57 mirrorMapName);
58 this.listeners.put(mirrorMapName, listener);
59 final MirrorMap<Serializable, Serializable> mirrorMap =
60 MirrorMap.get(mirrorMapName);
61 if (mirrorMap == null)
62 {
63 return false;
64 }
65 return mirrorMap.addListener(listener);
66 }
67 }
68
69
70
71
72
73
74
75
76 public void removeListener(String mirrorMapName)
77 {
78 synchronized (this.listeners)
79 {
80 ConnectionEndPointMapListener listener =
81 this.listeners.remove(mirrorMapName);
82 if (listener != null)
83 {
84 final MirrorMap<Serializable, Serializable> mirrorMap =
85 MirrorMap.get(mirrorMapName);
86 if (mirrorMap != null)
87 {
88 mirrorMap.removeListener(listener);
89 }
90 }
91 }
92 }
93
94 @Override
95 protected void doReceive(ICommand command)
96 {
97 executeCommand(command);
98 }
99
100 @Override
101 protected void destroyListener(
102 Entry<String, ConnectionEndPointMapListener> entry)
103 {
104 MirrorMap.disconnect(MirrorMap.get(entry.getKey()));
105 super.destroyListener(entry);
106 }
107 }