DwarfMiddlewareTutorialLesson3

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson4, back to DwarfMiddlewareTutorialLesson2

Lesson 3: Starting services on demand

(use TimeService and TimeClient with specific XML files)

In this lesson, you will learn how a service can be started automatically when it is needed by another service.

Reconfigure the time client and server

Use the installed binaries TimeService and TimeClient of lesson 2, and start up the service manager.

Run make all in (top build directory)/src/tutorials/middleware/lesson3. This will install two new service descriptions:

TimeService TimeClient
<service name="TimeService"
   startOnDemand="true" stopOnNoUse="true"
   startCommand="TimeService">
   <ability name="giveTime" type="TimeOfDay">
      <connector protocol="ObjrefExporter"/>
   </ability>
</service>
<service name="TimeClient"
   startOnDemand="false" stopOnNoUse="false">
   <need name="time" type="TimeOfDay">
      <connector protocol="ObjrefImporter"/>
   </need>
</service>

Note the new XML tags:

  • startOnDemand: This indicates that the service manager should start the service only when an ability is requested by another service. The default is false; thus, the TimeClient will behave as in lesson 2.
  • stopOnNoUse: These indicates that the service manager should shut the service down when no abilities are requested anymore. Again, the default is false.
  • startCommand: This is the name of a binary or jar file in the installation directory that the service manager should execute in order to load the service.

Try it out

In one terminal, run TimeClient. A new xterm window called TimeService will open automatically and run a Time Service.

The service manager shows what's going on: the TimeClient registers itself; the service manager launches an executable for the TimeService, and once the executable is started, it registers itself with the service manager.

13:52:19.765 26060  2 servicemgr.cpp       141 ServiceManager_i 33/ 1 services: registerService(TimeClient)
13:52:19.804 26051  2 defaultsvcload.cpp   099 DefaultSvcLoad : loadService: running /home/macwilli/test/bin/TimeService
13:52:21.931 26094  2 servicemgr.cpp       141 ServiceManager_i 33/ 2 services: registerService(TimeService)

Press Control-C to terminate the TimeClient. After a while of idling, the TimeService will be killed by the service manager:

13:52:41.150 26052  2 activeservicedesc.cp 782 ActiveServiceDescription_i TimeClient,Started: lost connection to service
13:52:41.162 26052  2 servicemgr.cpp       266 ServiceManager_i 33/ 2 services: deletedServiceDescription(TimeClient)
13:52:41.953 25874  2 servicemgr.cpp       171 ServiceManager_i 32/ 2 services: newServiceDescription(TimeClient)
13:52:56.329 26051  2 defaultsvcload.cpp   152 DefaultSvcLoad : loadService: killing process 26063, service TimeService
13:52:56.339 26051  2 servicemgr.cpp       266 ServiceManager_i 33/ 1 services: deletedServiceDescription(TimeService)
13:52:57.864 25874  2 servicemgr.cpp       171 ServiceManager_i 32/ 1 services: newServiceDescription(TimeService)

Exercise 3.1 Try running the TimeService manually, without a TimeClient running. What happens? How does the service manager know which process ID to kill?

Exercise 3.2 Edit the installed TimeClient.xml to read startOnDemand=true. Why doesn't this work?

Exercise 3.3 Edit the installed TimeClient.xml and add stopOnNoUse=true. What is going wrong here?

Exercise 3.4 Start the TimeClient, and close the window of the TimeService once it is up and running. What happens? Use your improved version of the TimeClient from Exercise 2.4. What happens now?

The SvcStartup interface

A service may implement the SvcStartup interface, as defined in Service.idl:

   interface SvcStartup {
      void startService(in ActiveServiceDescription serviceDesc);
      void stopService(in ActiveServiceDescription serviceDesc);
   };

The service manager calls the methods startService and stopService when a service is started or stopped. This allows a service to perform initialization and cleanup tasks, such as starting or stopping worker threads.

Exercise 3.5 Write a NewTimeService that implements the SvcStartup interface:

  • Define a new aggregation interface NewTimeService in Tutorial.idl that inherits from SvcStartup, Service and Clock.
  • Copy lesson2/TimeService.cpp to lesson3/NewTimeService.cpp, and edit the Makefile.am appropriately to create and install a NewTimeService binary. Modify TimeService.xml to launch this binary.
  • Implement the SvcStartup interface in NewTimeService. Note: you will have to derive from POA_DWARF::NewTimeService.
  • Display a greeting message on service startup and shutdown.


Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson4, back to DwarfMiddlewareTutorialLesson2

-- AsaMacWilliams - 17 Jul 2003


Edit | Attach | Refresh | Diffs | More | Revision r1.6 - 17 Mar 2005 - 21:09 - NikolasDoerfler

Lehrstuhl für Computer Aided Medical Procedures & Augmented Reality    rss.gif