public interface TopicControl extends Feature
1) Adding and removing topics.
2) Missing topic notifications — listening for requests to subscribe to
topics that do not exist thus allowing dynamic topic creation on demand.
3) Topic event listeners — listening for topic events, such as the number of
subscribers to a topic changing from zero to greater than zero or from
greater than zero to zero.
The Diffusion server stores data in topics. Each topic is bound to a topic
path in the topic tree, and may have a current value. Sessions can subscribe
to topics. Updates to topic values are broadcast to subscribing sessions.
There are several types of topic. The topic type
determines
the type of the data values a topic publishes to subscribers.
The simplest way to create a topic is to call
addTopic(String, TopicType)
, supplying a topic type. For example, to
create a JSON
topic bound to the topic path
foo
:
CompletableFuture<AddTopicResult%gt; result = topicControl.addTopic("foo", TopicType.JSON);
Success or failure is reported asynchronously through the CompletableFuture result.
The nature of a topic depends primarily on its topic type, but can be
customized using topic properties. Some types of topic cannot be created
without supplying mandatory topic properties. Topic properties can be
supplied in a topic specification
using
addTopic(String, TopicSpecification, AddCallback)
. Topic
specifications can be created using newSpecification(TopicType)
and
further customized with builder methods. For example, to create a
JSON
topic bound to the topic path foo
with
the VALIDATE_VALUES
property set
to true
:
CompletableFuture<AddTopicResult> result = topicControl.addTopic( "foo", topicControl.newSpecification(TopicType.JSON) .withProperty(TopicSpecification.VALIDATE_VALUES, "true"));
See TopicSpecification
for details of the available topic properties
and their effects on the different types of topic.
Topic creation is idempotent. If addTopic(path, specification)
is called and there is already a topic bound
to path
with a topic specification equal to specification
,
the call will complete normally with an TopicControl.AddTopicResult.EXISTS
result.
However, if there is a topic bound to path
with a different topic
specification, the call will complete exceptionally with an
TopicControl.ExistingTopicException
.
Topics can be removed using removeTopics(TopicSelector)
. Only those
selected topics that the caller has MODIFY_TOPIC
permission to will be removed, any others will remain.
Topics can also be automatically removed according to a removal criteria
specified using the REMOVAL
topic
property.
A topic can be bound to any path in the topic tree namespace. The only restriction is that two topics can not have the same path.
In the following example a topic can be created with the path A/B/foo
even though there are no topics with path A
or A/B
:
topicControl.addTopic("A/B/foo", TopicType.JSON);
Topics bound to the paths A
or A/B
can be created later.
Topics can be removed without affecting the topics subordinate to them in the
topic tree using remove(java.lang.String, com.pushtechnology.diffusion.client.features.control.topics.TopicControl.RemovalCallback)
providing a path topic selector. By using
the //
topic selector qualifier it is possible to remove a topic and
all of its descendant topics, that is to remove whole topic tree branches.
To add or remove a topic, a session needs MODIFY_TOPIC
permission for the topic path. When removing topics with a
topic selector that matches more than one topic, only topics with paths for
which the session has MODIFY_TOPIC
permission will be removed.
To register a
missing topic handler
the session needs
REGISTER_HANDLER
permission.
This feature may be obtained from a session
as follows:
TopicControl topicControl = session.feature(TopicControl.class);
Modifier and Type | Interface and Description |
---|---|
static interface |
TopicControl.AddCallback
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static interface |
TopicControl.AddContextCallback<C>
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static class |
TopicControl.AddTopicException
Exception thrown to report a failure to add a topic.
|
static class |
TopicControl.AddTopicResult
Used to report the result of adding a topic.
|
static class |
TopicControl.ExistingTopicException
Exception thrown to report a topic could not be added because an existing
topic with a different specification is bound to the topic path.
|
static class |
TopicControl.IncompatibleExistingTopicException
Exception thrown to report that a topic exists at the same path that is
managed by a component that has exclusive control over the topic.
|
static class |
TopicControl.IncompatibleTopicException
Exception thrown to report a topic could not be added because there is an
existing topic that is incompatible with the request.
|
static class |
TopicControl.InvalidTopicPathException
Exception thrown to report a topic could not be added because the topic
path supplied is invalid.
|
static class |
TopicControl.InvalidTopicSpecificationException
Exception thrown to report a topic could not be added because the
specification is invalid.
|
static interface |
TopicControl.MissingTopicHandler
Deprecated.
since 6.7
Use |
static interface |
TopicControl.MissingTopicNotification
Notification that a session has made a subscription request using a
selector that does not match any topics.
|
static interface |
TopicControl.MissingTopicNotificationStream
Stream called when a session subscribes using a topic selector that
matches no topics.
|
static interface |
TopicControl.RemovalCallback
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static interface |
TopicControl.RemovalContextCallback<C>
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
static class |
TopicControl.TopicLicenseLimitException
Exception thrown to report a topic could not be added because a licence
limit has been exceeded.
|
static interface |
TopicControl.TopicRemovalResult
Reports the number of topics removed by a call to
removeTopics(com.pushtechnology.diffusion.client.topics.TopicSelector) . |
Modifier and Type | Method and Description |
---|---|
void |
addMissingTopicHandler(String topicPath,
TopicControl.MissingTopicHandler handler)
Deprecated.
since 6.7
Prefer the CompletableFuture-based alternative
|
CompletableFuture<Registration> |
addMissingTopicHandler(String topicPath,
TopicControl.MissingTopicNotificationStream handler)
Register a
TopicControl.MissingTopicNotificationStream to handle requests for
a branch of the topic tree. |
CompletableFuture<TopicControl.AddTopicResult> |
addTopic(String topicPath,
TopicSpecification specification)
Request creation of a topic.
|
<C> void |
addTopic(String topicPath,
TopicSpecification specification,
C context,
TopicControl.AddContextCallback<C> callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
void |
addTopic(String topicPath,
TopicSpecification specification,
TopicControl.AddCallback callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
CompletableFuture<TopicControl.AddTopicResult> |
addTopic(String topicPath,
TopicType topicType)
Request creation of a topic.
|
TopicSpecification |
newSpecification(TopicType topicType)
Deprecated.
since 6.7
Use
|
<C> void |
remove(String topicSelector,
C context,
TopicControl.RemovalContextCallback<C> callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
void |
remove(String topicSelector,
TopicControl.RemovalCallback callback)
Deprecated.
since 6.7
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead. |
CompletableFuture<TopicControl.TopicRemovalResult> |
removeTopics(String topicSelector)
Send a request to remove one or more topics.
|
CompletableFuture<TopicControl.TopicRemovalResult> |
removeTopics(TopicSelector topicSelector)
Send a request to remove one or more topics.
|
getSession
@Deprecated TopicSpecification newSpecification(TopicType topicType)
Use
Diffusion.newTopicSpecification
which can be imported with a
static import, instead.
TopicSpecification
for a given topic type.topicType
- the topic typewithProperty
or
withProperties
methods of the provided specification.CompletableFuture<TopicControl.AddTopicResult> addTopic(String topicPath, TopicType topicType)
This is a convenience method that is equivalent to:
topicControl.addTopic( topicPath, topicControl.newSpecification(topicType));
topicPath
- the topic path to which the topic will be boundtopicType
- the type of topic to be created
If the task completes successfully, the CompletableFuture result
will be indicate whether a new topic was created, or whether a
topic with an identical topic specification is already bound to
at topicPath
.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
TopicControl.ExistingTopicException
– a topic is bound to
topicPath
with a different topic specification;
TopicControl.IncompatibleExistingTopicException
– an
incompatible topic already exists at topicPath
;
TopicControl.InvalidTopicPathException
– topicPath
is not a valid topic path;
TopicControl.InvalidTopicSpecificationException
– the
specification is invalid, possibly because mandatory properties
not supplied;
TopicControl.TopicLicenseLimitException
– the topic could
not be added as it would breach a licensing limit;
ClusterRoutingException
– if the operation failed
due to a transient cluster error;
TopicControl.AddTopicException
– the topic could not be
created for some reason other than those specified above;
PermissionsException
– the calling session
does not have MODIFY_TOPIC
permission for
topicPath
;
SessionClosedException
– the session is closed.
CompletableFuture<TopicControl.AddTopicResult> addTopic(String topicPath, TopicSpecification specification)
topicPath
- the topic path to which the topic will be boundspecification
- defines the topic to be created. A specification can
be created using newSpecification(TopicType)
.
If the task completes successfully, the CompletableFuture result
will be indicate whether a new topic was created, or whether a
topic with an identical topic specification is already bound to
at topicPath
.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
TopicControl.ExistingTopicException
– a topic is bound to
topicPath
with a different topic specification;
TopicControl.IncompatibleExistingTopicException
– an
incompatible topic already exists at topicPath
;
TopicControl.InvalidTopicPathException
– topicPath
is not a valid topic path;
TopicControl.InvalidTopicSpecificationException
– the
specification is invalid;
TopicControl.TopicLicenseLimitException
– the topic could
not be added as it would breach a licensing limit;
ClusterRoutingException
– if the operation failed
due to a transient cluster error;
TopicControl.AddTopicException
– the topic could not be
created for some reason other than those specified above;
PermissionsException
– the calling session
does not have MODIFY_TOPIC
permission for
topicPath
;
SessionClosedException
– the session is closed.
@Deprecated <C> void addTopic(String topicPath, TopicSpecification specification, C context, TopicControl.AddContextCallback<C> callback)
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
addTopic(String, TopicSpecification, AddCallback)
that allows a user defined context to be provided.C
- the context object typetopicPath
- the topic path to which the topic will be boundspecification
- defines the topic to be created. A specification can
be created using newSpecification(TopicType)
.context
- an object passed to the callback with the reply to allow
requests and replies to be correlated. The caller may use any
convenient object reference, including null
callback
- called with the result@Deprecated void addTopic(String topicPath, TopicSpecification specification, TopicControl.AddCallback callback)
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
topicPath
- the topic path to which the topic will be boundspecification
- defines the topic to be created. A specification can
be created using newSpecification(TopicType)
.callback
- called with the resultCompletableFuture<TopicControl.TopicRemovalResult> removeTopics(TopicSelector topicSelector)
All topics that match the provided topicSelector
that the caller
has permission to remove will be removed.
The selector's descendant pattern qualifier
(a
trailing /
or //
), can be used to remove descendant
topics. If a single /
qualifier is specified, all descendants of
the matched topic paths will be removed. If //
is specified, the
matched paths and all descendants of the matched paths (complete
branches) will be removed.
topicSelector
- specifies the topics to remove
If the task completes successfully, the CompletableFuture result
will bear a TopicControl.TopicRemovalResult
. This provides the number
of topics removed by calling
TopicControl.TopicRemovalResult.getRemovedCount()
.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
SessionClosedException
– the session is closed.
CompletableFuture<TopicControl.TopicRemovalResult> removeTopics(String topicSelector) throws IllegalArgumentException
This is equivalent to calling removeTopics(TopicSelector)
with a
selector parsed using TopicSelectors.parse(String)
.
topicSelector
- a topic selector expression
specifying the topics to remove.
If the task completes successfully, the CompletableFuture result
will bear a TopicControl.TopicRemovalResult
. This provides the number
of topics removed by calling
TopicControl.TopicRemovalResult.getRemovedCount()
.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
SessionClosedException
– the session is closed.
IllegalArgumentException
- if topicSelector
is an invalid
topic selector expression@Deprecated void remove(String topicSelector, TopicControl.RemovalCallback callback) throws IllegalArgumentException
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
All topics that match the provided topicSelector
that the caller
has permission to remove will be removed.
The selector's descendant pattern qualifier
(a
trailing /
or //
), can be used to remove descendant
topics. If a single /
qualifier is specified, all descendants of
the matched topic paths will be removed. If //
is specified, the
matched paths and all descendants of the matched paths (complete
branches) will be removed.
topicSelector
- a topic selector expression
specifying the topics to removecallback
- called to notify request completedIllegalArgumentException
- if topicSelector
is an invalid
topic selector expression@Deprecated <C> void remove(String topicSelector, C context, TopicControl.RemovalContextCallback<C> callback) throws IllegalArgumentException
Methods that use callbacks are deprecated and will be removed in a future release. Use CompletableFuture variant instead.
remove(String, RemovalCallback)
that allows a user
defined context to be provided.C
- the context object typetopicSelector
- a topic selector expression
specifying the topics to removecontext
- an object passed to the callback with the reply to allow
requests and replies to be correlated. The caller may use any
convenient object reference, including null
callback
- called to notify request completedIllegalArgumentException
- if topicSelector
is an invalid
topic selector expressionCompletableFuture<Registration> addMissingTopicHandler(String topicPath, TopicControl.MissingTopicNotificationStream handler)
TopicControl.MissingTopicNotificationStream
to handle requests for
a branch of the topic tree.
The provided handler is called when a session subscribes using a topic selector that matches no existing topics. This allows a control client session to be notified when another session requests a topic that does not exist.
A session can register multiple handlers, but may only register a single
handler for a given topic path. If there is already a handler registered
for the topic path the operation will fail with a
HandlerConflictException
. A handler will only be called for topic
selectors with a path prefix
that
starts with or is equal to topicPath
. If the path prefix matches
multiple handlers, the one registered for the most specific (longest)
topic path will be called.
Prefer this method to the callback-based alternative
addMissingTopicHandler(String, MissingTopicHandler)
since it
provides better error reporting.
topicPath
- identifies a branch of the topic treehandler
- the handler to use for notifying topics at or below the
topicPath
(unless there is a handler registered for a more
specific topic path)
If registration was successful, the CompletableFuture will
complete successfully with a Registration
which can be
used to unregister the handler.
Otherwise, the CompletableFuture will complete exceptionally with
a CompletionException
. Common reasons for failure, listed
by the exception reported as the
cause
, include:
HandlerConflictException
– if the session has
already registered a missing topic handler for topicPath
;
PermissionsException
– if the session does
not have REGISTER_HANDLER
permission;
SessionClosedException
– if the session is
closed.
@Deprecated void addMissingTopicHandler(String topicPath, TopicControl.MissingTopicHandler handler)
Prefer the CompletableFuture-based alternative
addMissingTopicHandler(String, MissingTopicNotificationStream)
since it provides better error reporting.
TopicControl.MissingTopicHandler
to handle requests for a branch of
the topic tree.
The provided handler is called when a session subscribes using a topic selector that matches no existing topics.
A session can register multiple handlers, but may only register a single
handler for a given topic path. See
onActive
.
A handler will only be called for topic selectors with a
path prefix
that starts with or is
equal to topicPath
. If the path prefix matches multiple handlers,
the one registered for the most specific (longest) topic path will be
called.
topicPath
- identifies a branch of the topic treehandler
- the handler to use for notifying topics at or below the
topicPath
(unless there is a handler registered for a more
specific topic path)Copyright © 2024 DiffusionData Ltd. All Rights Reserved.