Class ERequestFeed.Builder
- java.lang.Object
-
- net.sf.eBus.client.EFeed.Builder<F,T,B>
-
- net.sf.eBus.client.ERequestFeed.Builder
-
- Enclosing class:
- ERequestFeed
public static final class ERequestFeed.Builder extends EFeed.Builder<F,T,B>
EREquestFeed.Builder
is now the preferred mechanism for creating aERequestFeed
instance. ABuilder
instance is acquired fromERequestFeed.builder()
. The following example shows how to create anERequestFeed
instance using aBuilder
. The code assumes that the class implementsERequestor
interfacefeedStatus
method but uses other methods for reply messages. The exampleCatalogOrder
request message supports two replies besides the genericEReplyMessage
:OrderRejectReply
andOrderUpdateReply
.@Override public void startup() { final EMessageKey key = new EMessageKey(com.acme.CatalogOrder.class, subject); final ERequestFeed feed = (ERequestFeed.builder()).target(this) .messageKey(key) Message key must be set prior to setting reply callbacks. .scope(EFeed.FeedScope.REMOTE_ONLY) // Call .statusCallback(lambda expression) to replace feedStatus method // Set different callback for each reply message class. .replyCallback(EReplyMessage.class, this::genericReply) .replyCallback(OrderRejectReply.class, this::orderReject) .replyCallback(OrderUpdateReply.class, this::orderUpdate) .build(); ... }
- See Also:
ERequestFeed.builder()
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.client.EFeed.Builder
mEClient, mLocation, mScope, mTarget, mTargetClass
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ERequestFeed
buildImpl()
Returns a newERequrestFeed
instance based onthis Builder
's configuration.protected net.sf.eBus.client.ESubject
getSubject()
Returns eBus subject for the configured message key.ERequestFeed.Builder
mayClose(boolean flag)
Sets "may close" flag to given value.ERequestFeed.Builder
messageKey(EMessageKey key)
Sets eBus message key defining this feed.ERequestFeed.Builder
replyCallback(java.lang.Class<? extends EReplyMessage> mc, ReplyCallback cb)
Sets the callback for a specific reply message class.ERequestFeed.Builder
replyCallback(ReplyCallback cb)
Sets reply callback for all message classes.protected ERequestFeed.Builder
self()
Returnsthis
reference.ERequestFeed.Builder
statusCallback(FeedStatusCallback<IERequestFeed> cb)
Puts the feed status callback in place.protected Validator
validate(Validator problems)
Checks if message key is set.-
Methods inherited from class net.sf.eBus.client.EFeed.Builder
build, isOverridden, scope, target
-
-
-
-
Method Detail
-
getSubject
protected net.sf.eBus.client.ESubject getSubject()
Returns eBus subject for the configured message key.- Returns:
- eBus feed subject.
-
validate
protected Validator validate(Validator problems)
Checks if message key is set.- Parameters:
problems
- place invalid configuration settings in this problems list.- Returns:
problems
to allow for method chaining.
-
buildImpl
protected ERequestFeed buildImpl()
Returns a newERequrestFeed
instance based onthis Builder
's configuration.- Specified by:
buildImpl
in classEFeed.Builder<ERequestFeed,ERequestor,ERequestFeed.Builder>
- Returns:
- new request feed.
-
self
protected ERequestFeed.Builder self()
Returnsthis
reference.- Specified by:
self
in classEFeed.Builder<ERequestFeed,ERequestor,ERequestFeed.Builder>
- Returns:
this
reference.
-
messageKey
public ERequestFeed.Builder messageKey(EMessageKey key)
Sets eBus message key defining this feed. Returnsthis Builder
instance so that configuration methods may be chained.- Parameters:
key
- eBus message key.- Returns:
this Builder
instance.- Throws:
java.lang.NullPointerException
- iftarget
isnull
.
-
mayClose
public ERequestFeed.Builder mayClose(boolean flag)
Sets "may close" flag to given value. Atrue
means requester has ability to close an active request;false
means requester may not cancel an active request and must wait for the request to complete.Defaults to
true
.- Parameters:
flag
-true
means request may be closed.- Returns:
this Builder
instance.
-
statusCallback
public ERequestFeed.Builder statusCallback(FeedStatusCallback<IERequestFeed> cb)
Puts the feed status callback in place. Ifcb
is notnull
, feed status updates will be passed tocb
rather thanERequestor.feedStatus(EFeedState, IERequestFeed)
. Anull cb
results in feed status updates posted to theERequestor.feedStatus(EFeedState, IERequestFeed)
override.The following example shows how to use this method:
statusCallback( (fs, f) → { if (fs == EFeedState.DOWN) { // Clean up in-progress work. } }
- Parameters:
cb
- feed status update callback. May benull
.- Returns:
this Builder
instance.
-
replyCallback
public ERequestFeed.Builder replyCallback(java.lang.Class<? extends EReplyMessage> mc, ReplyCallback cb)
Sets the callback for a specific reply message class. Ifcb
is notnull
, replies will be passed tocb
rather thanERequestor.reply(int, EReplyMessage, ERequestFeed.ERequest)
. Acb
results in replies posted to theERequestor.reply(int, EReplyMessage, ERequestFeed.ERequest)
override.If the goal is to set a single callback method for all reply message types, then use
replyCallback(ReplyCallback)
. Note that method overrides all previous set reply callbacks.The following example shows how to use this method to set a reply callback lambda expression:
OrderRejectReply.class, this::orderReject
- Parameters:
mc
- the reply message class.cb
- callback for the reply message.- Returns:
this Builder
instance.- Throws:
java.lang.NullPointerException
- ifmc
isnull
.java.lang.IllegalArgumentException
- ifmc
is not a reply for this request.java.lang.IllegalStateException
- ifmessageKey(EMessageKey)
was not successfully called prior to setting the reply callback.- See Also:
messageKey(EMessageKey)
,replyCallback(ReplyCallback)
-
replyCallback
public ERequestFeed.Builder replyCallback(ReplyCallback cb)
Sets reply callback for all message classes. This will override any previous calls toreplyCallback(Class, ReplyCallback)
will be overwritten by this method. Therefore this method should be called prior to setting specific reply message class callbacks.If
cb
is notnull
, replies will be passed tocb
rather thanERequestor.reply(int, EReplyMessage, ERequestFeed.ERequest)
. Acb
results in replies posted to theERequestor.reply(int, EReplyMessage, ERequestFeed)
.If the goal is to set a callback for a specific reply message class, then use
replyCallback(Class, ReplyCallback)
.The following example shows how to set a generic reply callback lambda expression:
replyCallback(this::orderReply)
- Parameters:
cb
- callback for the reply message.- Returns:
this Builder
instance.- Throws:
java.lang.IllegalStateException
- ifmessageKey(EMessageKey)
was not successfully called prior to setting the reply callback.- See Also:
replyCallback(Class, ReplyCallback)
-
-