1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package fulmine.model.container.subscription.remote;
17
18 import static fulmine.util.Utils.nullCheck;
19
20 import java.util.Collection;
21
22 import fulmine.IAddressable;
23 import fulmine.context.IFrameworkContext;
24 import fulmine.event.listener.AbstractEventHandler;
25 import fulmine.event.listener.MultiSystemEventListener;
26 import fulmine.event.subscription.ISubscriptionFactory;
27 import fulmine.event.subscription.ISubscriptionParameters;
28 import fulmine.event.system.ISystemEventListener;
29 import fulmine.model.container.IContainer;
30 import fulmine.model.container.events.RemoteContainerCreatedEvent;
31 import fulmine.model.container.events.RemoteContainerDestroyedEvent;
32 import fulmine.model.container.subscription.ContainerSubscriptionManager;
33 import fulmine.util.log.AsyncLog;
34
35
36
37
38
39
40 public class RemoteContainerSubscriptionManager extends
41 ContainerSubscriptionManager
42 {
43 private final static AsyncLog LOG =
44 new AsyncLog(RemoteContainerSubscriptionManager.class);
45
46
47
48
49
50 private final String remoteContextIdentity;
51
52
53
54
55
56
57 private class RemoteContainerCreatedEventHandler extends
58 AbstractEventHandler<RemoteContainerCreatedEvent> implements
59 ISystemEventListener
60 {
61 @Override
62 public AsyncLog getLog()
63 {
64 return LOG;
65 }
66
67 @Override
68 public void handle(RemoteContainerCreatedEvent event)
69 {
70
71 if (RemoteContainerSubscriptionManager.this.remoteContextIdentity.equals(event.getRemoteContextIdentity()))
72 {
73 eventSourceCreated(event);
74 }
75 else
76 {
77 if (getLog().isDebugEnabled())
78 {
79 getLog().debug(
80 "Not handling "
81 + event
82 + " because the remote context identity does not match "
83 + RemoteContainerSubscriptionManager.this.remoteContextIdentity);
84 }
85 }
86 }
87 }
88
89
90
91
92
93
94 private class RemoteContainerDestroyedEventHandler extends
95 AbstractEventHandler<RemoteContainerDestroyedEvent> implements
96 ISystemEventListener
97 {
98 @Override
99 public AsyncLog getLog()
100 {
101 return LOG;
102 }
103
104 @Override
105 public void handle(RemoteContainerDestroyedEvent event)
106 {
107 if (RemoteContainerSubscriptionManager.this.remoteContextIdentity.equals(event.getRemoteContextIdentity()))
108 {
109 eventSourceDestroyed(event);
110 }
111 else
112 {
113 if (getLog().isDebugEnabled())
114 {
115 getLog().debug(
116 "Not handling "
117 + event
118 + " because the remote context identity does not match "
119 + RemoteContainerSubscriptionManager.this.remoteContextIdentity);
120 }
121 }
122 }
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136 @SuppressWarnings("unchecked")
137 public RemoteContainerSubscriptionManager(IFrameworkContext context,
138 String remoteContextIdentity, ISubscriptionFactory factory)
139 {
140 super(context, factory);
141 nullCheck(remoteContextIdentity, "No remote context identity");
142 this.remoteContextIdentity = remoteContextIdentity;
143 this.eventHandler =
144 new MultiSystemEventListener(this.getClass().getSimpleName(),
145 context, AbstractEventHandler.getEventHandlerMappings(
146 new RemoteContainerCreatedEventHandler(),
147 new RemoteContainerDestroyedEventHandler()));
148 }
149
150 @Override
151 protected AsyncLog getLog()
152 {
153 return LOG;
154 }
155
156 @Override
157 protected IContainer doGetEventSource(IAddressable id)
158 {
159 return getContext().getRemoteContainer(remoteContextIdentity,
160 id.getIdentity(), id.getType(), id.getDomain());
161 }
162
163 @Override
164 protected Collection<IContainer> doGetEventSources()
165 {
166 return getContext().getRemoteContainers(remoteContextIdentity);
167 }
168
169 @Override
170 protected boolean doEventSourceExists(IAddressable id)
171 {
172 return getContext().containsRemoteContainer(remoteContextIdentity,
173 id.getIdentity(), id.getType(), id.getDomain());
174 }
175
176 @Override
177 protected void doRaiseSubscribeEvent(ISubscriptionParameters parameters)
178 {
179
180 }
181
182 @Override
183 protected void doRaiseUnsubscribeEvent(ISubscriptionParameters parameters)
184 {
185
186 }
187 }