Up to
DwarfMiddlewareTutorial, forward to
DwarfMiddlewareTutorialLesson5, back to
DwarfMiddlewareTutorialLesson3
Lesson 4: Attributes for abilities, predicates for needs
In this lesson, you will learn how to perform a finer-grained selection of abilities to fulfill a given need.
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/lesson4
. This will install two new service descriptions:
TimeService | TimeClient |
<service name="TimeService">
<ability name="giveTime" type="TimeOfDay">
<attribute name="accuracy" value="low"/>
<connector protocol="ObjrefExporter"/>
</ability>
</service>
|
<service name="TimeClient">
<need name="time" type="TimeOfDay"
predicate="(accuracy=high)">
<connector protocol="ObjrefImporter"/>
</need>
</service>
|
An ability may have attributes, specified by name-value pairs. Here, the
TimeOfDay
ability has the attribute
accuracy
with a value of
low
.
Likewise, a need may have a predicate, specified as a boolean expression in LDAP notation. This basically means prefixing operators and a lot of parentheses, e.g.
(|(a=1)(!(b=2)))
. Note that the ampersand, the
and operator, must be escaped as & in XML.
Try it out
In one terminal, run
TimeClient
. In another, run
TimeService
. Nothing will happen. In DIVE, you will see two services that are not connected:
When you inspect the
TimeOfDay
need and ability in DIVE, you will see the attribute values and predicate. Note that many attributes are built-in and set by the service manager. Also note that a service itself may have attributes, which are inherited by the ability. Even a need may have attributes, but these are not used for selection of the communication partner.
Now modify
TimeService.xml
so that the
accuracy
attribute is
high
. The service manager will re-read the XML file, but still nothing will happen. In fact, the service manager has disconnected the running
TimeService
from its service description, since the XML file has changed. Restart the
TimeService
and the two services will be connected:
Exercise 4.1 Add another attribute to the
TimeService
, and try out a matching and a non-matching boolean expression for the
TimeClient
.
Exercise 4.2 Make the
TimeService
have three different abilities of type
TimeOfDay
, differing in their
name
, each with a different value of
accuracy
. Create a boolean expression for the
TimeClient
so that it will connect only to the third of these needs, creating this image in DIVE:
Exercise 4.3 Predicates may contain wildcards, e.g.
fo*ba*
matches
foobar
and
foambath
. Try this out.
Exercise 4.4 Work with another user on a second machine. Each run a service manager, DIVE, a Time Service and a Time Client. Turn on the "show host name" option in DIVE. By default, each Time Client will connect to the Time Server on its own machine. Reverse this using attributes, creating this image in DIVE:
The SvcSelection interface
A service may implement the
SvcSelection
interface, as defined in
Service.idl
:
interface SvcSelection {
void foundPartners(in ActiveServiceDescription serviceDesc,
in string needabilityname, in PartnerSeq partners);
};
The service manager calls this for a service that has a need, order to let the service choose its partner on its own. Normally, you have no need to do this; boolean expressions and wildcards will suffice.
Exercise 4.5 Write a
NewTimeService
that implements the
SvcSelection
interface and selects partners that have a
number
attribute which is prime.
Up to
DwarfMiddlewareTutorial, forward to
DwarfMiddlewareTutorialLesson5, back to
DwarfMiddlewareTutorialLesson3
--
AsaMacWilliams - 17 Jul 2003