DwarfMiddlewareTutorialLesson5

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

Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson6, back to DwarfMiddlewareTutorialLesson4

Lesson 5: Multiple services using templates

In this lesson, you will learn how to create multiple instances of the same service.

Reconfigure the time client and server

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

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

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

This lesson introduces the isTemplate attribute. By default, it is false, and only one instance of the service may exist on the host at any time. This makes sense for services that encapsulate physical resources, such as trackers or displays. When it is true, there may be any number of instances of this service running.

In this example, only the client is a template; the TimeService will behave as before.

Try it out

In one terminal, run TimeService. In three other terminals, run TimeClient. All three clients will be able to run and connect to the TimeService, showing this DIVE image:

Time Service and Three Clients

The service manager shows the multiple instances of the time clients starting up, called TimeClient1 to TimeClient3. Note that an additional service description, TimeClient4, is kept in reserve, so that it can prepare to set up connections even before the service itself is started.

19:19:44.999  3348  2 servicemgr.cpp       171 ServiceManager_i  1/ 1 services: newServiceDescription(TimeClient)
19:19:45.017  3348  2 servicemgr.cpp       171 ServiceManager_i  2/ 1 services: newServiceDescription(TimeService)
19:19:45.033  3351  2 servicemgr.cpp       191 ServiceManager_i  3/ 1 services: addClonedServiceDescription(TimeClient1)
19:19:45.042  3348  2 servicemgr.cpp       171 ServiceManager_i  4/ 1 services: newServiceDescription(DIVE)
19:19:45.096  3348  2 servicemgr.cpp       171 ServiceManager_i  5/ 1 services: newServiceDescription(ServiceReporter)
19:20:02.946  3389  2 servicemgr.cpp       141 ServiceManager_i  6/ 1 services: registerService(TimeService)
19:20:06.936  3404  2 servicemgr.cpp       141 ServiceManager_i  6/ 2 services: registerService(TimeClient)
19:20:06.948  3351  2 servicemgr.cpp       191 ServiceManager_i  6/ 2 services: addClonedServiceDescription(TimeClient2)
19:20:07.067  3411  2 servicemgr.cpp       141 ServiceManager_i  7/ 3 services: registerService(TimeClient)
19:20:07.083  3351  2 servicemgr.cpp       191 ServiceManager_i  7/ 3 services: addClonedServiceDescription(TimeClient3)
19:20:07.087  3413  2 servicemgr.cpp       141 ServiceManager_i  8/ 4 services: registerService(TimeClient)
19:20:07.111  3351  2 servicemgr.cpp       191 ServiceManager_i  8/ 4 services: addClonedServiceDescription(TimeClient4)

In another terminal, run TimeService again, while one instance is already running. Since isTemplate=false for TimeService, an error message occurs:

**********************************************
*  Detected run-time error in thread 4966   *
19:48:17.721  4966  0 activeservicedesc.cp 450 ActiveServiceDescription_i TimeService,Started: service alredy registered
19:48:17.713  4966  5 activeservicedesc.cp 435 ActiveServiceDescription_i TimeService,Started: registerService
19:48:17.712  4966  2 servicemgr.cpp       141 ServiceManager_i  9/ 5 services: registerService(TimeService)
**********************************************

Now, set isTemplate=true for the TimeService. This will allow you to start more than one TimeService at a time. However, the TimeClients will still only connect to one TimeService each - in fact, this will usually be the first one.

Exercise 5.1 How many TimeClients can you start until the machine you are using becomes unusable?


Up to DwarfMiddlewareTutorial, forward to DwarfMiddlewareTutorialLesson6, back to DwarfMiddlewareTutorialLesson4

-- AsaMacWilliams - 17 Jul 2003


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

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