Inspirel banner

Programming Distributed Systems with YAMI4

6.4.4 .NET

Assuming that the agent is already properly set up, the publisher side in C# can be implemented as follows:

ValuePublisher myValue;

myAgent.RegisterValuePublisher("some_value", myValue);

Above, myAgent is an agent object that will be used to manage all communication for this value publisher and "some_value" is an object name that will be visible to remote agents. This operation internally registers a regular object with the given name and provides the message handler that understands the ``subscribe'' and ``unsubscribe'' messages and implements proper management of subscribers.

The publisher can send new parameters value by calling the Publish() function with new value:

Parameters content = new Parameters()
// fill the content object appropriately
// ...


When the Publish() function is invoked, all subscribers that are on the internally managed list are notified with a message named "subscription_update" that is sent to the object which name was given when the subscription was established.

The user-defined delegate can be provided as a constructor parameter when the published value is created in order to extend the functionality of the value publisher with user-provided implementations of additional messages. Any regular handler can be registered (at most once) and all messages that are received by the value publisher will be delegated to that additional handler.

The ValuePublisher object has to be Close()d when it is no longer in use, to release its internal resources.