Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EIG:Getting Started with OSGi Remote Services

Adding ECF 3.2 to Your Target Platform

When ECF 3.2 is released (expected release date: Feb 19, 2010) it will be available on the ecf download page. Until the release, however, to work with ECF 3.2 you will need to get one of the recent daily builds of the ECF SDK (available here...see the C-HEAD-sdk_feature or the N-HEAD-sdk_feature), OR get the ECF source code and build/run from your local workspace.

Note that you only need the ECF SDK in your target platform.

You will also need Eclipse 3.6M5 in your target platform. See here to download Eclipse 3.6M5 (or newer).

Getting the Example Code

Click here for instructions on retrieving all the Hello Example source into your local workspace

Steps to Create the Hello Example

Below are the steps to define and build the Hello Example Remote Service.

Define a Service Interface

As with any OSGi service, local or remote, you must first define your service interface. Here is the 'hello' service interface defined in the org.eclipse.ecf.examples.remoteservices.hello bundle:

package org.eclipse.ecf.examples.remoteservices.hello;
 
public interface IHello {
 
	public void hello(String from);
 
}

Create the Service Implementation

There is a trivial implementation of the IHello interface in this class (which is in the org.eclipse.ecf.examples.remoteservices.hello bundle):

org.eclipse.ecf.examples.remoteservices.hello.impl.Hello

Service Host: Register Remote Service

To actually register (and distribute) the remote service all that's required is to register the service via the OSGi service registry...*with* some OSGi service properties defined. The OSGi 4.2 remote services specfication defines several standard service properties. When these properties are present when registering via the OSGi service registry, any present distribution system (e.g. ECF's remote services API + a provider implementation) automatically kicks in to distribute the service.

Here, for example, is the code in the hello example host (class: org.eclipse.ecf.internal.examples.remoteservices.hello.host.HelloHostApplication in org.eclipse.ecf.examples.remoteservices.host bundle):

// Setup properties for remote service distribution, as per OSGi 4.2 remote services
// specification (chap 13 in compendium spec)
Properties props = new Properties();
// add OSGi service property indicated export of all interfaces exposed by service (wildcard)
props.put(IDistributionConstants.SERVICE_EXPORTED_INTERFACES,IDistributionConstants.SERVICE_EXPORTED_INTERFACES_WILDCARD);
// add OSGi service property specifying config		props.put(IDistributionConstants.SERVICE_EXPORTED_CONFIGS, containerType);
// register remote service
helloRegistration = bundleContext.registerService(IHello.class.getName(), new Hello(), props);

Copyright © Eclipse Foundation, Inc. All Rights Reserved.