[kepler-dev] Publisher-Subscriber question

Christopher Brooks cxh at eecs.berkeley.edu
Fri Feb 12 10:10:31 PST 2010


Hi Ben,
The short answer is that in Ptolemy II,  tokens are usually immutable and
in the case of ptolemy.actor.lib.Publisher to multiple ptolemy.actor.lib.Subscribers,
each Subscriber will get a reference to the same Token object.

Page 33 of
http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-29.pdf
says

"A given channel may reach multiple ports, as shown in figure 2.5. This is represented by a relation
that is linked to multiple input ports. In the default implementation, in class IOPort, a reference to the
token is sent to all destinations. Note that tokens are assumed to be immutable, so the recipients cannot
modify the value. This is important because in most domains, it is not obvious in what order the recipients
will see the token.
The send() method takes a channel number argument. If the channel does not exist, the send()
method silently returns without sending the token anywhere. This makes it easier for model builders,
since they can simply leave ports unconnected if they are not interested in the output data.
IOPort provides a broadcast() method for convenience. This method sends a specified token to all
receivers linked to the port, regardless of the width of the port. If the width is zero, of course, the token
will not be sent anywhere."

Below is a more detailed analysis:

In the current development version of Ptolemy II, ptolemy.actor.lib.Publisher
and ptolemy.actor.lib.Subscriber defer the connection to CompositeActor.

CompositeActor.linkToPublishedPort() calls IOPort.liberalLink() which does
some checking, invalidates the schedule and calls ComponentPort._doLink().

_doLink() makes the connection between the Publisher and Subscriber.
Publisher.output is a regular multiport, though it can cross levels of
the hierarchy.  Publisher.fire()

    /** Read at most one input token from each
      *  input channel and send it to the subscribers,
      *  if any.
      *  @exception IllegalActionException If there is no director.
      */
     public void fire() throws IllegalActionException {
         super.fire();
         for (int i = 0; i < input.getWidth(); i++) {
             if (input.hasToken(i)) {
                 Token token = input.get(i);
                 output.send(i, token);
             }
         }
     }


In the above code, output.send(i, token) calls ptolemy.actor.TypedIOPort.send(i, token),
which, in IOPort(i, token), calls:

                 // Delegate to the receiver to handle putting to all
                 // receivers, since domain-specific techniques might be relevant.
                 farReceivers[channelIndex][0].putToAll(token,
                         farReceivers[channelIndex]);

In the SDF model of computation, ptolemy.domains.sdf.kernel.SDFReceiver.put() is
eventually called and puts the token on to the queue for the port.

Under SDF, all the Subscribers will have SDFReceivers, so each Subscriber will get
a reference to the same token.

So, the real answer is: it depends on the model of computation.


If you had a model for say, a water distribution system, and you wanted to
model distribution to different consumers, then it would probably be easier
to model the total availability of water as an input token and then have an actor
that received requests for water volumes and distributed water accordingly.
The actor could only distribute as much water as it actually has, and if
the demand exceeds supply, it would need to ration requests or starve them.
This sort of thing is a classic continuous time model involving water tanks and
such.  It can be simulated using SDF by looking at demand on a per iteration basis.

I hope this helps, and I hope I got it right . . .

_Christopher



On 2/12/10 9:20 AM, Knear, Benjamin wrote:
>
> Hi all,
>
> I understand that actors can output a token to a publisher to broadcast
> on a particular channel. And all subscribers with that channel will
> receive the token. But I'm wondering how the subscribers manage the
> token. Do they each receive a copy of the token? If I have an actor that
> broadcasts an amount of supply available to a publisher, I'm guessing
> all the subscribers will receive that same value. So all the subscribers
> that use that supply may use more than the supply available, because
> they are not realizing all of the subscribers using the supply. Is that
> correct?
>
> Thanks for the help!
> Ben
>
>
>
> _______________________________________________
> Kepler-dev mailing list
> Kepler-dev at kepler-project.org
> http://mercury.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-dev

-- 
Christopher Brooks, PMP                       University of California
CHESS Executive Director                      US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
ph: 510.643.9841 fax:510.642.2718	      (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670


More information about the Kepler-dev mailing list