public interface NotificationManager
Interface for the notification delivery system.
Responsible for processing received topic/notification updates, subscribing for optional topic updates and unsubscribing from them.
AbstractNotificationListener
,
NotificationTopicListListener
,
NotificationListenerInfo
Modifier and Type | Method and Description |
---|---|
void |
addMandatoryTopicsListener(NotificationListener listener)
Deprecated.
|
void |
addNotificationListener(NotificationListener listener)
Add listener to receive all notifications (both for mandatory and
optional topics).
|
void |
addNotificationListener(String topicId,
NotificationListener listener)
Add listener to receive notifications relating to the specified topic.
|
void |
addTopicListListener(NotificationTopicListListener listener)
Add listener for topics' list updates.
|
List<org.kaaproject.kaa.common.endpoint.gen.Topic> |
getTopics()
Retrieve a list of available topics.
|
void |
removeMandatoryTopicsListener(NotificationListener listener)
Deprecated.
|
void |
removeNotificationListener(NotificationListener listener)
Remove listener receiving all notifications (both for mandatory and
optional topics).
|
void |
removeNotificationListener(String topicId,
NotificationListener listener)
Remove listener receiving notifications for the specified topic.
|
void |
removeTopicListListener(NotificationTopicListListener listener)
Remove listener of topics' list updates.
|
void |
subscribeToTopic(String topicId,
boolean forceSync)
Subscribe to notifications relating to the specified optional topic.
|
void |
subscribeToTopics(List<String> topicIds,
boolean forceSync)
Subscribe to notifications relating to the specified list of
optional topics.
|
void |
sync()
Accept optional subscription changes.
|
void |
unsubscribeFromTopic(String topicId,
boolean forceSync)
Unsubscribe from notifications relating to the specified optional topic.
|
void |
unsubscribeFromTopics(List<String> topicIds,
boolean forceSync)
Unsubscribe from notifications relating to the specified list of
optional topics.
|
void |
updateTopicSubscriptions(Map<String,List<NotificationListenerInfo>> subscribers)
Deprecated.
|
@Deprecated void addMandatoryTopicsListener(NotificationListener listener)
Add listener for all mandatory topics' updates.
Use addNotificationListener(NotificationListener)
instead.
If specific listener is needed for some mandatory topic, use
addNotificationListener(String, NotificationListener)
.
listener
- the listener to receive notification.AbstractNotificationListener
@Deprecated void removeMandatoryTopicsListener(NotificationListener listener)
Remove listener for mandatory topics' updates.
Use removeNotificationListener(NotificationListener)
instead.
listener
- the listener which is no longer needs updates.AbstractNotificationListener
,
removeNotificationListener(NotificationListener)
void addTopicListListener(NotificationTopicListListener listener)
Add listener for topics' list updates.
listener
- the listener to receive updates.NotificationTopicListListener
void removeTopicListListener(NotificationTopicListListener listener)
Remove listener of topics' list updates.
listener
- listener the listener which is no longer needs updates.NotificationTopicListListener
@Deprecated void updateTopicSubscriptions(Map<String,List<NotificationListenerInfo>> subscribers) throws UnavailableTopicException
Update (subscribe/unsubscribe) info about topic's subscriptions.
Basic usage is to subscribe for optional topic updates and unsubscribe from them. More than one listener may be used for the same topic.
Also it may be used to add/remove specific listener(s) for some mandatory topic.
// Assume, BasicNotification is a notification class auto-generated according to predefined Avro schema
public class UserNotificationListener extends AbstractNotificationListener<BasicNotification> {
public UserNotificationListener() {}
protected Class<BasicNotification> getNotificationClass() {
return BasicNotification.class;
}
public void onNotification(String topicId, BasicNotification notification) {
System.out.println("Got notification: " + notification.toString());
}
}
// Assume, there are one mandatory topic with id "mand_id" and
// one optional with id "vol_id".
Map<String, List<NotificationListenerInfo>> subscriptions = new HashMap<>();
// Add specific listener for "mand_id" topic
UserNotificationListener mandatoryListener = new UserNotificationListener();
subscriptions.put("mand_id", Arrays.asList(
new NotificationListenerInfo(mandatoryListener, NotificationListenerInfo.Action.ADD)));
// Subscribe for optional topic updates
UserNotificationListener optionalListener = new UserNotificationListener();
subscriptions.put("vol_id", Arrays.asList(
new NotificationListenerInfo(optionalListener, NotificationListenerInfo.Action.ADD)));
kaaClient.getNotificationManager().updateTopicSubscriptions(subscriptions);
subscribers
- collections of pairs topic id/subscriber info.UnavailableTopicException
- Throw if unknown topic id is provided.subscribeToTopic(String, boolean)
,
subscribeToTopics(List, boolean)
,
addNotificationListener(NotificationListener)
,
addNotificationListener(String, NotificationListener)
List<org.kaaproject.kaa.common.endpoint.gen.Topic> getTopics()
Retrieve a list of available topics.
void addNotificationListener(NotificationListener listener)
Add listener to receive all notifications (both for mandatory and optional topics).
listener
- Listener to receive notificationsAbstractNotificationListener
void addNotificationListener(String topicId, NotificationListener listener) throws UnavailableTopicException
Add listener to receive notifications relating to the specified topic.
Listener(s) for optional topics may be added/removed irrespective to whether subscription was already or not.
topicId
- Id of topic (both mandatory and optional).listener
- Listener to receive notifications.UnavailableTopicException
- Throw if unknown topic id is provided.AbstractNotificationListener
void removeNotificationListener(NotificationListener listener)
Remove listener receiving all notifications (both for mandatory and optional topics).
listener
- Listener to receive notificationsAbstractNotificationListener
void removeNotificationListener(String topicId, NotificationListener listener) throws UnavailableTopicException
Remove listener receiving notifications for the specified topic.
Listener(s) for optional topics may be added/removed irrespective to whether subscription was already or not.
topicId
- Id of topic (both mandatory and optional).listener
- Listener to receive notifications.UnavailableTopicException
- Throw if unknown topic id is provided.AbstractNotificationListener
void subscribeToTopic(String topicId, boolean forceSync) throws UnavailableTopicException
Subscribe to notifications relating to the specified optional topic.
topicId
- Id of a optional topic.forceSync
- Define whether current subscription update should be
accepted immediately (see sync()
).UnavailableTopicException
- Throw if unknown topic id is provided or
topic isn't optional.sync()
void subscribeToTopics(List<String> topicIds, boolean forceSync) throws UnavailableTopicException
Subscribe to notifications relating to the specified list of optional topics.
topicIds
- List of optional topic id.forceSync
- Define whether current subscription update should be
accepted immediately (see sync()
).UnavailableTopicException
- Throw if unknown topic id is provided or
topic isn't optional.sync()
void unsubscribeFromTopic(String topicId, boolean forceSync) throws UnavailableTopicException
Unsubscribe from notifications relating to the specified optional topic.
All previously added listeners will be removed automatically.
topicId
- Id of a optional topic.forceSync
- Define whether current subscription update should be
accepted immediately (see sync()
).UnavailableTopicException
- Throw if unknown topic id is provided or
topic isn't optional.sync()
void unsubscribeFromTopics(List<String> topicIds, boolean forceSync) throws UnavailableTopicException
Unsubscribe from notifications relating to the specified list of optional topics.
All previously added listeners will be removed automatically.
topicIds
- List of optional topic id.forceSync
- Define whether current subscription update should be
accepted immediately (see sync()
).UnavailableTopicException
- Throw if unknown topic id is provided or
topic isn't optional.sync()
void sync()
Accept optional subscription changes.
Should be used after all subscribeToTopic(String, boolean)
,
subscribeToTopics(List, boolean)
, unsubscribeFromTopic(String, boolean)
,
unsubscribeFromTopics(List, boolean)
calls with parameter
forceSync
set to false
.
Use it as a convenient way to make different consequent changes in the optional subscription:
NotificationManager notificationManager = kaaClient.getNotificationManager();
// Make subscription changes
notificationManager.subscribeOnTopics(Arrays.asList(
"optional_topic1", "optional_topic2", "optional_topic3"), false);
notificationManager.unsubscribeFromTopic("optional_topic4", false);
// Add listeners for optional topics here
// Commit changes
notificationManager.sync();
Copyright © 2015. All rights reserved.