public interface EPublisher extends EObject
advertisethe notification feeds it supports. Once eBus accepts the advertisement, a publisher has two options:
publishStatus(EFeedState, EPublishFeed)method where
feed. In this option, it is necessary to call
upstatus before publishing the first notification.
upfeed state and then start publishing notifications on that feed after checking that
EPublishFeed.publish(net.sf.eBus.messages.ENotificationMessage). Alternatively, catch
EPublishFeed.publish()when the feed is down.
When the application publisher shuts down, then it should
EFeed.close() the feed. There is no need to
EPublishFeed.updateFeedState(EFeedState.DOWN) as this
is automatically done by
close. If the publisher does not do this, eBus will
automatically retract the advertisement when it detects the
publisher is finalized.
As of eBus v. 4.2.0, implementing the interface methods is no
longer necessary. Instead, Java lambda expressions may be used
to handle publisher callbacks. This is done by calling
using a lambda expression to specify the callback target.
Still, the application must either override
callback method or put the status callback in place. Failure
to do either results in
failing. A class wishing to publish notification messages must
EPublisher even though it is no longer
necessary to override the interface method.
The reason for separate
EPublishFeed.updateFeedState(EFeedState) methods is
to distinguish between the publisher existing or not and
whether the publisher is able to publish the notification.
Here are two examples of how to use
opensits notification feed and
advertisesit. Once the application publisher opens the serial port and establishes communication with the monitor, the publisher then
reportsthe feed is
up. If communication to the monitor is lost, then a
downfeed state is reported. This feed state continues until monitor communications is re-established.
EPublisher. This instance performs value-added computation on the received notifications and publishes the results. Again, the instance opens and advertises its feed but leaves its initial publish status in the down state. The instance then subscribes to its inbound feeds. When all those feeds are up, the instance then sets its outbound feed state to up. If any of the inbound feeds receives a
feed state updatewith a
downstate, then the published feed is then set to down. This continues until the inbound feed comes back up. This is an example of a publish state change cascading along a publisher, subscriber chain.
If the application publisher is always capable of publishing
its feed without interruption, then it is sufficient to call
|Modifier and Type||Method and Description|
eBus is requesting that the publisher either start or stop publishing the specified feed.
default void publishStatus(EFeedState feedState, EPublishFeed feed)
up, the publisher is free to start publishing notification messages on the feed when
EPublishFeed.updateFeedState(EFeedState)is called with an up state. If
down, then the publisher may not publish notifications on the feed.
Note: a publisher is allowed to publish
notifications feed after
publishStatus is called
with an up state and the publisher calls
EPublishFeed.updateFeedState(EFeedState) with an
up state. There is no order for these two events and are
independent of each other.
default definition which throws an
UnsupportedOperationException. The reason for this
default method implementation is to allow users to define
a separate method with the signature
void (EFeedState, EPublishFeed) and then use
use that defined method for