public static interface Topics.TopicStream extends Stream
When using this type of stream it is the responsibility of the
application to interpret delta events and apply them to any locally held
values. For some types the use of a Topics.ValueStream
is much simpler.
A stream implementation can be registered using
addTopicStream
. The
stream will receive events for all topics that matched by the topic
selector with which it is registered.
A stream implementation can also be registered as a fallback stream using
addFallbackTopicStream
. Fallback streams will receive events for all
topics that are not selected by other streams the session has registered
using addStream
or addTopicStream
.
If the stream is removed
,
onClose
will be called.
If the session is closed,
onError
will be called with ErrorReason.SESSION_CLOSED
.
Modifier and Type | Interface and Description |
---|---|
static class |
Topics.TopicStream.Default
Default
Topics.TopicStream implementation. |
Modifier and Type | Method and Description |
---|---|
void |
onSubscription(String topicPath,
TopicDetails details)
Subscription notification.
|
void |
onTopicUpdate(String topicPath,
Content content,
UpdateContext context)
Topic update received.
|
void |
onUnsubscription(String topicPath,
Topics.UnsubscribeReason reason)
Unsubscription notification.
|
void onSubscription(String topicPath, TopicDetails details)
This method is called when a session is subscribed to a topic that matches the stream registration. This method is also called when a stream is added, for all of the session's subscriptions to topics that match the stream registration.
For a given topic, onSubscription
will be the initial
notification, and the first notification following an
unsubscription
notification if the
session re-subscribes to the topic.
This method is also called for fallback streams if the session
removes
the last stream
that selected a subscribed topic. The fallback stream will now
receive updates for the topic, starting with an immediate
notification of the currently cached value (if any).
topicPath
- the topic pathdetails
- the topic details. This provides only
basic
details of the topic.void onUnsubscription(String topicPath, Topics.UnsubscribeReason reason)
This method is called if the session is unsubscribed from a topic that matches the stream registration. The stream will receive no more updates for the topic unless the session re-subscribes to the topic.
This method is also called for fallback streams if the session
adds
the first
stream that selects a subscribed topic. For these notifications,
reason
will be Topics.UnsubscribeReason.STREAM_CHANGE
. The
fallback stream will no longer receive updates for the topic.
topicPath
- the topic pathreason
- the reason for unsubscriptionvoid onTopicUpdate(String topicPath, Content content, UpdateContext context)
This indicates an update to the state of a topic that is subscribed to. Both value and delta updates are notified via this method and the supplied context will indicate which.
If the stream is added with a selector which matches topics to which
the session is already subscribed, and the topic type is
JSON
, BINARY
, or
SINGLE_VALUE
), this will be called
after the subscription notification to provide the current known
value. For other topic types, the current value is not retained by
the client, and the next update received could be a delta. For such
topics it is important to add streams before subscription.
topicPath
- the topic pathcontent
- the topic content. The context can contain more
information about the nature of the contentcontext
- the update context which can indicate whether the
content represents the total state or a change to the stateCopyright © 2016 Push Technology Ltd. All Rights Reserved.