Developing a Distributed OSGi Application in Eclipse has been created by David Bosschaert (Dec 23, 2008).

Content:

This is really easy and assumes that you've already set up your Eclipse workspace as described here.

1. Create a new Plugin Project for a 'standard' OSGi Framework.
Unable to render embedded object: File (new_project.jpg) not found.

2. Create an OSGi service and and register it with the OSGi Service Registry. I'm creating a service that implements my test.distributed.service.TemperatureService.

package test.distributed.service;
import java.util.Date;

public interface TemperatureService {
    int getTemperature(Date date, String city, boolean celcius);
}

The service is registered with the OSGi Service Registry in the Activator.

package test.distributed.service;
import java.util.*;
import org.osgi.framework.*;

public class Activator implements BundleActivator {
    private ServiceRegistration registration;

    public void start(BundleContext bc) throws Exception {
    Dictionary props = new Hashtable();
    props.put("osgi.remote.interfaces", "*");

    registration = bc.registerService(TemperatureService.class.getName(), 
                                      new TemperatureServiceImpl(), props);	}

    public void stop(BundleContext context) throws Exception {
        registration.unregister();
    }
}

The only thing you need to do to expose a service remotely is setting the osgi.remote.interfaces property to the (comma separated) list of interfaces of the service that need to be exposed. Specifying * simply takes all the interfaces that were passed in to the registerService() call.
By default the service will be made available on http://{machine}:9000/fully/qualified/ClassName (so in this case http://localhost:9000/test/distributed/service/TemperatureService). You can change this by adding the osgi.remote.configuration.type and osgi.remote.configuration.pojo.address properties on the service, e.g.:

props.put("osgi.remote.configuration.type", "pojo");
props.put("osgi.remote.configuration.pojo.address", "http://localhost:8888/temp");

Reply via email to