Thursday, September 24, 2009

Running demo in Eclipse Equinox

Running in Eclipse Equinox: Look up basic instructions on equinox quickstart.
Add the following to your config.ini file (note two versions of the same complexapp):

osgi.bundles=javax.servlet_2.4.0.jar@start, services-3.1.2.jar@start, org.eclipse.equinox.http.jar@start, shared-1.0-SNAPSHOT.jar@start, http.handler-1.0-SNAPSHOT.jar@start, complexapp-1.0-SNAPSHOT.jar@start, complexapp-2.0-SNAPSHOT.jar@start
Testing it out: Start Equinox with -console so you have the osgi prompt. Here is a log of commands and interesting portions are highlighted (running on Windows).
rahul@lappy /cygdrive/c/osgidemo/runtime
$ java -jar org.eclipse.osgi_3.5.0.jar -console <-- Start with console
osgi> http.handler started! <-- osgi prompt
New Service added
New Service added
osgi> ss
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.5.0.v20090520
1 ACTIVE javax.servlet_2.4.0.v200806031604
2 ACTIVE org.eclipse.osgi.services_3.1.200.v20070605
3 ACTIVE org.eclipse.equinox.http_1.0.300.v20090520-1800
4 ACTIVE com.irahul.shared_1.0.0.SNAPSHOT
5 ACTIVE com.irahul.http.handler_1.0.0.SNAPSHOT
6 ACTIVE com.irahul.complexapp_1.0.0.SNAPSHOT
7 ACTIVE com.irahul.complexapp_2.0.0.SNAPSHOT
osgi> bundle 5
com.irahul.http.handler_1.0.0.SNAPSHOT [5]
Id=5, Status=ACTIVE Data Root=C:\osgidemo\runtime\configuration\org.eclip
se.osgi\bundles\5\data
No registered services.
Services in use: <-- Services used, noticed multiple ComplexService
{com.irahul.shared.ComplexService}={service.id=30}
{org.osgi.service.http.HttpService}={http.port=80, service.pid=org.eclipse.e
quinox.http.HttpService-http, http.address=ALL, service.vendor=IBM, service.desc
ription=OSGi Http Service – IBM Implementation, http.scheme=http, http.timeout=3
0, service.id=26}
{com.irahul.shared.ComplexService}={service.id=29}
No exported packages
Imported packages <-- Pacakages being imported
com.irahul.shared; version=”0.0.0″
javax.servlet; version=”2.4.0″
org.eclipse.equinox.http; version=”0.0.0″org.eclipse.equinox.http_1.0.300.v  20090520-1800="" [0]="" [3]>="" org.osgi.framework;="" version="”1.5.0″<org.eclipse.osgi_3.5.0.v20090520">
org.osgi.service.http; version=”1.2.0″
osgi> bundle 6
com.irahul.complexapp_1.0.0.SNAPSHOT [6]
Id=6, Status=ACTIVE Data Root=C:\osgidemo\runtime\configuration\org.eclip
se.osgi\bundles\6\data
Registered Services
{com.irahul.shared.ComplexService}={service.id=29}
No services in use.
No exported packages
Imported packages
com.irahul.shared
; version=”0.0.0″
org.osgi.framework; version=”1.5.0″
No fragment bundles
Named class space
com.irahul.complexapp; bundle-version=”1.0.0.SNAPSHOT”[provided]
No required bundles
osgi> bundle 7
com.irahul.complexapp_2.0.0.SNAPSHOT [7]
Id=7, Status=ACTIVE Data Root=C:\osgidemo\runtime\configuration\org.eclip
se.osgi\bundles\7\data
Registered Services
{com.irahul.shared.ComplexService}={service.id=30}
No services in use.
No exported packages
Imported packages
com.irahul.shared;
 version=”0.0.0″
org.osgi.framework; version=”1.5.0″
No fragment bundles
Named class space
com.irahul.complexapp; bundle-version=”2.0.0.SNAPSHOT”[provided]
No required bundles
osgi> stop 6
Service stopped
osgi> stop 7
Service stopped
osgi> ss
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.5.0.v20090520
1 ACTIVE javax.servlet_2.4.0.v200806031604
2 ACTIVE org.eclipse.osgi.services_3.1.200.v20070605
3 ACTIVE org.eclipse.equinox.http_1.0.300.v20090520-1800
4 ACTIVE com.irahul.shared_1.0.0.SNAPSHOT
5 ACTIVE com.irahul.http.handler_1.0.0.SNAPSHOT
6 RESOLVED com.irahul.complexapp_1.0.0.SNAPSHOT
7 RESOLVED com.irahul.complexapp_2.0.0.SNAPSHOT
osgi> bundle 5
com.irahul.http.handler_1.0.0.SNAPSHOT [5]
Id=5, Status=ACTIVE Data Root=C:\osgidemo\runtime\configuration\org.eclip
se.osgi\bundles\5\data
No registered services.
Services in use: <-- ComplexService disappear
{org.osgi.service.http.HttpService}={http.port=80, service.pid=org.eclipse.e
quinox.http.HttpService-http, http.address=ALL, service.vendor=IBM, service.desc
ription=OSGi Http Service - IBM Implementation, http.scheme=http, http.timeout=3
0, service.id=26}
No exported packages
Imported packages
com.irahul.shared; version="0.0.0"
javax.servlet; version=”2.4.0″
org.eclipse.equinox.http; version=”0.0.0″
org.osgi.service.http; version=”1.2.0″
osgi>
You can access the handler registered at http://localhost. Open it in a browser and hit refresh a few times, you should see a different message as a random service is picked! Then as you stop/start the complexapp bundles you can expect to see different messages.

Next: Spring Dynamic Modules (SpringDM) implementation for this same demo app

No comments: