Lines 19-24
Link Here
|
19 |
import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription; |
19 |
import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription; |
20 |
import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication; |
20 |
import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication; |
21 |
import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; |
21 |
import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; |
|
|
22 |
import org.eclipse.ecf.osgi.services.distribution.IRemoteServiceContainerFinder; |
22 |
import org.eclipse.ecf.remoteservice.*; |
23 |
import org.eclipse.ecf.remoteservice.*; |
23 |
import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent; |
24 |
import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent; |
24 |
import org.eclipse.ecf.remoteservice.events.IRemoteServiceUnregisteredEvent; |
25 |
import org.eclipse.ecf.remoteservice.events.IRemoteServiceUnregisteredEvent; |
Lines 27-33
Link Here
|
27 |
import org.osgi.framework.ServiceRegistration; |
28 |
import org.osgi.framework.ServiceRegistration; |
28 |
import org.osgi.service.discovery.*; |
29 |
import org.osgi.service.discovery.*; |
29 |
|
30 |
|
30 |
public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker { |
31 |
public class DiscoveredServiceTrackerImpl implements DiscoveredServiceTracker, |
|
|
32 |
IRemoteServiceContainerFinder { |
31 |
|
33 |
|
32 |
DistributionProviderImpl distributionProvider; |
34 |
DistributionProviderImpl distributionProvider; |
33 |
|
35 |
|
Lines 49-54
Link Here
|
49 |
ECFServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION, |
51 |
ECFServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION, |
50 |
ECFServicePublication.PROP_KEY_SERVICE_PROPERTIES }); |
52 |
ECFServicePublication.PROP_KEY_SERVICE_PROPERTIES }); |
51 |
|
53 |
|
|
|
54 |
// Impl of IRemoteServiceContainerFinder |
55 |
public IRemoteServiceContainer[] findRemoteServiceContainers( |
56 |
ECFServiceEndpointDescription endpointDescription) { |
57 |
return findRSCAs(endpointDescription.getECFEndpointID(), |
58 |
endpointDescription); |
59 |
} |
60 |
|
52 |
/* |
61 |
/* |
53 |
* (non-Javadoc) |
62 |
* (non-Javadoc) |
54 |
* |
63 |
* |
Lines 108-113
Link Here
|
108 |
} |
117 |
} |
109 |
} |
118 |
} |
110 |
|
119 |
|
|
|
120 |
private IRemoteServiceContainer[] findRemoteServiceContainersViaService( |
121 |
ECFServiceEndpointDescription description) { |
122 |
IRemoteServiceContainerFinder[] finders = Activator.getDefault() |
123 |
.getRemoteServiceContainerFinders(); |
124 |
if (finders == null || finders.length == 0) |
125 |
return new IRemoteServiceContainer[0]; |
126 |
List result = new ArrayList(); |
127 |
for (int i = 0; i < finders.length; i++) { |
128 |
IRemoteServiceContainer[] foundRSContainers = finders[i] |
129 |
.findRemoteServiceContainers(description); |
130 |
if (foundRSContainers != null && foundRSContainers.length > 0) { |
131 |
for (int j = 0; j < foundRSContainers.length; j++) |
132 |
result.add(foundRSContainers[j]); |
133 |
} |
134 |
} |
135 |
return (IRemoteServiceContainer[]) result |
136 |
.toArray(new IRemoteServiceContainer[] {}); |
137 |
} |
138 |
|
111 |
private void handleDiscoveredServiceAvailable(ServiceEndpointDescription sed) { |
139 |
private void handleDiscoveredServiceAvailable(ServiceEndpointDescription sed) { |
112 |
// If the service endpoint description is not ECF's then we |
140 |
// If the service endpoint description is not ECF's then we |
113 |
// don't process it |
141 |
// don't process it |
Lines 118-134
Link Here
|
118 |
|
146 |
|
119 |
ID endpointID = ecfSED.getECFEndpointID(); |
147 |
ID endpointID = ecfSED.getECFEndpointID(); |
120 |
// Find RSCAs for the given description |
148 |
// Find RSCAs for the given description |
121 |
ContainerAdapterHelper[] cahs = findRSCAs(endpointID, ecfSED); |
149 |
// IRemoteServiceContainer[] rsContainers = findRSCAs(endpointID, |
122 |
if (cahs == null || cahs.length == 0) { |
150 |
// ecfSED); |
|
|
151 |
IRemoteServiceContainer[] rsContainers = findRemoteServiceContainersViaService(ecfSED); |
152 |
if (rsContainers == null || rsContainers.length == 0) { |
123 |
logError("handleDiscoveredServiceAvailable", |
153 |
logError("handleDiscoveredServiceAvailable", |
124 |
"No RemoteServiceContainerAdapters found for description=" |
154 |
"No RemoteServiceContainerAdapters found for description=" |
125 |
+ ecfSED, null); |
155 |
+ ecfSED, null); |
126 |
return; |
156 |
return; |
127 |
} |
157 |
} |
128 |
// Give warning if more than one ContainerAdapterHelper found |
158 |
// Give warning if more than one ContainerAdapterHelper found |
129 |
if (cahs.length > 1) { |
159 |
if (rsContainers.length > 1) { |
130 |
logWarning("handleDiscoveredServiceAvailable", |
160 |
logWarning("handleDiscoveredServiceAvailable", |
131 |
"Multiple remote service containers=" + Arrays.asList(cahs) |
161 |
"Multiple remote service containers=" |
|
|
162 |
+ Arrays.asList(rsContainers) |
132 |
+ " found for service endpoint description=" |
163 |
+ " found for service endpoint description=" |
133 |
+ ecfSED); |
164 |
+ ecfSED); |
134 |
} |
165 |
} |
Lines 136-154
Link Here
|
136 |
// Get futureRemoteReferences...then create a thread |
167 |
// Get futureRemoteReferences...then create a thread |
137 |
// to process the future |
168 |
// to process the future |
138 |
Collection providedInterfaces = ecfSED.getProvidedInterfaces(); |
169 |
Collection providedInterfaces = ecfSED.getProvidedInterfaces(); |
139 |
for (int i = 0; i < cahs.length; i++) { |
170 |
for (int i = 0; i < rsContainers.length; i++) { |
140 |
for (Iterator j = providedInterfaces.iterator(); j.hasNext();) { |
171 |
for (Iterator j = providedInterfaces.iterator(); j.hasNext();) { |
141 |
String providedInterface = (String) j.next(); |
172 |
String providedInterface = (String) j.next(); |
142 |
// Use async call to prevent blocking here |
173 |
// Use async call to prevent blocking here |
143 |
trace("handleDiscoveredServiceAvailable", "rsca=" + cahs[i] |
174 |
trace("handleDiscoveredServiceAvailable", "rsca=" |
144 |
+ ",intf=" + providedInterface); |
175 |
+ rsContainers[i] + ",intf=" + providedInterface); |
145 |
IFuture futureRemoteReferences = cahs[i].getRSCA() |
176 |
IFuture futureRemoteReferences = rsContainers[i] |
146 |
.asyncGetRemoteServiceReferences( |
177 |
.getContainerAdapter().asyncGetRemoteServiceReferences( |
147 |
new ID[] { endpointID }, providedInterface, |
178 |
new ID[] { endpointID }, providedInterface, |
148 |
null); |
179 |
null); |
149 |
// And process the future returned in separate thread |
180 |
// And process the future returned in separate thread |
150 |
processFutureForRemoteServiceReferences(ecfSED, |
181 |
processFutureForRemoteServiceReferences(ecfSED, |
151 |
futureRemoteReferences, cahs[i]); |
182 |
futureRemoteReferences, rsContainers[i]); |
152 |
} |
183 |
} |
153 |
} |
184 |
} |
154 |
} |
185 |
} |
Lines 171-177
Link Here
|
171 |
private void processFutureForRemoteServiceReferences( |
202 |
private void processFutureForRemoteServiceReferences( |
172 |
final ECFServiceEndpointDescription sed, |
203 |
final ECFServiceEndpointDescription sed, |
173 |
final IFuture futureRemoteReferences, |
204 |
final IFuture futureRemoteReferences, |
174 |
final ContainerAdapterHelper ch) { |
205 |
final IRemoteServiceContainer ch) { |
175 |
Thread t = new Thread(new Runnable() { |
206 |
Thread t = new Thread(new Runnable() { |
176 |
public void run() { |
207 |
public void run() { |
177 |
try { |
208 |
try { |
Lines 230-243
Link Here
|
230 |
} |
261 |
} |
231 |
|
262 |
|
232 |
private void addProxyServiceRegistration(ServiceEndpointDescription sed, |
263 |
private void addProxyServiceRegistration(ServiceEndpointDescription sed, |
233 |
ContainerAdapterHelper ch, IRemoteServiceReference ref, |
264 |
IRemoteServiceContainer ch, IRemoteServiceReference ref, |
234 |
ServiceRegistration registration) { |
265 |
ServiceRegistration registration) { |
235 |
ID containerID = ch.getContainer().getID(); |
266 |
ID containerID = ch.getContainer().getID(); |
236 |
RemoteServiceRegistrations reg = (RemoteServiceRegistrations) discoveredRemoteServiceRegistrations |
267 |
RemoteServiceRegistrations reg = (RemoteServiceRegistrations) discoveredRemoteServiceRegistrations |
237 |
.get(containerID); |
268 |
.get(containerID); |
238 |
if (reg == null) { |
269 |
if (reg == null) { |
239 |
reg = new RemoteServiceRegistrations(sed, ch.getContainer(), ch |
270 |
reg = new RemoteServiceRegistrations(sed, ch.getContainer(), ch |
240 |
.getRSCA(), |
271 |
.getContainerAdapter(), |
241 |
new RemoteServiceReferenceUnregisteredListener()); |
272 |
new RemoteServiceReferenceUnregisteredListener()); |
242 |
discoveredRemoteServiceRegistrations.put(containerID, reg); |
273 |
discoveredRemoteServiceRegistrations.put(containerID, reg); |
243 |
} |
274 |
} |
Lines 345-351
Link Here
|
345 |
} |
376 |
} |
346 |
|
377 |
|
347 |
private void registerRemoteServiceReferences( |
378 |
private void registerRemoteServiceReferences( |
348 |
ECFServiceEndpointDescription sed, ContainerAdapterHelper ch, |
379 |
ECFServiceEndpointDescription sed, IRemoteServiceContainer ch, |
349 |
IRemoteServiceReference[] remoteReferences) { |
380 |
IRemoteServiceReference[] remoteReferences) { |
350 |
|
381 |
|
351 |
synchronized (discoveredRemoteServiceRegistrations) { |
382 |
synchronized (discoveredRemoteServiceRegistrations) { |
Lines 359-366
Link Here
|
359 |
|
390 |
|
360 |
for (int i = 0; i < remoteReferences.length; i++) { |
391 |
for (int i = 0; i < remoteReferences.length; i++) { |
361 |
// Get IRemoteService, used to create the proxy below |
392 |
// Get IRemoteService, used to create the proxy below |
362 |
IRemoteService remoteService = ch.getRSCA().getRemoteService( |
393 |
IRemoteService remoteService = ch.getContainerAdapter() |
363 |
remoteReferences[i]); |
394 |
.getRemoteService(remoteReferences[i]); |
364 |
// If no remote service then give up |
395 |
// If no remote service then give up |
365 |
if (remoteService == null) { |
396 |
if (remoteService == null) { |
366 |
logError("registerRemoteServiceReferences", |
397 |
logError("registerRemoteServiceReferences", |
Lines 381-387
Link Here
|
381 |
|
412 |
|
382 |
// Get service properties for the proxy |
413 |
// Get service properties for the proxy |
383 |
Dictionary properties = getPropertiesForRemoteService(sed, ch |
414 |
Dictionary properties = getPropertiesForRemoteService(sed, ch |
384 |
.getRSCA(), remoteReferences[i], remoteService); |
415 |
.getContainerAdapter(), remoteReferences[i], |
|
|
416 |
remoteService); |
385 |
|
417 |
|
386 |
// Create proxy right here |
418 |
// Create proxy right here |
387 |
Object proxy = null; |
419 |
Object proxy = null; |
Lines 431-437
Link Here
|
431 |
return results; |
463 |
return results; |
432 |
} |
464 |
} |
433 |
|
465 |
|
434 |
private ContainerAdapterHelper[] findRSCAs(ID endpointID, |
466 |
private IRemoteServiceContainer[] findRSCAs(ID endpointID, |
435 |
ServiceEndpointDescription sedh) { |
467 |
ServiceEndpointDescription sedh) { |
436 |
IContainerManager containerManager = Activator.getDefault() |
468 |
IContainerManager containerManager = Activator.getDefault() |
437 |
.getContainerManager(); |
469 |
.getContainerManager(); |
Lines 441-447
Link Here
|
441 |
if (containers == null) { |
473 |
if (containers == null) { |
442 |
// log this? |
474 |
// log this? |
443 |
logWarning("findRSCAs", "No containers found for container manager"); |
475 |
logWarning("findRSCAs", "No containers found for container manager"); |
444 |
return new ContainerAdapterHelper[0]; |
476 |
return new IRemoteServiceContainer[0]; |
445 |
} |
477 |
} |
446 |
List results = new ArrayList(); |
478 |
List results = new ArrayList(); |
447 |
for (int i = 0; i < containers.length; i++) { |
479 |
for (int i = 0; i < containers.length; i++) { |
Lines 450-460
Link Here
|
450 |
if (adapter != null |
482 |
if (adapter != null |
451 |
&& includeRCSAForDescription(containers[i], adapter, |
483 |
&& includeRCSAForDescription(containers[i], adapter, |
452 |
endpointID, sedh)) { |
484 |
endpointID, sedh)) { |
453 |
results.add(new ContainerAdapterHelper(containers[i], adapter)); |
485 |
results.add(new RemoteServiceContainer(containers[i], adapter)); |
454 |
} |
486 |
} |
455 |
} |
487 |
} |
456 |
return (ContainerAdapterHelper[]) results |
488 |
return (IRemoteServiceContainer[]) results |
457 |
.toArray(new ContainerAdapterHelper[] {}); |
489 |
.toArray(new IRemoteServiceContainer[] {}); |
458 |
} |
490 |
} |
459 |
|
491 |
|
460 |
private boolean includeRCSAForDescription(IContainer container, |
492 |
private boolean includeRCSAForDescription(IContainer container, |