Skip to main content
Jump to: navigation, search

Difference between revisions of "EIG:Install TimeService Tutorial into Apache Karaf"

(Importing and using the Remote Service Using Eclipse)
(Debugging the Client Using Eclipse)
Line 19: Line 19:
 
For reference, this output is produced by the TimeService Examples Host activator class  [http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java com.mycorp.examples.timeservice.host.Activator].  The source for the entire bundle can be found in the [http://git.eclipse.org/c/ecf/org.eclipse.ecf.git ECF primary git repo], project path:  examples/bundles/com.mycorp.examples.timeservice.host.
 
For reference, this output is produced by the TimeService Examples Host activator class  [http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java com.mycorp.examples.timeservice.host.Activator].  The source for the entire bundle can be found in the [http://git.eclipse.org/c/ecf/org.eclipse.ecf.git ECF primary git repo], project path:  examples/bundles/com.mycorp.examples.timeservice.host.
  
==Debugging the Client Using Eclipse==
+
==Running/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:
+
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.7 or Java 1.8
+
#Java 1.8
#Eclipse Mars (see [https://www.eclipse.org/downloads/ here to download]) with eGit  
+
#Eclipse (see [https://www.eclipse.org/downloads/ here to download]) with eGit installed
#ECF (see [http://www.eclipse.org/ecf/downloads.php here to download and install])
+
#ECF SDK for Eclipse (see [http://www.eclipse.org/ecf/downloads.php here to download and install])
  
Once the above are installed, add the [http://git.eclipse.org/c/ecf/org.eclipse.ecf.git ECF primary git repo] to the git repos view
+
Once the above are installed, clone the [http://git.eclipse.org/gitroot/ecf/org.eclipse.ecf.git ECF git repo] in the Git Repositories View (only master branch is needed).
  
 
[[File:Karafinst5.png]]
 
[[File:Karafinst5.png]]
  
and import from the examples/plugins directory the two projects:  com.mycorp.examples.timeservice and com.mycorp.examples.timeservice.consumer.ds
+
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
  
 
[[File:Karafinst6.png]]
 
[[File:Karafinst6.png]]

Revision as of 19:29, 4 December 2016

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.

Running/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 Eclipse. For this the prerequisites are:

  1. Java 1.8
  2. Eclipse (see here to download) with eGit installed
  3. 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).

Karafinst5.png

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

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

Back to the top