public class DefaultNotificationManager extends Object implements NotificationManager, NotificationProcessor
NotificationManager implementation.| Constructor and Description |
|---|
DefaultNotificationManager(KaaClientState state,
NotificationTransport transport) |
| 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 |
notificationReceived(List<org.kaaproject.kaa.common.endpoint.gen.Notification> notifications)
Called when new notifications arrived.
|
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 |
topicsListUpdated(List<org.kaaproject.kaa.common.endpoint.gen.Topic> list)
Called on topics' list update.
|
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.
|
public DefaultNotificationManager(KaaClientState state, NotificationTransport transport)
public void addNotificationListener(NotificationListener listener)
NotificationManagerAdd listener to receive all notifications (both for mandatory and optional topics).
addNotificationListener in interface NotificationManagerlistener - Listener to receive notificationsAbstractNotificationListenerpublic void removeNotificationListener(NotificationListener listener)
NotificationManagerRemove listener receiving all notifications (both for mandatory and optional topics).
removeNotificationListener in interface NotificationManagerlistener - Listener to receive notificationsAbstractNotificationListener@Deprecated public void updateTopicSubscriptions(Map<String,List<NotificationListenerInfo>> subscribers) throws UnavailableTopicException
NotificationManagerUpdate (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);
updateTopicSubscriptions in interface NotificationManagersubscribers - collections of pairs topic id/subscriber info.UnavailableTopicException - Throw if unknown topic id is provided.NotificationManager.subscribeToTopic(String, boolean),
NotificationManager.subscribeToTopics(List, boolean),
NotificationManager.addNotificationListener(NotificationListener),
NotificationManager.addNotificationListener(String, NotificationListener)@Deprecated public void addMandatoryTopicsListener(NotificationListener listener)
NotificationManagerAdd listener for all mandatory topics' updates.
Use NotificationManager.addNotificationListener(NotificationListener) instead.
If specific listener is needed for some mandatory topic, use
NotificationManager.addNotificationListener(String, NotificationListener).
addMandatoryTopicsListener in interface NotificationManagerlistener - the listener to receive notification.AbstractNotificationListener@Deprecated public void removeMandatoryTopicsListener(NotificationListener listener)
NotificationManagerRemove listener for mandatory topics' updates.
Use NotificationManager.removeNotificationListener(NotificationListener) instead.
removeMandatoryTopicsListener in interface NotificationManagerlistener - the listener which is no longer needs updates.AbstractNotificationListener,
NotificationManager.removeNotificationListener(NotificationListener)public void addTopicListListener(NotificationTopicListListener listener)
NotificationManagerAdd listener for topics' list updates.
addTopicListListener in interface NotificationManagerlistener - the listener to receive updates.NotificationTopicListListenerpublic void removeTopicListListener(NotificationTopicListListener listener)
NotificationManagerRemove listener of topics' list updates.
removeTopicListListener in interface NotificationManagerlistener - listener the listener which is no longer needs updates.NotificationTopicListListenerpublic List<org.kaaproject.kaa.common.endpoint.gen.Topic> getTopics()
NotificationManagerRetrieve a list of available topics.
getTopics in interface NotificationManagerpublic void subscribeToTopic(String topicId, boolean forceSync) throws UnavailableTopicException
NotificationManagerSubscribe to notifications relating to the specified optional topic.
subscribeToTopic in interface NotificationManagertopicId - Id of a optional topic.forceSync - Define whether current subscription update should be
accepted immediately (see NotificationManager.sync()).UnavailableTopicException - Throw if unknown topic id is provided or
topic isn't optional.NotificationManager.sync()public void subscribeToTopics(List<String> topicIds, boolean forceSync) throws UnavailableTopicException
NotificationManagerSubscribe to notifications relating to the specified list of optional topics.
subscribeToTopics in interface NotificationManagertopicIds - List of optional topic id.forceSync - Define whether current subscription update should be
accepted immediately (see NotificationManager.sync()).UnavailableTopicException - Throw if unknown topic id is provided or
topic isn't optional.NotificationManager.sync()public void unsubscribeFromTopic(String topicId, boolean forceSync) throws UnavailableTopicException
NotificationManagerUnsubscribe from notifications relating to the specified optional topic.
All previously added listeners will be removed automatically.
unsubscribeFromTopic in interface NotificationManagertopicId - Id of a optional topic.forceSync - Define whether current subscription update should be
accepted immediately (see NotificationManager.sync()).UnavailableTopicException - Throw if unknown topic id is provided or
topic isn't optional.NotificationManager.sync()public void unsubscribeFromTopics(List<String> topicIds, boolean forceSync) throws UnavailableTopicException
NotificationManagerUnsubscribe from notifications relating to the specified list of optional topics.
All previously added listeners will be removed automatically.
unsubscribeFromTopics in interface NotificationManagertopicIds - List of optional topic id.forceSync - Define whether current subscription update should be
accepted immediately (see NotificationManager.sync()).UnavailableTopicException - Throw if unknown topic id is provided or
topic isn't optional.NotificationManager.sync()public void addNotificationListener(String topicId, NotificationListener listener) throws UnavailableTopicException
NotificationManagerAdd 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.
addNotificationListener in interface NotificationManagertopicId - Id of topic (both mandatory and optional).listener - Listener to receive notifications.UnavailableTopicException - Throw if unknown topic id is provided.AbstractNotificationListenerpublic void removeNotificationListener(String topicId, NotificationListener listener) throws UnavailableTopicException
NotificationManagerRemove listener receiving notifications for the specified topic.
Listener(s) for optional topics may be added/removed irrespective to whether subscription was already or not.
removeNotificationListener in interface NotificationManagertopicId - Id of topic (both mandatory and optional).listener - Listener to receive notifications.UnavailableTopicException - Throw if unknown topic id is provided.AbstractNotificationListenerpublic void sync()
NotificationManagerAccept optional subscription changes.
Should be used after all NotificationManager.subscribeToTopic(String, boolean),
NotificationManager.subscribeToTopics(List, boolean), NotificationManager.unsubscribeFromTopic(String, boolean),
NotificationManager.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();
sync in interface NotificationManagerpublic void topicsListUpdated(List<org.kaaproject.kaa.common.endpoint.gen.Topic> list)
NotificationProcessortopicsListUpdated in interface NotificationProcessorlist - the new topics' list.Topicpublic void notificationReceived(List<org.kaaproject.kaa.common.endpoint.gen.Notification> notifications) throws IOException
NotificationProcessornotificationReceived in interface NotificationProcessornotifications - the list of new notifications.IOExceptionNotificationCopyright © 2014. All rights reserved.