T - The event (base) type. If all events are of the same type then that type should be used; otherwise a common
base type for all applicable events should be used, such as Object or IDLEntity.public interface AcsEventSubscriber<T>
Subscriber lifecycle:
disconnect() when done using the subscriber,
even if startReceivingEvents() was never called.
addSubscription(Callback) and addGenericSubscription(GenericCallback). removeSubscription(Class)
and removeGenericSubscription().
TODO: Verify that these can be called both before and after startReceivingEvents. startReceivingEvents() to actually subscribe.
suspend() and resume() to temporarily suspend and later resume
the subscription. Depending on the underlying framework, suspending will typically
cause events to be queued somewhere.
disconnect() to destroy all resources. The subscriber cannot be used afterwards.
getLifecycleState().
Discussion:
startReceivingEvents(),
whereas they are released only in the single method disconnect().
However, the underlying state machine knows two 'connect' and two 'disconnect' transitions
and artificially maps them to the asymmetric API.
If we want to make the API symmetric, we could break up 'disconnect' into 'stopReceivingEvents'
and 'destroy'.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
AcsEventSubscriber.Callback<U>
User callback for received events.
|
static interface |
AcsEventSubscriber.GenericCallback
Generic event callback, for use with
addGenericSubscription(GenericCallback). |
| Modifier and Type | Method and Description |
|---|---|
void |
addGenericSubscription(AcsEventSubscriber.GenericCallback receiver)
Adds a generic handler for all types of events.
|
<U extends T> |
addSubscription(AcsEventSubscriber.Callback<U> receiver)
Adds a handler that will receive events of a specific type.
|
void |
disconnect()
Disconnects this subscriber from the Notification Channel, and releases all
the resources associated with it.
|
java.lang.String |
getLifecycleState()
Returns the lifecycle state as obtained from an internal state machine.
|
boolean |
isSuspended()
Returns
true if this subscriber has been suspended. |
void |
removeGenericSubscription()
Removes the generic event handler, so that it will no longer receive events.
|
<U extends T> |
removeSubscription(java.lang.Class<U> structClass)
Removes the subscription for a specified event type or for all events types, so that the handler previously
registered for that event type will no longer receive events.
|
void |
resume()
Used to reenable the Subscriber after a call to the
suspend() method. |
void |
startReceivingEvents()
This method must be called to actually start receiving events.
|
void |
suspend()
Used to temporarily halt receiving events of all types.
|
<U extends T> void addSubscription(AcsEventSubscriber.Callback<U> receiver) throws AcsJEventSubscriptionEx
AcsEventSubscriber.Callback.getEventType()
on the receiver parameter.
Note that the same event type can only be subscribed to with one handler, which means that another handler added for the same type will replace the previous handler.
The event type must be that of actual events, not of base classes.
For example, the AcsEventSubscriber could be parameterized with base type IDLEntity
and we could then add two subscriptions for events defined as IDL structs,
say AntennaStatus and TemperatureData.
If you want to subscribe to events without knowing their exact type,
use addGenericSubscription(GenericCallback) instead.
receiver - The callback to use when receiving events for the specified type.AcsJEventSubscriptionEx - If there is a problem and the receiver cannot be added<U extends T> void removeSubscription(java.lang.Class<U> structClass) throws AcsJEventSubscriptionEx
structClass - the event type to be unsubscribed. If null, then all subscriptions but the generic
subscription are removed.AcsJEventSubscriptionEx - if the specified event type has not been previously subscribed or if the removal fails with a
technical problem.void addGenericSubscription(AcsEventSubscriber.GenericCallback receiver) throws AcsJEventSubscriptionEx
addSubscription(Callback),
each with a Callback object that matches exactly the subscribed event type.
It is possible to add a generic handler in addition to event type-specific handlers (where the latter will get precedence). Adding another generic handler will replace the previous generic handler.
receiver - The callback to use when receiving eventsAcsJEventSubscriptionEx - If there is a problem and the generic receiver cannot
be addedvoid removeGenericSubscription()
throws AcsJEventSubscriptionEx
SubscriptionNotFoundException - If a generic receiver has not been previously subscribedAcsJEventSubscriptionEx - If there is any problem while unsubscribing the generic receiverjava.lang.String getLifecycleState()
This state can be used only for debug output. The state names may change over time and should not be used to control execution.
void startReceivingEvents()
throws AcsJIllegalStateEventEx,
AcsJCouldntPerformActionEx
No further invocations should be attempted on this method after one
has been already successful. Otherwise, an AcsJIllegalStateEventEx
will be thrown.
If this method is not called, no event will ever be received
AcsJIllegalStateEventEx - If the user calls this method on an object that
is already receiving eventsAcsJCouldntPerformActionEx - If any error happens while trying
to start receiving eventsvoid disconnect()
throws AcsJIllegalStateEventEx,
AcsJCouldntPerformActionEx
Calling this method over a subscriber object that has been already disconnected
will throw an AcsJIllegalStateEventEx.
AcsJIllegalStateEventEx - If this method is called on an AcsEventSubscriber object
that has been already disconnectedAcsJCouldntPerformActionExvoid suspend()
throws AcsJIllegalStateEventEx,
AcsJCouldntPerformActionEx
If the Subscriber has been connected already (method startReceivingEvents(),
then after calling this method, incoming events will be buffered instead of being discarded;
unexpired events will be received later, after a call to resume().
// * This call has no effect if the Subscriber is not connected, or if it is // * connected but already suspended.
AcsJIllegalStateEventEx - if the subscriber is not connected to an NC.AcsJCouldntPerformActionExboolean isSuspended()
true if this subscriber has been suspended.void resume()
throws AcsJIllegalStateEventEx,
AcsJCouldntPerformActionEx
suspend() method. Queued events will be received after
this call, see suspend().
This call has no effect if the Subscriber is not connected, or if it is
connected and already processing events.AcsJIllegalStateEventExAcsJCouldntPerformActionEx