EIG:Install TimeService Tutorial into Apache Karaf
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-rs-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
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.
Running/Debugging the TimeService Client in Eclipse
For this part of the tutorial, the time service consumer will be a simple OSGi client, which will run in Eclipse. For this the prerequisites are:
- Java 1.8
- Eclipse (see here to download) with eGit installed
- ECF SDK for Eclipse (see here to download and install)
Once the above are installed, clone the ECF git repo in the Git Repositories View (only master branch is needed).
and then Import Projects these two projects from the examples/plugins directory: com.mycorp.examples.timeservice.async and com.mycorp.examples.timeservice.consumer.ds.async
Open the TimeServiceComponentAsync.java source from the com.mycorp.examples.timeservice.consumer.ds.async package in the project of the same name, and place a break point on the first code line of the bindTimeService method.
The bindTimeService method will be called by Declarative Services when the ITimeServiceAsync is discovered via Zeroconf LAN-based remote services discovery. The instance of ITimeServiceAsync will be an ECF-constructed proxy service for accessing the remote ITimeService via the Java8 CompletableFuture.
To start the client running in the debugger, open the editor of this product file: com.mycorp.examples.timeservice.consumer.ds.async/TimeServiceConsumer.generic.zeroconf.product. When ready to launch the client, click on 'Launch an Eclipse Application in Debug Mode' in the lower-left part of the Overview tab.
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 remote service may not be automatically discovered by the client.
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
Also, the Karaf console will show an indication that the remote service implementation method was invoked