Delivering Events

Once an event is published, COM+ is responsible for delivering the event to the subscribers. By default, publishers have very little to do with the delivery itself, to ensure decoupling of publishers from subscribers. However, COM+ does provide you ways to fine-tune the delivery and obtain additional information on the result of firing the event to the subscribers.

Serial Versus Parallel Publishing

Events by default are fired serially at subscribers—COM+ goes through the list of subscribers and publishes to them one at a time. The call to the event class does not return to the publisher until the last subscriber is notified. As a result, the publisher is blocked during publishing. To minimize the blocking time, you can configure your event class to use multiple threads for publishing by checking the "Fire in parallel” checkbox in the Advanced tab of the event class properties page (see Figure 9-4).

This setting is a mere request that COM+ will fire in parallel, and COM+ is not required to comply. COM+ uses threads from the RPC pool of threads to publish to subscribers, so parallel publishing is subjected to pool limitations. You should consider Fire in parallel as an optimization technique only; avoid relying on it in your design. For example, do not count on having all the subscribers get the event at the same time.

Error Handling

When an event class succeeds in publishing to all the subscribers, it returns S_OK to the publisher. If the event is delivered to COM+ but there are no subscribers, the return code is EVENT_S_NOSUBSCRIBERS . If the event is delivered, but is unable to invoke any of the subscribers, the return code is EVENT_E_ALL_SUBSCRIBERS_FAILED . In the case of partial delivery (an event that invokes some, but not all, subscribers), the return code is EVENT_S_SOME_SUBSCRIBERS_FAILED .

To promote loose coupling between the publisher and the subscribers, COM+ does not provide success or failure information about delivery for particular subscribers. The rationale is that publishers should not care about particular subscribers.

However, if your publisher does care about success or failure when delivering events to particular subscribers, you can implement a publisher filter to handle this case, which is discussed in the next section.

Publishing Order

COM+ does not, by default, provide a way to specify the order in which an event gets delivered to multiple subscribers. The publisher fires at the event class, and under-the-hood COM+ scans the list of subscribers and publishes to them. The events are published one at a time to the subscribers, in no determined or necessarily repeatable order. Publishers can control the order in which subscribers receive an event by implementing a publisher filter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset