Get Service Demo

The Get Service demo is a simple bundle, which calls the Time Service registered by the Register Service and by the Register Service Factory demos.

Demo Components

The JAR of the Get Service demo is getservice.jar in the demo/bundles directory.

The source files of the demo are located in the demo/framework/basics/getservice directory of the Framework Professional Edition Package . If you have changed the source of the demo, to recompile and repack it use the mkgs script.

Starting the Demo

Using an Install Script

The Get 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.

Activating All Necessary Components Manually

  1. Start the OSGi framework.
  2. Make sure that the ProSyst Util Bundle or ProSyst Utill Full Bundle is running.
  3. Install and start the Register Service (demo/bundles/regservice.jar) or Register Service Factory (/demo/bundles/regservicefactory.jar) demo.
  4. Install and start the Get Service demo bundle using its JAR.

Inside the Demo

The Get Service demo contains a single class - demo.basics.getservice.GetService. It is a bundle activator which refers to the Time Service of the Register Service or Register Service Factory demo.

When the Get Service demo bundle is started, it gets the TimeService service and calls its method. It sends the results to the OSGi Log service and to the framework console via the log utility of the ProSyst Util Bundle.

                   . . .
      log = new Log(bc);
      log.setDebug(true);
      log.setPrintOnConsole(true);
       
      timeRef = bc.getServiceReference(TimeService.class.getName());
        if (timeRef != null) {
        timeService = (TimeService) bc.getService(timeRef);
      }
       
      if (timeService == null) {
        log.info("[GetServiceDemo] TimeService NOT found!");
        return;
      }
       
      log.info("[GetServiceDemo] TimeService found: "
+ timeRef.getProperty(timeService.TIME_ZONE)); log.info("[GetServiceDemo] Current time: " + timeService.getCurrentTime()); . . .
Listing 1: Getting a service.

Basic Demos