Class SubscriptionService
- java.lang.Object
-
- org.forgerock.openig.tools.notifications.ws.SubscriptionService
-
- All Implemented Interfaces:
NotificationService
public class SubscriptionService extends Object implements NotificationService
Web-socket client endpoint that bridges AM notifications protocol to our own API.This class manages subscriptions requests and acknowledgments asynchronously.
This class is web-socket implementation-free (no dependency on any web-socket container specific API or behaviour).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.forgerock.openig.tools.notifications.NotificationService
NotificationService.Registration
-
-
Constructor Summary
Constructors Constructor Description SubscriptionService(TopicManager manager)
SubscriptionService
constructor taking aTopicManager
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Promise<NotificationService.Registration,NeverThrowsException>
addConnectionEventListener(Consumer<ConnectionEvent> listener)
Registers asynchronously a listener that will be notified on connection/disconnection events.Promise<Void,NeverThrowsException>
close()
Close theSubscriptionService
and unsubscribe from all topics.void
onClose()
Means of notifying theSubscriptionService
that a notification provider has closed.void
onMessage(JsonValue message)
Means of supplying theSubscriptionService
with subscription and notification messages.void
onOpen(WebSocketAdapter webSocket)
Means of notifying theSubscriptionService
that a notification provider available.Promise<Subscription,SubscriptionException>
subscribe(String topicName, NotificationListener listener)
Subscribes (asynchronously) to a given topic, providing a listener that will be invoked at notification reception time.
-
-
-
Constructor Detail
-
SubscriptionService
public SubscriptionService(TopicManager manager)
SubscriptionService
constructor taking aTopicManager
.- Parameters:
manager
-TopicManager
to handle topic subscription
-
-
Method Detail
-
onOpen
public void onOpen(WebSocketAdapter webSocket)
Means of notifying theSubscriptionService
that a notification provider available.- Parameters:
webSocket
- the WebSocket to use to handle notification registration
-
onClose
public void onClose()
Means of notifying theSubscriptionService
that a notification provider has closed.
-
onMessage
public void onMessage(JsonValue message)
Means of supplying theSubscriptionService
with subscription and notification messages.- Parameters:
message
- the subscription or notification message
-
subscribe
public Promise<Subscription,SubscriptionException> subscribe(String topicName, NotificationListener listener)
Description copied from interface:NotificationService
Subscribes (asynchronously) to a given topic, providing a listener that will be invoked at notification reception time.- Specified by:
subscribe
in interfaceNotificationService
- Parameters:
topicName
- topic name to subscribe tolistener
- notification listener- Returns:
- a promise of a subscription that will be completed after AM sends back the acknowledgement.
-
addConnectionEventListener
public Promise<NotificationService.Registration,NeverThrowsException> addConnectionEventListener(Consumer<ConnectionEvent> listener)
Description copied from interface:NotificationService
Registers asynchronously a listener that will be notified on connection/disconnection events. The returnedPromise
will be completed once theNotificationService
is connected.- Specified by:
addConnectionEventListener
in interfaceNotificationService
- Parameters:
listener
- consumer of connection events- Returns:
- a promise of a registration object that has to be used for un-registration
-
close
public Promise<Void,NeverThrowsException> close()
Close theSubscriptionService
and unsubscribe from all topics.- Returns:
- a
Promise
-
-