public class HedwigSubscriber extends Object implements Subscriber
Modifier and Type | Field and Description |
---|---|
protected ClientConfiguration |
cfg |
protected HChannelManager |
channelManager |
Constructor and Description |
---|
HedwigSubscriber(HedwigClientImpl client) |
Modifier and Type | Method and Description |
---|---|
void |
addSubscriptionListener(SubscriptionListener listener)
Register a subscription listener which get notified about subscription
event indicating a state of a subscription that subscribed disable
resubscribe logic.
|
void |
asyncCloseSubscription(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
Callback<Void> callback,
Object context)
Closes all of the client side cached data for this subscription without
actually sending an unsubscribe request to the server.
|
void |
asyncSubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscribeRequest.CreateOrAttach mode,
Callback<Void> callback,
Object context)
Subscribe to the given topic asynchronously for the inputted subscriberId
disregarding if the topic has been created yet or not.
|
void |
asyncSubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscriptionOptions options,
Callback<Void> callback,
Object context)
Subscribe to the given topic asynchronously for the inputted subscriberId.
|
protected void |
asyncSubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscriptionOptions options,
Callback<Void> callback,
Object context,
boolean isHub) |
void |
asyncUnsubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
Callback<Void> callback,
Object context)
Unsubscribe from a topic asynchronously that the subscriberId user has
previously subscribed to.
|
protected void |
asyncUnsubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
Callback<Void> callback,
Object context,
boolean isHub) |
void |
closeSubscription(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId)
Closes all of the client side cached data for this subscription without
actually sending an unsubscribe request to the server.
|
void |
consume(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.MessageSeqId messageSeqId)
Manually send a consume message to the server for the given inputs.
|
List<com.google.protobuf.ByteString> |
getSubscriptionList(com.google.protobuf.ByteString subscriberId)
Fills the input List with the subscriptions this subscriberId client is
subscribed to.
|
boolean |
hasSubscription(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId)
Checks if the subscriberId client is currently subscribed to the given
topic.
|
void |
removeSubscriptionListener(SubscriptionListener listener)
Unregister a subscription listener.
|
void |
startDelivery(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
MessageHandler messageHandler)
Begin delivery of messages from the server to us for this topic and
subscriberId.
|
void |
startDeliveryWithFilter(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
MessageHandler messageHandler,
org.apache.hedwig.filter.ClientMessageFilter messageFilter)
Begin delivery of messages from the server to us for this topic and
subscriberId.
|
void |
stopDelivery(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId)
Stop delivery of messages for this topic and subscriberId.
|
void |
subscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscribeRequest.CreateOrAttach mode)
Subscribe to the given topic for the inputted subscriberId.
|
void |
subscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscriptionOptions options)
Subscribe to the given topic for the inputted subscriberId.
|
protected void |
subscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
PubSubProtocol.SubscriptionOptions options,
boolean isHub) |
void |
unsubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId)
Unsubscribe from a topic that the subscriberId user has previously
subscribed to.
|
protected void |
unsubscribe(com.google.protobuf.ByteString topic,
com.google.protobuf.ByteString subscriberId,
boolean isHub) |
protected final ClientConfiguration cfg
protected final HChannelManager channelManager
public HedwigSubscriber(HedwigClientImpl client)
public void addSubscriptionListener(SubscriptionListener listener)
Subscriber
addSubscriptionListener
in interface Subscriber
listener
- Subscription Listenerpublic void removeSubscriptionListener(SubscriptionListener listener)
Subscriber
removeSubscriptionListener
in interface Subscriber
listener
- Subscription Listenerpublic void subscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscribeRequest.CreateOrAttach mode) throws PubSubException.CouldNotConnectException, PubSubException.ClientAlreadySubscribedException, PubSubException.ServiceDownException, InvalidSubscriberIdException
Subscriber
subscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribermode
- Whether to prohibit, tolerate, or require an existing
subscription.PubSubException.CouldNotConnectException
- If we are not able to connect to the server hostPubSubException.ClientAlreadySubscribedException
- If client is already subscribed to the topicPubSubException.ServiceDownException
- If unable to subscribe to topicInvalidSubscriberIdException
- If the subscriberId is not valid. We may want to set aside
certain formats of subscriberId's for different purposes.
e.g. local vs. hub subscriberpublic void subscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscriptionOptions options) throws PubSubException.CouldNotConnectException, PubSubException.ClientAlreadySubscribedException, PubSubException.ServiceDownException, InvalidSubscriberIdException
Subscriber
subscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscriberoptions
- Options to pass to the subscription. See
asyncSubscribe
for details on how to set options.PubSubException.CouldNotConnectException
- If we are not able to connect to the server hostPubSubException.ClientAlreadySubscribedException
- If client is already subscribed to the topicPubSubException.ServiceDownException
- If unable to subscribe to topicInvalidSubscriberIdException
- If the subscriberId is not valid. We may want to set aside
certain formats of subscriberId's for different purposes.
e.g. local vs. hub subscriberprotected void subscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscriptionOptions options, boolean isHub) throws PubSubException.CouldNotConnectException, PubSubException.ClientAlreadySubscribedException, PubSubException.ServiceDownException, InvalidSubscriberIdException
public void asyncSubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscribeRequest.CreateOrAttach mode, Callback<Void> callback, Object context)
Subscriber
asyncSubscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribermode
- Whether to prohibit, tolerate, or require an existing
subscription.callback
- Callback to invoke when the subscribe request to the server
has actually gone through. This will have to deal with error
conditions on the async subscribe request.context
- Calling context that the Callback needs since this is done
asynchronously.public void asyncSubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscriptionOptions options, Callback<Void> callback, Object context)
Subscriber
Subscribe to the given topic asynchronously for the inputted subscriberId.
SubscriptionOptions contains parameters for how the hub should make the subscription. The options includes createorattach mode, message bound and message filter.
The createorattach mode defines whether the subscription should create a new subscription, or just attach to a preexisting subscription. If it tries to create the subscription, and the subscription already exists, then an error will occur.
The message bound defines the maximum number of undelivered messages which will be stored for the subscription. This can be used to ensure that unused subscriptions do not grow in an unbounded fashion. By default, the message bound is infinite, i.e. all undelivered messages will be stored for the subscription. Note that if one subscription on a topic has a infinite message bound, the message bound for all other subscriptions on that topic will effectively be infinite as the messages have to be stored for the first subscription in any case.
The message filter defines a ServerMessageFilter
run in hub server to filter messages delivered to the subscription. The server message
filter should be placed in the classpath of hub server before using it.
// create a new subscription with a message bound of 5
SubscriptionOptions options = SubscriptionOptions.newBuilder()
.setCreateOrAttach(CreateOrAttach.CREATE).setMessageBound(5).build();
client.getSubscriber().asyncSubscribe(ByteString.copyFromUtf8("myTopic"),
ByteString.copyFromUtf8("mySubscription"),
options,
myCallback,
myContext);
asyncSubscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscriberoptions
- Options to pass to the subscription.callback
- Callback to invoke when the subscribe request to the server
has actually gone through. This will have to deal with error
conditions on the async subscribe request.context
- Calling context that the Callback needs since this is done
asynchronously.protected void asyncSubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.SubscriptionOptions options, Callback<Void> callback, Object context, boolean isHub)
public void unsubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId) throws PubSubException.CouldNotConnectException, PubSubException.ClientNotSubscribedException, PubSubException.ServiceDownException, InvalidSubscriberIdException
Subscriber
unsubscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscriberPubSubException.CouldNotConnectException
- If we are not able to connect to the server hostPubSubException.ClientNotSubscribedException
- If the client is not currently subscribed to the topicPubSubException.ServiceDownException
- If the server was down and unable to complete the requestInvalidSubscriberIdException
- If the subscriberId is not valid. We may want to set aside
certain formats of subscriberId's for different purposes.
e.g. local vs. hub subscriberprotected void unsubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, boolean isHub) throws PubSubException.CouldNotConnectException, PubSubException.ClientNotSubscribedException, PubSubException.ServiceDownException, InvalidSubscriberIdException
public void asyncUnsubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, Callback<Void> callback, Object context)
Subscriber
asyncUnsubscribe
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribercallback
- Callback to invoke when the unsubscribe request to the server
has actually gone through. This will have to deal with error
conditions on the async unsubscribe request.context
- Calling context that the Callback needs since this is done
asynchronously.protected void asyncUnsubscribe(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, Callback<Void> callback, Object context, boolean isHub)
public void consume(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, PubSubProtocol.MessageSeqId messageSeqId) throws PubSubException.ClientNotSubscribedException
Subscriber
consume
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribermessageSeqId
- Message Sequence ID for the latest message that the client app
has successfully consumed. All messages up to that point will
also be considered as consumed.PubSubException.ClientNotSubscribedException
- If the client is not currently subscribed to the topic based
on the client's local state.public boolean hasSubscription(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId) throws PubSubException.CouldNotConnectException, PubSubException.ServiceDownException
Subscriber
hasSubscription
in interface Subscriber
topic
- Topic name of the subscription.subscriberId
- ID of the subscriberPubSubException.CouldNotConnectException
- If we are not able to connect to the server hostPubSubException.ServiceDownException
- If there is an error checking the server if the client has a
subscriptionpublic List<com.google.protobuf.ByteString> getSubscriptionList(com.google.protobuf.ByteString subscriberId) throws PubSubException.CouldNotConnectException, PubSubException.ServiceDownException
Subscriber
getSubscriptionList
in interface Subscriber
subscriberId
- ID of the subscriberPubSubException.CouldNotConnectException
- If we are not able to connect to the server hostPubSubException.ServiceDownException
- If there is an error retrieving the list of topicspublic void startDelivery(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, MessageHandler messageHandler) throws PubSubException.ClientNotSubscribedException, AlreadyStartDeliveryException
Subscriber
startDelivery
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribermessageHandler
- Message Handler that will consume the subscribed messagesPubSubException.ClientNotSubscribedException
- If the client is not currently subscribed to the topicAlreadyStartDeliveryException
- If someone started delivery a message handler before stopping existed one.public void startDeliveryWithFilter(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, MessageHandler messageHandler, org.apache.hedwig.filter.ClientMessageFilter messageFilter) throws PubSubException.ClientNotSubscribedException, AlreadyStartDeliveryException
Subscriber
messageFilter
could be delivered to
messageHandler
.startDeliveryWithFilter
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribermessageHandler
- Message Handler that will consume the subscribed messagesPubSubException.ClientNotSubscribedException
- If the client is not currently subscribed to the topicAlreadyStartDeliveryException
- If someone started delivery a message handler before stopping existed one.public void stopDelivery(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId) throws PubSubException.ClientNotSubscribedException
Subscriber
stopDelivery
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscriberPubSubException.ClientNotSubscribedException
- If the client is not currently subscribed to the topicpublic void closeSubscription(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId) throws PubSubException.ServiceDownException
Subscriber
closeSubscription
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscriberPubSubException.ServiceDownException
- If the subscribe channel was not able to be closed
successfullypublic void asyncCloseSubscription(com.google.protobuf.ByteString topic, com.google.protobuf.ByteString subscriberId, Callback<Void> callback, Object context)
Subscriber
asyncCloseSubscription
in interface Subscriber
topic
- Topic name of the subscriptionsubscriberId
- ID of the subscribercallback
- Callback to invoke when the subscribe channel has been closed.context
- Calling context that the Callback needs since this is done
asynchronously.Copyright © 2015 The Apache Software Foundation. All rights reserved.