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)
NotificationManager
Add listener to receive all notifications (both for mandatory and optional topics).
addNotificationListener
in interface NotificationManager
listener
- Listener to receive notificationsAbstractNotificationListener
public void removeNotificationListener(NotificationListener listener)
NotificationManager
Remove listener receiving all notifications (both for mandatory and optional topics).
removeNotificationListener
in interface NotificationManager
listener
- Listener to receive notificationsAbstractNotificationListener
@Deprecated public void updateTopicSubscriptions(Map<String,List<NotificationListenerInfo>> subscribers) throws UnavailableTopicException
NotificationManager
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);
updateTopicSubscriptions
in interface NotificationManager
subscribers
- 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)
NotificationManager
Add 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 NotificationManager
listener
- the listener to receive notification.AbstractNotificationListener
@Deprecated public void removeMandatoryTopicsListener(NotificationListener listener)
NotificationManager
Remove listener for mandatory topics' updates.
Use NotificationManager.removeNotificationListener(NotificationListener)
instead.
removeMandatoryTopicsListener
in interface NotificationManager
listener
- the listener which is no longer needs updates.AbstractNotificationListener
,
NotificationManager.removeNotificationListener(NotificationListener)
public void addTopicListListener(NotificationTopicListListener listener)
NotificationManager
Add listener for topics' list updates.
addTopicListListener
in interface NotificationManager
listener
- the listener to receive updates.NotificationTopicListListener
public void removeTopicListListener(NotificationTopicListListener listener)
NotificationManager
Remove listener of topics' list updates.
removeTopicListListener
in interface NotificationManager
listener
- listener the listener which is no longer needs updates.NotificationTopicListListener
public List<org.kaaproject.kaa.common.endpoint.gen.Topic> getTopics()
NotificationManager
Retrieve a list of available topics.
getTopics
in interface NotificationManager
public void subscribeToTopic(String topicId, boolean forceSync) throws UnavailableTopicException
NotificationManager
Subscribe to notifications relating to the specified optional topic.
subscribeToTopic
in interface NotificationManager
topicId
- 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
NotificationManager
Subscribe to notifications relating to the specified list of optional topics.
subscribeToTopics
in interface NotificationManager
topicIds
- 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
NotificationManager
Unsubscribe from notifications relating to the specified optional topic.
All previously added listeners will be removed automatically.
unsubscribeFromTopic
in interface NotificationManager
topicId
- 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
NotificationManager
Unsubscribe from notifications relating to the specified list of optional topics.
All previously added listeners will be removed automatically.
unsubscribeFromTopics
in interface NotificationManager
topicIds
- 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
NotificationManager
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.
addNotificationListener
in interface NotificationManager
topicId
- Id of topic (both mandatory and optional).listener
- Listener to receive notifications.UnavailableTopicException
- Throw if unknown topic id is provided.AbstractNotificationListener
public void removeNotificationListener(String topicId, NotificationListener listener) throws UnavailableTopicException
NotificationManager
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.
removeNotificationListener
in interface NotificationManager
topicId
- Id of topic (both mandatory and optional).listener
- Listener to receive notifications.UnavailableTopicException
- Throw if unknown topic id is provided.AbstractNotificationListener
public void sync()
NotificationManager
Accept 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 NotificationManager
public void topicsListUpdated(List<org.kaaproject.kaa.common.endpoint.gen.Topic> list)
NotificationProcessor
topicsListUpdated
in interface NotificationProcessor
list
- the new topics' list.Topic
public void notificationReceived(List<org.kaaproject.kaa.common.endpoint.gen.Notification> notifications) throws IOException
NotificationProcessor
notificationReceived
in interface NotificationProcessor
notifications
- the list of new notifications.IOException
Notification
Copyright © 2014. All rights reserved.