Skip to main content

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.

Jump to: navigation, search

EIG:Remoting

Revision as of 10:05, 12 February 2011 by Mpetzold.gmx.net (Talk | contribs)

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







Back to the top