Jump to: navigation, search

EIG:Install TimeService Tutorial into Apache Karaf

Introduction

See the Building your first OSGi Remote Services Tutorial to understand how to design and build this example.

Prior to running this tutorial you must install ECF Remote Services into your Karaf server.

Exporting the Remote Service with Karaf

To export the remote time service host with Apache Karaf simply install the timeservice host example feature

feature:install -v ecf-remoteservices-examples-timeservice-host

This will install two bundles: the timeservice API bundle (com.mycorp.examples.timeservice) and the timeservice host bundle (com.mycorp.examples.timeservice.host). When Karaf start these bundles, they are exported, and will produce the following output on console

Karafinst4.png

The output after the EXPORT_REGISTRATION indicates that the TimeService has been exported as a remote service and is ready for remote consumer discovery and usage.

For reference, this output is produced by the TimeService Examples Host activator class com.mycorp.examples.timeservice.host.Activator. The source for the entire bundle can be found in the ECF primary git repo, project path: examples/bundles/com.mycorp.examples.timeservice.host.

Debugging the Client Using Eclipse

For this part of the tutorial, the time service consumer will be a simple OSGi client, which will run in debug mode using Eclipse. For this the prerequisites are:

  1. Java 1.7 or Java 1.8
  2. Eclipse Mars (see here to download) with eGit
  3. ECF (see here to download and install)

Once the above are installed, add the ECF primary git repo to the git repos view

Karafinst5.png

and import from the examples/plugins directory the two projects: com.mycorp.examples.timeservice and com.mycorp.examples.timeservice.consumer.ds

Karafinst6.png

Open the TimeServiceComponent.java source from the com.mycorp.examples.timeservice.consumer.ds package in the project of the same name, and place a break point on the first code line of the bindTimeService method.

Karafinst7.png

The bindTimeService method will be called by Declarative Services when the ITimeService is discovered via remote services discovery. The instance of ITimeService will be an ECF-constructed proxy for accessing the remote ITimeService.

To start the client running in the debugger, open the editor of this product file: com.mycorp.examples.timeservice.consumer.ds/launch/TimeServiceConsumer.ds.generic.noreg.product. When ready to launch the client, click on Launch an Eclipse application in debug mode.

Karafinst8.png

After a few seconds the service should be discovered and the proxy injected into the bindTimeService method by declarative services, causing the Eclipse debugger to stop the client execution at the breakpoint set above.

NOTE: For this localhost example, the discovery provider used is Zeroconf (in bundle org.eclipse.ecf.provider.jmdns). Zeroconf uses multicast on a LAN. If you are not attached to a LAN, or the LAN you are on has restricted use of Zeroconf, the the remote service may not be automatically discovered by the client.

Karafinst9.png

Allow the execution to continue and the remote method will be invoked, and the current time reported by the Karaf server's remote service will be shown in the consumer's console

Karafinst10.png

Also, the Karaf console will show an indication that the remote service implementation method was invoked

Karafinst11.png