public interface EReplier extends EObject
open
the reply feed,
advertise this reply ability, and
declare
with an up feed state that it (the replier) is ready to
handle requests.
A replier can retract an advertisement by calling
EReplyFeed.unadvertise(). The reply feed is discarded
by calling EFeed.close(). If a replier is
temporarily unable to reply to a request, then
updateFeedState(EFeedState.DOWN) should be used rather
than un-advertising. When the replier is again able to
respond, updateFeedState(EFeedState.UP) is called.
Requests matching the advertised reply feed are forwarded as
EReplyFeed.ERequest instances via the
request(EReplyFeed.ERequest)
callback. Replies are sent via
EReplyFeed.ERequest.reply(net.sf.eBus.messages.EReplyMessage).
Note: the replier is limited to
reply messages
specified in the
request message's
EReplyInfo annotation or in the
request message super class (EReplyInfo is inherited).
If the reply message is not a member of
EReplyInfo.replyMessageClasses(),
then it will be rejected.
If a requestor cancels a request, the replier is informed by
the cancelRequest(EReplyFeed.ERequest)
callback. The request is unilaterally ended by the
requestor and the replier may no longer
send replies to the request.
As of eBus v. 4.2.0, implementing the interface methods is no
longer necessary. Instead, Java lambda expressions may be used
to handle replier callbacks. This is done by calling
EReplyFeed.requestCallback(RequestCallback) and/or
EReplyFeed.cancelRequestCallback(CancelRequestCallback)
and passing a lambda expression to specify the callback
target. Still, the application must either override
EReplier interface methods or put callbacks in place.
Failure to do either results in EReplyFeed.advertise()
failing. A class wishing to receive requests must still
implement EReplier even though it is no longer
necessary to override the interface methods.
It is possible to mix and match EReplier overrides and
callbacks. That is, a request callback can be used in
conjunction with a
cancelRequest(EReplyFeed.ERequest) override.
eBus maintains a weak reference to application objects. If a replier is garbage collected without un-advertising and closing its reply feed, eBus automatically closes the feed and posts failure replies to all active requests.
ERequestor,
EReplyFeed.ERequest,
EReplyFeed,
ERequestMessage,
EReplyMessage| Modifier and Type | Method and Description |
|---|---|
default void |
cancelRequest(EReplyFeed.ERequest request)
The specified request is canceled by the
requestor. |
default void |
request(EReplyFeed.ERequest request)
An incoming request.
|
default void request(EReplyFeed.ERequest request)
reply
either from within this method call or asynchronously
after returning from this method. If the reply is sent
asynchronously, then the replier must store
request for later use. Replies are sent using
ERequest and not EReplyFeed.
The
request message
is stored in request and can be retrieved by
calling EReplyFeed.ERequest.request().
The request matches the
replier's open and advertised feed. The
associated EReplyFeed may be retrieved by calling
EReplyFeed.ERequest.replier().
request - post replies via this request.UnsupportedOperationException - if implementing class does not override this method nor
uses a callback.cancelRequest(EReplyFeed.ERequest)default void cancelRequest(EReplyFeed.ERequest request)
requestor. The request is shut down and
no further replies will be accepted. However, in-flight
replies posted prior to cancellation may still be
delivered.
The request matches the
replier's open and advertised feed. The
associated EReplyFeed may be retrieved by calling
EReplyFeed.ERequest.replier().
request - cancel this request.UnsupportedOperationException - if implementing class does not override this method nor
uses a callback.request(EReplyFeed.ERequest)Copyright © 2019. All rights reserved.