Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 259525 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ecf/internal/provider/discovery/Activator.java (-86 / +12 lines)
Lines 10-30 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.provider.discovery;
11
package org.eclipse.ecf.internal.provider.discovery;
12
12
13
import java.util.*;
13
import org.osgi.framework.BundleActivator;
14
import org.eclipse.ecf.core.ContainerConnectException;
14
import org.osgi.framework.BundleContext;
15
import org.eclipse.ecf.core.identity.IDCreateException;
16
import org.eclipse.ecf.core.identity.IDFactory;
17
import org.eclipse.ecf.core.util.Trace;
18
import org.eclipse.ecf.discovery.service.IDiscoveryService;
19
import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
20
import org.osgi.framework.*;
21
import org.osgi.util.tracker.ServiceTracker;
22
15
23
public class Activator implements BundleActivator {
16
public class Activator implements BundleActivator {
24
	// The shared instance
17
	// The shared instance
25
	private static Activator plugin;
18
	private static Activator plugin;
26
	public static final String PLUGIN_ID = "org.eclipse.ecf.provider.discovery"; //$NON-NLS-1$
19
	public static final String PLUGIN_ID = "org.eclipse.ecf.provider.discovery"; //$NON-NLS-1$
27
20
21
	private static BundleContext context;
22
28
	/**
23
	/**
29
	 * Returns the shared instance
24
	 * Returns the shared instance
30
	 * 
25
	 * 
Lines 45-133 Link Here
45
	 * (non-Javadoc)
40
	 * (non-Javadoc)
46
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
41
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
47
	 */
42
	 */
48
	public void start(final BundleContext context) throws Exception {
43
	public void start(final BundleContext ctxt) throws Exception {
49
		Properties props = new Properties();
44
		context = ctxt;
50
		props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer")); //$NON-NLS-1$
51
		props.put(IDiscoveryService.CONTAINER_NAME, CompositeDiscoveryContainer.NAME);
52
		props.put(Constants.SERVICE_RANKING, new Integer(1000));
53
		context.registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
54
55
			/* (non-Javadoc)
56
			 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
57
			 */
58
			public Object getService(Bundle bundle, ServiceRegistration registration) {
59
60
				// get all previously registered IDS from OSGi (but not this one)
61
				Filter filter = null;
62
				try {
63
					String filter2 = "(&(" + Constants.OBJECTCLASS + "=" + IDiscoveryService.class.getName() + ")(!(" + IDiscoveryService.CONTAINER_NAME + "=" + CompositeDiscoveryContainer.NAME + ")))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
64
					filter = context.createFilter(filter2);
65
				} catch (InvalidSyntaxException e2) {
66
					Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e2); //$NON-NLS-1$ //$NON-NLS-2$
67
					return null;
68
				}
69
				ServiceTracker tracker = new ServiceTracker(context, filter, null);
70
				tracker.open();
71
				Object[] services = tracker.getServices();
72
				tracker.close();
73
				List discoveries = services == null ? new ArrayList() : new ArrayList(Arrays.asList(services));
74
75
				// register the composite discovery service)
76
				final CompositeDiscoveryContainer cdc;
77
				try {
78
					cdc = new CompositeDiscoveryContainer(discoveries);
79
				} catch (IDCreateException e1) {
80
					Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e1); //$NON-NLS-1$ //$NON-NLS-2$
81
					return null;
82
				}
83
				try {
84
					cdc.connect(null, null);
85
				} catch (ContainerConnectException e) {
86
					Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
87
					return null;
88
				}
89
90
				// add a service listener to add/remove IDS dynamically 
91
				try {
92
					context.addServiceListener(new ServiceListener() {
93
						/* (non-Javadoc)
94
						 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
95
						 */
96
						public void serviceChanged(ServiceEvent arg0) {
97
							IDiscoveryService anIDS = (IDiscoveryService) context.getService(arg0.getServiceReference());
98
							switch (arg0.getType()) {
99
								case ServiceEvent.REGISTERED :
100
									cdc.addContainer(anIDS);
101
									break;
102
								case ServiceEvent.UNREGISTERING :
103
									cdc.removeContainer(anIDS);
104
									break;
105
								default :
106
									break;
107
							}
108
						}
109
110
					}, "(" + Constants.OBJECTCLASS + "=" + IDiscoveryService.class.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
111
				} catch (InvalidSyntaxException e) {
112
					// nop
113
				}
114
				return cdc;
115
			}
116
117
			/* (non-Javadoc)
118
			 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
119
			 */
120
			public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
121
				// nop
122
			}
123
		}, props);
124
	}
45
	}
125
46
126
	/*
47
	/*
127
	 * (non-Javadoc)
48
	 * (non-Javadoc)
128
	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
49
	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
129
	 */
50
	 */
130
	public void stop(BundleContext context) throws Exception {
51
	public void stop(BundleContext ctxt) throws Exception {
131
		plugin = null;
52
		plugin = null;
53
		context = null;
54
	}
55
56
	public static BundleContext getContext() {
57
		return context;
132
	}
58
	}
133
}
59
}
(-)plugin.xml (+7 lines)
Lines 24-28 Link Here
24
            name="ecf.namespace.composite">
24
            name="ecf.namespace.composite">
25
      </namespace>
25
      </namespace>
26
   </extension>
26
   </extension>
27
   <extension
28
         point="org.eclipse.ecf.start">
29
      <run
30
            asynchronous="false"
31
            class="org.eclipse.ecf.internal.provider.discovery.ECFStart">
32
      </run>
33
   </extension>
27
34
28
</plugin>
35
</plugin>
(-)src/org/eclipse/ecf/internal/provider/discovery/ECFStart.java (+110 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.provider.discovery;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.ecf.core.ContainerConnectException;
16
import org.eclipse.ecf.core.identity.IDCreateException;
17
import org.eclipse.ecf.core.identity.IDFactory;
18
import org.eclipse.ecf.core.start.IECFStart;
19
import org.eclipse.ecf.core.util.Trace;
20
import org.eclipse.ecf.discovery.service.IDiscoveryService;
21
import org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer;
22
import org.osgi.framework.*;
23
import org.osgi.util.tracker.ServiceTracker;
24
25
public class ECFStart implements IECFStart {
26
27
	public IStatus run(IProgressMonitor monitor) {
28
		try {
29
			Properties props = new Properties();
30
			props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.discovery.CompositeDiscoveryContainer")); //$NON-NLS-1$
31
			props.put(IDiscoveryService.CONTAINER_NAME, CompositeDiscoveryContainer.NAME);
32
			props.put(Constants.SERVICE_RANKING, new Integer(1000));
33
			Activator.getContext().registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
34
35
				/* (non-Javadoc)
36
				 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
37
				 */
38
				public Object getService(Bundle bundle, ServiceRegistration registration) {
39
40
					// get all previously registered IDS from OSGi (but not this one)
41
					Filter filter = null;
42
					try {
43
						String filter2 = "(&(" + Constants.OBJECTCLASS + "=" + IDiscoveryService.class.getName() + ")(!(" + IDiscoveryService.CONTAINER_NAME + "=" + CompositeDiscoveryContainer.NAME + ")))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
44
						filter = Activator.getContext().createFilter(filter2);
45
					} catch (InvalidSyntaxException e2) {
46
						Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e2); //$NON-NLS-1$ //$NON-NLS-2$
47
						return null;
48
					}
49
					ServiceTracker tracker = new ServiceTracker(Activator.getContext(), filter, null);
50
					tracker.open();
51
					Object[] services = tracker.getServices();
52
					tracker.close();
53
					List discoveries = services == null ? new ArrayList() : new ArrayList(Arrays.asList(services));
54
55
					// register the composite discovery service)
56
					final CompositeDiscoveryContainer cdc;
57
					try {
58
						cdc = new CompositeDiscoveryContainer(discoveries);
59
					} catch (IDCreateException e1) {
60
						Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e1); //$NON-NLS-1$ //$NON-NLS-2$
61
						return null;
62
					}
63
					try {
64
						cdc.connect(null, null);
65
					} catch (ContainerConnectException e) {
66
						Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
67
						return null;
68
					}
69
70
					// add a service listener to add/remove IDS dynamically 
71
					try {
72
						Activator.getContext().addServiceListener(new ServiceListener() {
73
							/* (non-Javadoc)
74
							 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
75
							 */
76
							public void serviceChanged(ServiceEvent arg0) {
77
								IDiscoveryService anIDS = (IDiscoveryService) Activator.getContext().getService(arg0.getServiceReference());
78
								switch (arg0.getType()) {
79
									case ServiceEvent.REGISTERED :
80
										cdc.addContainer(anIDS);
81
										break;
82
									case ServiceEvent.UNREGISTERING :
83
										cdc.removeContainer(anIDS);
84
										break;
85
									default :
86
										break;
87
								}
88
							}
89
90
						}, "(" + Constants.OBJECTCLASS + "=" + IDiscoveryService.class.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
91
					} catch (InvalidSyntaxException e) {
92
						// nop
93
					}
94
					return cdc;
95
				}
96
97
				/* (non-Javadoc)
98
				 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
99
				 */
100
				public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
101
					// nop
102
				}
103
			}, props);
104
105
			return Status.OK_STATUS;
106
		} catch (Exception e) {
107
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Exception starting composite container", e); //$NON-NLS-1$
108
		}
109
	}
110
}
(-)src/org/eclipse/ecf/internal/provider/jmdns/JMDNSPlugin.java (-48 / +6 lines)
Lines 10-24 Link Here
10
 *****************************************************************************/
10
 *****************************************************************************/
11
package org.eclipse.ecf.internal.provider.jmdns;
11
package org.eclipse.ecf.internal.provider.jmdns;
12
12
13
import java.net.InetAddress;
14
import java.util.Properties;
15
import org.eclipse.core.runtime.IAdapterManager;
13
import org.eclipse.core.runtime.IAdapterManager;
16
import org.eclipse.ecf.core.ContainerConnectException;
14
import org.eclipse.ecf.core.util.PlatformHelper;
17
import org.eclipse.ecf.core.identity.IDCreateException;
15
import org.eclipse.ecf.core.util.SystemLogService;
18
import org.eclipse.ecf.core.identity.IDFactory;
19
import org.eclipse.ecf.core.util.*;
20
import org.eclipse.ecf.discovery.service.IDiscoveryService;
21
import org.eclipse.ecf.provider.jmdns.container.JMDNSDiscoveryContainer;
22
import org.osgi.framework.*;
16
import org.osgi.framework.*;
23
import org.osgi.service.log.LogService;
17
import org.osgi.service.log.LogService;
24
import org.osgi.util.tracker.ServiceTracker;
18
import org.osgi.util.tracker.ServiceTracker;
Lines 27-34 Link Here
27
 * The main plugin class to be used in the desktop.
21
 * The main plugin class to be used in the desktop.
28
 */
22
 */
29
public class JMDNSPlugin implements BundleActivator {
23
public class JMDNSPlugin implements BundleActivator {
30
	private static final String NAME = "ecf.discovery.jmdns"; //$NON-NLS-1$
31
32
	// The shared instance.
24
	// The shared instance.
33
	private static JMDNSPlugin plugin;
25
	private static JMDNSPlugin plugin;
34
26
Lines 36-43 Link Here
36
28
37
	public static final String PLUGIN_ID = "org.eclipse.ecf.provider.jmdns"; //$NON-NLS-1$
29
	public static final String PLUGIN_ID = "org.eclipse.ecf.provider.jmdns"; //$NON-NLS-1$
38
30
39
	protected static InetAddress LOCALHOST = null;
40
41
	/**
31
	/**
42
	 * The constructor.
32
	 * The constructor.
43
	 */
33
	 */
Lines 73-114 Link Here
73
	 */
63
	 */
74
	public void start(BundleContext ctxt) throws Exception {
64
	public void start(BundleContext ctxt) throws Exception {
75
		this.context = ctxt;
65
		this.context = ctxt;
76
		LOCALHOST = InetAddress.getLocalHost();
77
78
		Properties props = new Properties();
79
		props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.jmdns.container.JMDNSDiscoveryContainer")); //$NON-NLS-1$
80
		props.put(IDiscoveryService.CONTAINER_NAME, NAME);
81
		props.put(Constants.SERVICE_RANKING, new Integer(750));
82
		context.registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
83
			private volatile JMDNSDiscoveryContainer jdc;
84
85
			/* (non-Javadoc)
86
			 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
87
			 */
88
			public Object getService(Bundle bundle, ServiceRegistration registration) {
89
				if (jdc == null) {
90
					try {
91
						jdc = new JMDNSDiscoveryContainer(LOCALHOST);
92
						jdc.connect(null, null);
93
					} catch (IDCreateException e) {
94
						Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSPlugin.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
95
					} catch (ContainerConnectException e) {
96
						Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSPlugin.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
97
						jdc = null;
98
					}
99
				}
100
				return jdc;
101
			}
102
103
			/* (non-Javadoc)
104
			 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
105
			 */
106
			public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
107
				//TODO-mkuppe we later might want to dispose jSLP when the last!!! consumer ungets the service 
108
				//Though don't forget about the (ECF) Container which might still be in use
109
			}
110
		}, props);
111
112
	}
66
	}
113
67
114
	protected Bundle getBundle() {
68
	protected Bundle getBundle() {
Lines 145-150 Link Here
145
		return plugin;
99
		return plugin;
146
	}
100
	}
147
101
102
	public BundleContext getContext() {
103
		return context;
104
	}
105
148
	/**
106
	/**
149
	 * @param string
107
	 * @param string
150
	 * @param t
108
	 * @param t
(-)plugin.xml (+6 lines)
Lines 17-21 Link Here
17
            description="JMDNS Namespace"
17
            description="JMDNS Namespace"
18
            name="ecf.namespace.jmdns"/>
18
            name="ecf.namespace.jmdns"/>
19
   </extension>
19
   </extension>
20
   <extension
21
         point="org.eclipse.ecf.start">
22
      <run
23
            class="org.eclipse.ecf.internal.provider.jmdns.ECFStart">
24
      </run>
25
   </extension>
20
26
21
</plugin>
27
</plugin>
(-)src/org/eclipse/ecf/internal/provider/jmdns/ECFStart.java (+78 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.provider.jmdns;
12
13
import java.net.InetAddress;
14
import java.util.Properties;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.ecf.core.ContainerConnectException;
17
import org.eclipse.ecf.core.identity.IDCreateException;
18
import org.eclipse.ecf.core.identity.IDFactory;
19
import org.eclipse.ecf.core.start.IECFStart;
20
import org.eclipse.ecf.core.util.Trace;
21
import org.eclipse.ecf.discovery.service.IDiscoveryService;
22
import org.eclipse.ecf.provider.jmdns.container.JMDNSDiscoveryContainer;
23
import org.osgi.framework.*;
24
25
public class ECFStart implements IECFStart {
26
27
	protected static InetAddress LOCALHOST = null;
28
	private static final String NAME = "ecf.discovery.jmdns"; //$NON-NLS-1$
29
30
	public ECFStart() {
31
		// 
32
	}
33
34
	public IStatus run(IProgressMonitor arg0) {
35
		try {
36
			LOCALHOST = InetAddress.getLocalHost();
37
38
			Properties props = new Properties();
39
			props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.jmdns.container.JMDNSDiscoveryContainer")); //$NON-NLS-1$
40
			props.put(IDiscoveryService.CONTAINER_NAME, NAME);
41
			props.put(Constants.SERVICE_RANKING, new Integer(750));
42
			JMDNSPlugin.getDefault().getContext().registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
43
				private volatile JMDNSDiscoveryContainer jdc;
44
45
				/* (non-Javadoc)
46
				 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
47
				 */
48
				public Object getService(Bundle bundle, ServiceRegistration registration) {
49
					if (jdc == null) {
50
						try {
51
							jdc = new JMDNSDiscoveryContainer(LOCALHOST);
52
							jdc.connect(null, null);
53
						} catch (IDCreateException e) {
54
							Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSPlugin.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
55
						} catch (ContainerConnectException e) {
56
							Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSPlugin.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
57
							jdc = null;
58
						}
59
					}
60
					return jdc;
61
				}
62
63
				/* (non-Javadoc)
64
				 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
65
				 */
66
				public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
67
					//TODO-mkuppe we later might want to dispose jSLP when the last!!! consumer ungets the service 
68
					//Though don't forget about the (ECF) Container which might still be in use
69
				}
70
			}, props);
71
72
			return Status.OK_STATUS;
73
		} catch (Exception e) {
74
			return new Status(IStatus.ERROR, JMDNSPlugin.PLUGIN_ID, IStatus.ERROR, "Exception starting jmdns container", e); //$NON-NLS-1$
75
		}
76
	}
77
78
}
(-)src/org/eclipse/ecf/internal/provider/jslp/Activator.java (-42 / +4 lines)
Lines 12-24 Link Here
12
12
13
import ch.ethz.iks.slp.Advertiser;
13
import ch.ethz.iks.slp.Advertiser;
14
import ch.ethz.iks.slp.Locator;
14
import ch.ethz.iks.slp.Locator;
15
import java.util.Properties;
16
import org.eclipse.ecf.core.ContainerConnectException;
17
import org.eclipse.ecf.core.identity.IDCreateException;
18
import org.eclipse.ecf.core.identity.IDFactory;
19
import org.eclipse.ecf.core.util.Trace;
20
import org.eclipse.ecf.discovery.service.IDiscoveryService;
21
import org.eclipse.ecf.provider.jslp.container.JSLPDiscoveryContainer;
22
import org.osgi.framework.*;
15
import org.osgi.framework.*;
23
import org.osgi.util.tracker.ServiceTracker;
16
import org.osgi.util.tracker.ServiceTracker;
24
17
Lines 86-126 Link Here
86
		// initially get the advertiser and add a life cycle listener
79
		// initially get the advertiser and add a life cycle listener
87
		advertiserSt = new ServiceTracker(context, Advertiser.class.getName(), null);
80
		advertiserSt = new ServiceTracker(context, Advertiser.class.getName(), null);
88
81
89
		// register ourself as an OSGi service
82
	}
90
		Properties props = new Properties();
83
91
		props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.jslp.container.JSLPDiscoveryContainer")); //$NON-NLS-1$
84
	public BundleContext getContext() {
92
		props.put(IDiscoveryService.CONTAINER_NAME, JSLPDiscoveryContainer.NAME);
85
		return bundleContext;
93
		props.put(Constants.SERVICE_RANKING, new Integer(500));
94
95
		context.registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
96
			private volatile JSLPDiscoveryContainer jdc;
97
98
			/* (non-Javadoc)
99
			 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
100
			 */
101
			public Object getService(Bundle bundle, ServiceRegistration registration) {
102
				if (jdc == null) {
103
					try {
104
						jdc = new JSLPDiscoveryContainer();
105
						jdc.connect(null, null);
106
					} catch (IDCreateException e) {
107
						Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/tracing", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
108
					} catch (ContainerConnectException e) {
109
						Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/tracing", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
110
						jdc = null;
111
					}
112
				}
113
				return jdc;
114
			}
115
116
			/* (non-Javadoc)
117
			 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
118
			 */
119
			public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
120
				//TODO-mkuppe we later might want to dispose jSLP when the last!!! consumer ungets the service 
121
				//Though don't forget about the (ECF) Container which might still be in use
122
			}
123
		}, props);
124
	}
86
	}
125
87
126
	/*
88
	/*
(-)plugin.xml (+6 lines)
Lines 16-20 Link Here
16
            description="JSLP Namespace"
16
            description="JSLP Namespace"
17
            name="ecf.namespace.slp"/>
17
            name="ecf.namespace.slp"/>
18
   </extension>
18
   </extension>
19
   <extension
20
         point="org.eclipse.ecf.start">
21
      <run
22
            class="org.eclipse.ecf.internal.provider.jslp.ECFStart">
23
      </run>
24
   </extension>
19
25
20
</plugin>
26
</plugin>
(-)src/org/eclipse/ecf/internal/provider/jslp/ECFStart.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Versant Corp.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.ecf.internal.provider.jslp;
12
13
import java.util.Properties;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.ecf.core.ContainerConnectException;
16
import org.eclipse.ecf.core.identity.IDCreateException;
17
import org.eclipse.ecf.core.identity.IDFactory;
18
import org.eclipse.ecf.core.start.IECFStart;
19
import org.eclipse.ecf.core.util.Trace;
20
import org.eclipse.ecf.discovery.service.IDiscoveryService;
21
import org.eclipse.ecf.provider.jslp.container.JSLPDiscoveryContainer;
22
import org.osgi.framework.*;
23
24
public class ECFStart implements IECFStart {
25
26
	public ECFStart() {
27
		// 
28
	}
29
30
	public IStatus run(IProgressMonitor arg0) {
31
		try {
32
			// register ourself as an OSGi service
33
			Properties props = new Properties();
34
			props.put(IDiscoveryService.CONTAINER_ID, IDFactory.getDefault().createStringID("org.eclipse.ecf.provider.jslp.container.JSLPDiscoveryContainer")); //$NON-NLS-1$
35
			props.put(IDiscoveryService.CONTAINER_NAME, JSLPDiscoveryContainer.NAME);
36
			props.put(Constants.SERVICE_RANKING, new Integer(500));
37
38
			Activator.getDefault().getContext().registerService(IDiscoveryService.class.getName(), new ServiceFactory() {
39
				private volatile JSLPDiscoveryContainer jdc;
40
41
				/* (non-Javadoc)
42
				 * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
43
				 */
44
				public Object getService(Bundle bundle, ServiceRegistration registration) {
45
					if (jdc == null) {
46
						try {
47
							jdc = new JSLPDiscoveryContainer();
48
							jdc.connect(null, null);
49
						} catch (IDCreateException e) {
50
							Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/tracing", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
51
						} catch (ContainerConnectException e) {
52
							Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/tracing", this.getClass(), "getService(Bundle, ServiceRegistration)", e); //$NON-NLS-1$ //$NON-NLS-2$
53
							jdc = null;
54
						}
55
					}
56
					return jdc;
57
				}
58
59
				/* (non-Javadoc)
60
				 * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
61
				 */
62
				public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
63
					//TODO-mkuppe we later might want to dispose jSLP when the last!!! consumer ungets the service 
64
					//Though don't forget about the (ECF) Container which might still be in use
65
				}
66
			}, props);
67
68
			return Status.OK_STATUS;
69
		} catch (Exception e) {
70
			return new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Exception starting jslp container", e); //$NON-NLS-1$
71
		}
72
	}
73
}

Return to bug 259525