View | Details | Raw Unified | Return to bug 249240 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ecf/internal/osgi/services/distribution/ContainerAdapterHelper.java (-41 lines)
Removed Link Here
1
/*******************************************************************************
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
******************************************************************************/
10
/**
11
 * 
12
 */
13
package org.eclipse.ecf.internal.osgi.services.distribution;
14
15
import org.eclipse.ecf.core.IContainer;
16
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
17
18
class ContainerAdapterHelper {
19
	private IContainer container;
20
	private IRemoteServiceContainerAdapter containerAdapter;
21
22
	public ContainerAdapterHelper(IContainer c, IRemoteServiceContainerAdapter rsca) {
23
		this.container = c;
24
		this.containerAdapter = rsca;
25
	}
26
27
	public IContainer getContainer() {
28
		return container;
29
	}
30
31
	public IRemoteServiceContainerAdapter getRSCA() {
32
		return containerAdapter;
33
	}
34
35
	public String toString() {
36
		StringBuffer buf = new StringBuffer("ContainerAdapterHelper[");
37
		buf.append("containerID=").append(getContainer().getID());
38
		buf.append(";rsca=").append(getRSCA()).append("]");
39
		return buf.toString();
40
	}
41
}
(-)src/org/eclipse/ecf/internal/osgi/services/distribution/Activator.java (-2 / +27 lines)
Lines 16-21 Link Here
16
import org.eclipse.ecf.core.IContainerManager;
16
import org.eclipse.ecf.core.IContainerManager;
17
import org.eclipse.ecf.core.util.*;
17
import org.eclipse.ecf.core.util.*;
18
import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
18
import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants;
19
import org.eclipse.ecf.osgi.services.distribution.IRemoteServiceContainerFinder;
19
import org.osgi.framework.*;
20
import org.osgi.framework.*;
20
import org.osgi.framework.hooks.service.EventHook;
21
import org.osgi.framework.hooks.service.EventHook;
21
import org.osgi.service.discovery.DiscoveredServiceTracker;
22
import org.osgi.service.discovery.DiscoveredServiceTracker;
Lines 37-48 Link Here
37
	private ServiceRegistration eventHookRegistration;
38
	private ServiceRegistration eventHookRegistration;
38
	private ServiceRegistration distributionProviderRegistration;
39
	private ServiceRegistration distributionProviderRegistration;
39
	private ServiceRegistration discoveredServiceTrackerRegistration;
40
	private ServiceRegistration discoveredServiceTrackerRegistration;
41
	private ServiceRegistration rsContainerFinderRegistration;
40
42
41
	private ServiceTracker logServiceTracker = null;
43
	private ServiceTracker logServiceTracker = null;
42
	private LogService logService = null;
44
	private LogService logService = null;
43
45
44
	private ServiceTracker adapterManagerTracker;
46
	private ServiceTracker adapterManagerTracker;
45
47
48
	private ServiceTracker rsContainerFinderTracker;
49
46
	public static Activator getDefault() {
50
	public static Activator getDefault() {
47
		return plugin;
51
		return plugin;
48
	}
52
	}
Lines 100-109 Link Here
100
	}
104
	}
101
105
102
	private void addDiscoveredServiceTracker() {
106
	private void addDiscoveredServiceTracker() {
107
		DiscoveredServiceTrackerImpl dstImpl = new DiscoveredServiceTrackerImpl(
108
				this.distributionProvider);
103
		this.discoveredServiceTrackerRegistration = this.context
109
		this.discoveredServiceTrackerRegistration = this.context
104
				.registerService(DiscoveredServiceTracker.class.getName(),
110
				.registerService(DiscoveredServiceTracker.class.getName(),
105
						new DiscoveredServiceTrackerImpl(
111
						dstImpl, null);
106
								this.distributionProvider), null);
112
		this.rsContainerFinderRegistration = this.context.registerService(
113
				IRemoteServiceContainerFinder.class.getName(), dstImpl, null);
107
	}
114
	}
108
115
109
	private void addServiceRegistryHooks() {
116
	private void addServiceRegistryHooks() {
Lines 161-166 Link Here
161
			this.discoveredServiceTrackerRegistration.unregister();
168
			this.discoveredServiceTrackerRegistration.unregister();
162
			this.discoveredServiceTrackerRegistration = null;
169
			this.discoveredServiceTrackerRegistration = null;
163
		}
170
		}
171
		if (this.rsContainerFinderRegistration != null) {
172
			this.rsContainerFinderRegistration.unregister();
173
			this.rsContainerFinderRegistration = null;
174
		}
164
	}
175
	}
165
176
166
	/*
177
	/*
Lines 190-195 Link Here
190
			distributionProvider.dispose();
201
			distributionProvider.dispose();
191
			distributionProvider = null;
202
			distributionProvider = null;
192
		}
203
		}
204
		if (rsContainerFinderTracker != null) {
205
			rsContainerFinderTracker.close();
206
			rsContainerFinderTracker = null;
207
		}
193
		this.context = null;
208
		this.context = null;
194
		plugin = null;
209
		plugin = null;
195
	}
210
	}
Lines 203-208 Link Here
203
		return (IContainerManager) containerManagerTracker.getService();
218
		return (IContainerManager) containerManagerTracker.getService();
204
	}
219
	}
205
220
221
	public IRemoteServiceContainerFinder[] getRemoteServiceContainerFinders() {
222
		if (rsContainerFinderTracker == null) {
223
			rsContainerFinderTracker = new ServiceTracker(this.context,
224
					IRemoteServiceContainerFinder.class.getName(), null);
225
			rsContainerFinderTracker.open();
226
		}
227
		return (IRemoteServiceContainerFinder[]) rsContainerFinderTracker
228
				.getServices();
229
	}
230
206
	public IAdapterManager getAdapterManager() {
231
	public IAdapterManager getAdapterManager() {
207
		// First, try to get the adapter manager via
232
		// First, try to get the adapter manager via
208
		if (adapterManagerTracker == null) {
233
		if (adapterManagerTracker == null) {
(-)src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java (-23 / +55 lines)
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,
(-)src/org/eclipse/ecf/osgi/services/distribution/IRemoteServiceContainerFinder.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors:
8
 *   EclipseSource - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.ecf.osgi.services.distribution;
11
12
import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription;
13
import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
14
15
public interface IRemoteServiceContainerFinder {
16
17
	public IRemoteServiceContainer[] findRemoteServiceContainers(
18
			ECFServiceEndpointDescription endpointDescription);
19
20
}

Return to bug 249240