The service interface above is contained in the o.e.e.e.remoteservices.hello bundle, along with a trivial implementation (in org.eclipse.ecf.examples.remoteservices.hello.impl.Hello).

+

===Registering the Service (Host)===

===Registering the Service (Host)===

−

Here is the code in org.eclipse.ecf.internal.examples.remoteservices.hello.host.rs.Activator that registers a remote service with the ECF RFC119 implementation:

+

Here is the code in org.eclipse.ecf.internal.examples.remoteservices.hello.host.rs.Activator that registers a remote service with the ECF Remote Service API:

<source lang="java">

<source lang="java">

Line 86:

Line 81:

IRemoteServiceReference[] helloReferences = containerAdapter

IRemoteServiceReference[] helloReferences = containerAdapter

.getRemoteServiceReferences(IDFactory.getDefault().createID(

.getRemoteServiceReferences(IDFactory.getDefault().createID(

−

container.getConnectNamespace(), RSGI_SERVICE_HOST),

+

container.getConnectNamespace(), ROSGI_SERVICE_HOST),

IHello.class.getName(), null);

IHello.class.getName(), null);

Assert.isNotNull(helloReferences);

Assert.isNotNull(helloReferences);

Line 96:

Line 91:

IHello proxy = (IHello) remoteService.getProxy();

IHello proxy = (IHello) remoteService.getProxy();

// 6. Finally...call the proxy

// 6. Finally...call the proxy

−

proxy.hello("RemoteService Consumer");

+

String response = proxy.hello("RemoteService Consumer");

}

}

Line 121:

Line 116:

===Asynchronous Remote Method Invocation===

===Asynchronous Remote Method Invocation===

−

Sometimes it's desirable to invoke remote methods asynchronously, without blocking until the remote method call completes. This is sometimes desirable, for example, if your user interface thread is doing the calling, as remote methods can/could block for a much longer time than would be acceptable for users.

+

New: See support for [[Asynchronous Remote Services]]

−

ECF remote services provides an API to invoke remote methods with a guarantee that they will be executed asynchronously, in some other thread, and allowing the calling thread not to be blocked.

−

This capability is exposed via the IRemoteService. Here is the example code on the consumer to invoke the hello service asynchronously (non-blocking)

Gets the containerAdapter from the container instance so that remote services can be registered/accessed.

Creates and registers the IHello implementation.

Here is the expected output to the console for this host

osgi> IHello RemoteService registered

If you get the following warning when starting the host:

osgi> WARNING: Port 9278 already in use. This instance of R-OSGi is running on port 9279

This means that there is some other R-OSGi instance running on that same system, and that port 9278 is not available for use by the host. In this case, you need to stop the host, and disable the other R-OSGi instance before running the host again. To disable R-OSGI, see Disabling R-OSGi and R-OSGI Properties.

Using the Service (Consumer)

The ECF remote services API consumer essentially needs to lookup the remote reference, and then use the
Here is code from org.eclipse.ecf.internal.examples.remoteservices.hello.consumer.rs.Activator