Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EIG:Remoting"
Line 1: | Line 1: | ||
− | == Creating an OSGi Service<br> == | + | == Creating an OSGi Service<br> == |
− | OSGi Services should be registered under a specific interface. Even if it's possible the service should not be registered only by a class name:<br> | + | OSGi Services should be registered under a specific interface. Even if it's possible the service should not be registered only by a class name:<br> |
<pre>public interface MyServiceInterface { | <pre>public interface MyServiceInterface { | ||
Line 7: | Line 7: | ||
} | } | ||
− | </pre> | + | </pre> |
− | There is of course then some sort of implementaions of this service: <br> | + | There is of course then some sort of implementaions of this service: <br> |
<pre>public class MyService implements MyServiceInterface { | <pre>public class MyService implements MyServiceInterface { | ||
Line 15: | Line 15: | ||
} | } | ||
} | } | ||
− | </pre> | + | </pre> |
− | == Registering an OSGi Remote Service<br> == | + | == Registering an OSGi Remote Service<br> == |
− | The registration of an OSGi Remote Service is nearly the same as with any regular service in an OSGi Framework (e.g. Eclipse Equinox). The only additional thing you need to do is setting some service properties. For the Eclipse Communication Framework (ECF) only two properties are required: The "service.exported.interfaces" property marks the service for export (as an OSGi Remote Service) and defines under which interfaces this service can be exported. The "service.exported.configs" property is a list of configuration types (endpoint typed) that should be used to export the service. The other properties are optional settings for the distribution provider.<br> | + | The registration of an OSGi Remote Service is nearly the same as with any regular service in an OSGi Framework (e.g. Eclipse Equinox). The only additional thing you need to do is setting some service properties. For the Eclipse Communication Framework (ECF) only two properties are required: The "service.exported.interfaces" property marks the service for export (as an OSGi Remote Service) and defines under which interfaces this service can be exported. The "service.exported.configs" property is a list of configuration types (endpoint typed) that should be used to export the service. The other properties are optional settings for the distribution provider.<br> |
=== OSGi Remote Service Properties<br> === | === OSGi Remote Service Properties<br> === | ||
Line 24: | Line 24: | ||
service.exported.configs<br> | service.exported.configs<br> | ||
− | service.exported.intents<br> | + | service.exported.intents<br> |
− | service.exported.intents.extra<br> | + | service.exported.intents.extra<br> |
− | service.exported.interfaces | + | service.exported.interfaces |
− | service.intents | + | service.intents |
− | === Example<br> === | + | === Example<br> === |
<pre>public class Activator implements BundleActivator { | <pre>public class Activator implements BundleActivator { | ||
Line 54: | Line 54: | ||
// Unregister the service | // Unregister the service | ||
− | if(this.myServiceRegistration != null) { | + | if(this.myServiceRegistration != null) { |
this.myServiceRegistration.unregister(); | this.myServiceRegistration.unregister(); | ||
this.myServiceRegistration = null; | this.myServiceRegistration = null; | ||
Line 62: | Line 62: | ||
} | } | ||
} | } | ||
− | </pre> | + | </pre> |
+ | == Using an OSGi Remote Service<br> == | ||
+ | |||
+ | If you want to use an OSGi Remote Service this is also as simple as with regular services in the framework.<br> | ||
+ | |||
+ | === Filter<br> === | ||
+ | |||
+ | The specified filter expression is used to select the registered services whose service properties contain keys and values which satisfy the filter expression. <br> | ||
+ | |||
+ | (service.imported=*)<br> | ||
+ | |||
+ | (service.remote.registration=true)<br> | ||
+ | |||
+ | === Example: Get Service References<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === Example: Service Tracker<br> === | ||
+ | |||
+ | <br> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | <br> | ||
+ | |||
<br> | <br> |
Revision as of 10:05, 12 February 2011
Contents
Creating an OSGi Service
OSGi Services should be registered under a specific interface. Even if it's possible the service should not be registered only by a class name:
public interface MyServiceInterface { public String hello(); }
There is of course then some sort of implementaions of this service:
public class MyService implements MyServiceInterface { public String hello() { return "Hello World!"; } }
Registering an OSGi Remote Service
The registration of an OSGi Remote Service is nearly the same as with any regular service in an OSGi Framework (e.g. Eclipse Equinox). The only additional thing you need to do is setting some service properties. For the Eclipse Communication Framework (ECF) only two properties are required: The "service.exported.interfaces" property marks the service for export (as an OSGi Remote Service) and defines under which interfaces this service can be exported. The "service.exported.configs" property is a list of configuration types (endpoint typed) that should be used to export the service. The other properties are optional settings for the distribution provider.
OSGi Remote Service Properties
service.exported.configs
service.exported.intents
service.exported.intents.extra
service.exported.interfaces
service.intents
Example
public class Activator implements BundleActivator { private MyServiceInterface myService = null; private ServiceRegistration myServiceRegistration = null; public void start(BundleContext bundleContext) throws Exception { // Instantiate a service instance this.myService = new MyService(); // Register the service instance as an OSGi Remote Service Properties props = new Properties(); props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "ecf.r_osgi.peer"); this.myServiceRegistration = bundleContext.registerService(MyServiceInterface.class.getName(), new MyService(), props); } public void stop(BundleContext bundleContext) throws Exception { // Unregister the service if(this.myServiceRegistration != null) { this.myServiceRegistration.unregister(); this.myServiceRegistration = null; this.myService = null; } } }
Using an OSGi Remote Service
If you want to use an OSGi Remote Service this is also as simple as with regular services in the framework.
Filter
The specified filter expression is used to select the registered services whose service properties contain keys and values which satisfy the filter expression.
(service.imported=*)
(service.remote.registration=true)
Example: Get Service References
Example: Service Tracker