Package net.sf.eBus.feed.historic
Class EHistoricSubscribeFeed.Builder
- java.lang.Object
-
- net.sf.eBus.feed.historic.EAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>
-
- net.sf.eBus.feed.historic.EHistoricSubscribeFeed.Builder
-
- Enclosing class:
- EHistoricSubscribeFeed
public static final class EHistoricSubscribeFeed.Builder extends EAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>
Builder is used to instantiateEHistoricSubscribeFeedinstances. A builder instance is acquired viaEHistoricSubscribeFeed.builder(EMessageKey, IEHistoricSubscriber)which requires that a non-nullnotification message key and historic subscriber be provided. This message key defines the notification message class and subject subscribed to and retrieved by the historic subscriber. The historic subscriber owns the historic subscribe feed. The historic subscribe feed is an eBus hybrid object and runs in the owner's dispatcher.This builder requires the following properties be defined (beside those properties required by
EAbstractHistoricFeed.Builder):- begin timestamp, location, and clusivity and
- end timestamp, location, and clusivity.
It is recommended that each builder instance be used to create only one historic publish feed.
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.feed.historic.EAbstractHistoricFeed.Builder
mFeedClass, mKey, mName, mOwner, mRequestKey, mScope, mStatusKey, sFeedIndex
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EHistoricSubscribeFeedbuildImpl()Returns new historic subscribe feed instance created from builder settings.EHistoricSubscribeFeed.Buildercondition(ECondition condition)Sets subscription condition to the given value.EHistoricSubscribeFeed.BuilderdoneCallback(HistoricFeedDoneCallback cb)Puts historic subscribe feed completion callback in place.EHistoricSubscribeFeed.Builderfrom(Instant beginTime, EInterval.Clusivity beginClusivity)Sets historic subscription feed to begin in the past.EHistoricSubscribeFeed.BuilderfromNow()Sets historic subscription feed to begin at the current time.protected StringgenerateName()Returns default historic subscribe feed name.EHistoricSubscribeFeed.BuildernotifyCallback(HistoricNotifyCallback cb)Puts the notification message callback in place.protected EHistoricSubscribeFeed.Builderself()Returnsthis Builderself reference.EHistoricSubscribeFeed.BuilderstatusCallback(HistoricFeedStatusCallback cb)Puts historic subscribe feed status callback in place.EHistoricSubscribeFeed.Builderto(Instant endTime, EInterval.Clusivity endClusivity)Sets historic subscription feed to end either in the past or in the future depending on whetherendTimeis in the past or future.EHistoricSubscribeFeed.BuildertoForever()Sets historic live subscription feed to continue until unsubscribed.EHistoricSubscribeFeed.BuildertoNow(EInterval.Clusivity endClusivity)Sets historic subscription feed to end at the current time.protected net.sf.eBus.util.Validatorvalidate(net.sf.eBus.util.Validator problems)Validates historic subscribe feed builder settings.-
Methods inherited from class net.sf.eBus.feed.historic.EAbstractHistoricFeed.Builder
build, name, scope
-
-
-
-
Method Detail
-
self
protected EHistoricSubscribeFeed.Builder self()
Returnsthis Builderself reference.- Specified by:
selfin classEAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>- Returns:
this Builderself reference.
-
validate
protected net.sf.eBus.util.Validator validate(net.sf.eBus.util.Validator problems)
Validates historic subscribe feed builder settings. Returnsproblemsparameter to allow forvalidatemethod chaining.- Overrides:
validatein classEAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>- Parameters:
problems- place validation failures into this list.- Returns:
problemsto allowvalidatemethod chaining.
-
generateName
protected String generateName()
Returns default historic subscribe feed name. Used when feed name is not explicitly set.- Specified by:
generateNamein classEAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>- Returns:
- default historic subscribe feed name.
-
buildImpl
protected EHistoricSubscribeFeed buildImpl()
Returns new historic subscribe feed instance created from builder settings.- Specified by:
buildImplin classEAbstractHistoricFeed.Builder<IEHistoricSubscriber,EHistoricSubscribeFeed,EHistoricSubscribeFeed.Builder>- Returns:
- new historic subscribe feed instance.
-
condition
public EHistoricSubscribeFeed.Builder condition(ECondition condition)
Sets subscription condition to the given value. May benullwhich results in aEFeed.NO_CONDITIONcondition.An example using this method is:
builder.condition(m -> ((CatalogUpdate) m).category == Category.APPLIANCES)- Parameters:
condition- subscription condition.- Returns:
this Builderinstance.
-
doneCallback
public EHistoricSubscribeFeed.Builder doneCallback(@Nullable HistoricFeedDoneCallback cb)
Puts historic subscribe feed completion callback in place. Ifcbis notnull, feed completion will be passed tocbrather thanIEHistoricSubscriber.feedDone(EHistoricSubscribeFeed.HistoricFeedState, EHistoricSubscribeFeed). The reverse is true, ifcbisnull, then updates are posted to theIEHistoricSubscriber.feedDoneoverride.An example using this method is:
doneCallback( (fs, f) → { if (fs == HistoricFeedState.DONE_ERROR) { // Handle historic feed error. } }- Parameters:
cb- historic feed completion callback. May benull.- Returns:
this Builderinstance.
-
statusCallback
public EHistoricSubscribeFeed.Builder statusCallback(@Nullable HistoricFeedStatusCallback cb)
Puts historic subscribe feed status callback in place. Ifcbis notnull, subscribe status updates will be passed tocbrather thanIEHistoricSubscriber.feedStatus(PublishStatusEvent, EHistoricSubscribeFeed). The reverse is true: ifcbisnull, then updates are posted to theIEHistoricSubscriber.feedStatusoverride.An example using this method is:
statusCallback( (pse, f) → { if (pse.feedState == EFeedState.DOWN) { // Clean up in-progress work. }}- Parameters:
cb- historic subscriber status update callback. May benull.- Returns:
this Builderinstance.
-
notifyCallback
public EHistoricSubscribeFeed.Builder notifyCallback(@Nullable HistoricNotifyCallback cb)
Puts the notification message callback in place. Ifcbis notnull, then notification messages will be passed tocbrather thanESubscriber.notify(ENotificationMessage, IESubscribeFeed). Anull cbmeans that notification messages will be passed to theIEHistoricSubscriber.notify(ENotificationMessage, EHistoricSubscribeFeed)override.An example showing how to use this method is:
notifyCallback(this::locationUpdate)- Parameters:
cb- pass notification messages back to target via this callback.- Returns:
this Builderinstance.
-
from
public EHistoricSubscribeFeed.Builder from(Instant beginTime, EInterval.Clusivity beginClusivity)
Sets historic subscription feed to begin in the past.- Parameters:
beginTime- historic feed begin time in the past.beginClusivity- historic feed begin time clusivity.- Returns:
this Builderinstance.- Throws:
NullPointerException- ifbeginTimeorbeginClusivityisnull.IllegalArgumentException- ifbeginTimeis ≥ current time.IllegalStateException- if begin time is already set.
-
fromNow
public EHistoricSubscribeFeed.Builder fromNow()
Sets historic subscription feed to begin at the current time. The begin clusivity is set toEInterval.Clusivity.INCLUSIVE.- Returns:
this Builderinstance.- Throws:
IllegalStateException- if begin time is already set.
-
to
public EHistoricSubscribeFeed.Builder to(Instant endTime, EInterval.Clusivity endClusivity)
Sets historic subscription feed to end either in the past or in the future depending on whetherendTimeis in the past or future. If end time is at the current time, then begin time must be in the past and not at the current time.- Parameters:
endTime- historic feed end time in past or future.endClusivity- historic feed end time clusivity.- Returns:
this Builderinstance.- Throws:
NullPointerException- ifendTimeorendClusivityisnull.IllegalStateException- if end time is already set.
-
toNow
public EHistoricSubscribeFeed.Builder toNow(EInterval.Clusivity endClusivity)
Sets historic subscription feed to end at the current time. This means that historic begin time must be in the past and not set to the current time.- Parameters:
endClusivity- historic subscribe feed ends at or after current time.- Returns:
this Builderinstance.- Throws:
NullPointerException- ifendClusivityisnull.IllegalStateException- if end time is already set.
-
toForever
public EHistoricSubscribeFeed.Builder toForever()
Sets historic live subscription feed to continue until unsubscribed.- Returns:
this Builderinstance.
-
-