[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] Distributing hello world example

Hi Ronen,

On 3/27/2011 6:34 AM, ronen hamias wrote:
Hi All,

i am trying to distribute simple hello world implementation

when i invoke my client i get this error:

It looks to me from the stack traces that the client cannot connect to the service host. This could be because

a) the service host is not exporting correctly,
b) the client is trying to access the incorrect host/port;

Basically, the client/consumer is saying that it can't reach the host it's trying to reach.

my client source code looks like this: ---------------------------------------------------------------------------------------------------------------------------------------------------------- package pt.hello.client;

import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ecf.core.identity.IDFactory;

import org.eclipse.ecf.remoteservice.IRemoteCall;
import org.eclipse.ecf.remoteservice.IRemoteCallListener;
import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;

import pt.hello.IHello;

 * The activator class controls the plug-in life cycle
public class Activator implements BundleActivator {

public static final String ROSGI_SERVICE_HOST = "r-osgi://localhost:9279";

    private BundleContext context;
    private ServiceTracker containerManagerServiceTracker;
    private IContainer container;

* (non-Javadoc)
* @see
* org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
public void start(BundleContext context) throws Exception {
this.context = context;
// 1. Create R-OSGi Container
IContainerManager containerManager = getContainerManagerService();
container = containerManager.getContainerFactory().createContainer(
// 2. Get remote service container adapter
IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) container
// 3. Lookup IRemoteServiceReference
IRemoteServiceReference[] helloReferences = containerAdapter
container.getConnectNamespace(), ROSGI_SERVICE_HOST),
IHello.class.getName(), null);
Assert.isTrue(helloReferences.length > 0);
// 4. Get remote service for reference
IRemoteService remoteService = containerAdapter
// 5. Get the proxy
IHello proxy = (IHello) remoteService.getProxy();
// 6. Finally...call the proxy
proxy.hello("RemoteService Consumer");

IRemoteCall createRemoteCall() { return new IRemoteCall() {

            public String getMethod() {
                return "hello";

            public Object[] getParameters() {
                return new Object[] { "Asynch RemoteService Consumer" };

            public long getTimeout() {
                return 0;

    IRemoteCallListener createRemoteCallListener() {
        return new IRemoteCallListener() {

public void handleEvent(IRemoteCallEvent event) {
if (event instanceof IRemoteCallCompleteEvent) {
IRemoteCallCompleteEvent cce = (IRemoteCallCompleteEvent) event;
if (!cce.hadException())
.println("Remote call completed successfully!");
.println("Remote call completed with exception: "
+ cce.getException());

* (non-Javadoc)
* @see
* org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
public void stop(BundleContext context) throws Exception {
if (container != null) {
container = null;
if (containerManagerServiceTracker != null) {
containerManagerServiceTracker = null;
this.context = null;

private IContainerManager getContainerManagerService() {
if (containerManagerServiceTracker == null) {
containerManagerServiceTracker = new ServiceTracker(context,
IContainerManager.class.getName(), null);
return (IContainerManager) containerManagerServiceTracker.getService();

my server side source code looks like this:

package pt.hello.service;

import java.util.Properties;

import org.eclipse.ecf.osgi.services.distribution.IDistributionConstants;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import pt.hello.IHello;

public class Activator implements BundleActivator{
private static final String containerType = "ecf.r_osgi.peer";
public static final String DEFAULT_CONTAINER_ID = "r-osgi://localhost:9279";
private String containerId = DEFAULT_CONTAINER_ID;
private ServiceRegistration helloRegistration;

* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
public void start(BundleContext context) throws Exception{
System.out.println("IHello RemoteService registered");

void registerHelloRemoteService(BundleContext context) {
// 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)
// add OSGi service property specifying config
// add ECF service property specifying container factory args
// register remote service
helloRegistration = context.registerService(
IHello.class.getName(), new HelloImpl(), props);
// tell everyone
System.out.println("Host: Hello Service Registered");

    void unregisterHelloRemoteService() {
        if (helloRegistration != null) {
            helloRegistration = null;
        // tell everyone
        System.out.println("Host: Hello Remote Service Unregistered");

* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
public void stop(BundleContext context) throws Exception{}

i guess i am missing somthing... can someone direct me what i am doing wrong?

Well, it looks to me as if you are exporting the service with the wrong/incorrect endpoint it. That is, when you start the service host app (I assume you are starting it first), r-osgi will use port *9278*, but because you use this:

public static final String DEFAULT_CONTAINER_ID = "r-osgi://localhost:9279";

The endpoint will be exported with endpoint id = "r-osgi://localhost:9279". And when the client attempts to connect to r-osgi://localhost:9279 it fails (because the service host is listening on 9278).

It is possible to tell the r-osgi provider to use a specific port (e.g. 9279)...but because r-osgi existed prior to ECF's usage as a remote services provider this is done via system properties. These r-OSGi-specific properties are described here


Hope this helps.

Incidently...why are you using the OSGi remote services on the host, but not on the client? You can do this, but it makes the client more complicated (i.e. the need for all the code that uses the ECF remote services API directly...e.g. containerAdapter.getRemoteReferences(...), etc).