public final class ESubscribeFeed extends ENotifyFeed implements IESubscribeFeed
ESubscribeFeed
is the application entry point for
receiving notification messages
.
Follow these steps to use this feed:
Step 1: Implement the ESubscriber
interface.
Step 2:
Use ESubscribeFeed.Builder
to create a subscribe feed
for a given ESubscriber
instance and
type+topic message key
. The condition is
optional and defaults to null
. If provided, then only
notification messages satisfying the condition are forwarded
to the subscriber.
Use ESubscribeFeed.Builder.statusCallback(FeedStatusCallback)
and
ESubscribeFeed.Builder.notifyCallback(NotifyCallback)
to set Java
lambda expressions used in place of ESubscriber
interface methods.
Step 3: Subscribe
to the
open feed.
Step 4: Wait for an
up
feed status
.
This callback will occur before any notification messages are
delivered. If the feed state is down
,
then no notifications will be delivered until the feed state
comes back up.
Step 5: Once the feed state is up, wait for
notification messages
to arrive.
Step 6: When the subscriber is shutting down,
retract
the subscription and
close
the feed.
ESubscribeFeed
import net.sf.eBus.client.EFeed.FeedScope;
import net.sf.eBus.client.EFeedState;
import net.sf.eBus.client.ESubscribeFeed;
import net.sf.eBus.client.ESubscriber;
import net.sf.eBus.messages.EMessageKey;
import net.sf.eBus.messages.ENotificationMessage;
Step 1: Implement the ESubscriber interface.
public class CatalogSubscriber implements ESubscriber
{
// Subscribe to this notification message class/subject key and feed scope.
private final EMessageKey mKey;
private final FeedScope mScope;
// Store the feed here so it can be used to unsubscribe.
private ESubscribeFeed mFeed;
public CatalogSubscriber(final String subject, final FeedScope scope) {
mKey = new EMessageKey(CatalogUpdate.class, subject);
mScope = scope;
mFeed = null;
}
@Override public void startup() {
try {
Step 2: Open the ESubscribe feed.
// This subscriber has no associated ECondition and uses ESubscriber interface method overrides.
mFeed = (ESubscribeFeed.builder()).target(this)
.messageKey(mKey)
.scope(mScope)
.build();
Step 3: Subscribe to the feed.
mFeed.subscribe();
} catch(IllegalArgumentException argex) {
// Feed open failed. Place recovery code here.
}
}
Step 4: Wait for EFeedState.UP feed status.
@Override public void feedStatus(final EFeedState feedState, final IESubscribeFeed feed) {
// What is the feed state?
if (feedState == EFeedState.DOWN) {
// Down. There are no publishers. Expect no notifications until a
// publisher is found. Put error recovery code here.
} else {
// Up. There is at least one publisher. Expect to receive notifications.
}
}
Step 5: Wait for notifications to arrive.
@Override public void notify(final ENotificationMessage msg, final IESubscribeFeed feed) {
// Notification handling code here.
}
@Override public void shutdown() {
Step 6: When subscriber is shutting down, retract subscription feed.
// mFeed.unsubscribe() is not necessary since close() will unsubscribe.
if (mFeed != null) {
mFeed.close();
mFeed = null;
}
}
}
ESubscriber
,
EPublisher
,
EPublishFeed
Modifier and Type | Class and Description |
---|---|
protected static class |
net.sf.eBus.client.ESingleFeed.FeedType
Enumerates the supported feed types.
|
static class |
ESubscribeFeed.Builder
ESubscribeFeed.Builder is now the preferred
mechanism for creating a ESubscribeFeed instance. |
EFeed.AbstractClientTask, EFeed.FeedScope, EFeed.NotifyTask, EFeed.StatusTask<T extends IEFeed>
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FEED_STATUS_METHOD
ESubscriber.feedStatus(EFeedState, IESubscribeFeed)
method name. |
protected int |
mActivationCount
Tracks the number of contra-feeds matched to this feed.
|
protected net.sf.eBus.client.ESingleFeed.FeedType |
mFeedType
Specifies whether this is a publish, subscribe, request,
or reply feed.
|
protected net.sf.eBus.client.ESubject |
mSubject
The feed interfaces with this eBus subject.
|
FEED_IS_INACTIVE, FEED_NOT_ADVERTISED, mEClient, mFeedId, mFeedState, mInPlace, mIsActive, mScope, NO_CONDITION, NOTIFY_METHOD, NULL_CLIENT
Modifier and Type | Method and Description |
---|---|
int |
activationCount()
Returns the feed activation count.
|
static ESubscribeFeed.Builder |
builder()
Returns a new
ESubscribeFeed builder instance. |
protected void |
inactivate()
If the advertisement is in place, then retracts it.
|
EMessageKey |
key()
Returns the feed message key.
|
java.lang.String |
messageSubject()
Returns the feed
message key subect . |
void |
subscribe()
Activates this notification subscription.
|
java.lang.String |
toString()
Returns a containing the feed message key and data member
values.
|
void |
unsubscribe()
De-activates this subscriber feed.
|
protected static void |
validateOpenParams(ESubscriber client,
EMessageKey key,
EFeed.FeedScope scope)
Verifies that given parameters are not set to
null
and that key references a notification message and
that the message scope and feed scope are in agreement. |
addAllKeys, addKey, addListener, checkScopes, clientId, close, createDispatcher, defaultDispatcher, eClient, equals, feedId, feedState, findKeys, findKeys, findKeys, hashCode, inPlace, isActive, isFeedUp, isOverridden, loadKeys, location, register, register, register, removeListener, scope, setExhaust, shutdown, shutdown, shutdownAll, startup, startup, startupAll, storeKeys, storeKeys, storeKeys, subclassDistance
public static final java.lang.String FEED_STATUS_METHOD
ESubscriber.feedStatus(EFeedState, IESubscribeFeed)
method name.protected final net.sf.eBus.client.ESingleFeed.FeedType mFeedType
protected final net.sf.eBus.client.ESubject mSubject
feed type
.protected int mActivationCount
protected void inactivate()
inactivate
in class EFeed
public void subscribe()
feed stateupdate callback method
.
Nothing is done if already subscribed.
subscribe
in interface IESubscribeFeed
java.lang.IllegalStateException
- if this feed is closed or if the client did not override
ESubscriber
methods nor put the required callbacks
in place.unsubscribe()
,
EFeed.close()
public void unsubscribe()
Note that the client may still receive notification messages which were posted concurrently as this unsubscribe.
unsubscribe
in interface IESubscribeFeed
subscribe()
,
EFeed.close()
public static ESubscribeFeed.Builder builder()
ESubscribeFeed
builder instance.
This instance should be used to build a single
notification subscribe feed instance and not used to
create multiple such feeds.protected static void validateOpenParams(ESubscriber client, EMessageKey key, EFeed.FeedScope scope)
null
and that key
references a notification message and
that the message scope and feed scope are in agreement.
This method is called for effect only.client
- subscriber client.key
- notification message code.scope
- feed scope.public java.lang.String toString()
public final EMessageKey key()
EPublishFeed
, then a
notification
message key is returned.public final java.lang.String messageSubject()
message key subect
.public final int activationCount()
Copyright © 2001 - 2024. Charles W. Rapp. All rights reserved.