The Register Service demo is a simple bundle which registers a Time Service in the OSGi framework. The Time Service provides the current system time.
The Register Service demo bundle is packed in the regservice.jar in the demo/bundles directory of the Framework Professional Edition Package .
The Java source files of the demo are in the The Java source files of the demo are in the demo/framework/basics/regservice directory.
The mkrs.bat recompiles and repacks the demo. Use this file if you have changed something in the source files of the demo.
The Register Service demo is included in the demo/framework/basics/install.txt install script. For more information about installing demos via install scripts, refer to General Rules for Demos.
To start the Register Service demo:
The Register Service demo consists of the following components:
demo.basics.registerservice.service.TimeService - The abstract
class which represents the Time Servicedemo.basics.registerservice.impl.service.simple.TimeServiceSimple
- The class which extends TimeService and contains the realization
of the servicedemo.basics.registerservice.impl.service.simple.RegisterService
- The bundle activator of the Register Service demoThe TimeService abstract class represents the Time service to
the other bundles running in the OSGi framework. This class has only one method
- getCurrentTime, which returns the current system time as a String.
The TimeServiceSimple extends TimeService and overrides
the getCurrentTime method. It calls the toString method
of TimeService passing java.util.GregorianCalendar
as argument. toString represents the current time in the following
format <day_of_week>, <dd> <mm> <yyyy> <hh>:<mm>:<ss>
<time_zone>.
public class TimeServiceSimple extends TimeService {
GregorianCalendar calendar;
public TimeServiceSimple() {
calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
}
public String getCurrentTime() {
return toString(calendar);
} |
When the bundle is started, the start method of the bundle activator
is called. The Register Service bundle registers the Time Service under the
TimeService abstract class with an implementation object TimeServiceSimple
and a service property TimeService.TIME_ZONE equal to "GMT".
Hashtable props = new Hashtable();
props.put(TimeService.TIME_ZONE, "GMT");
timeServReg = bc.registerService(TimeService.class.getName(), |