The MethodSubscription Class
The MethodSubscription
class extends the MethodInvocation
class. A MethodSubscription
should be constructed in accordance with the MethodDescriptor
of the target method.
Registering a subscription returns a Subscription
object that can be used to cancel the subscription and to examine how the subscription was created
Only methods that return data should be subscribed to. This includes methods of type IMPACT_INFO
and IMPACT_ACTION_INFO
.
Synchronous and Asynchronous Method Subscriptions
You can use either of two constructors to build a MethodSubscription
, depending on whether you are creating a subscription for a synchronous or asynchronous method. The MethodDescriptor
for a method indicates whether the method is synchronous or asynchronous. An asynchronous method is analogous to an event source. Listeners that subscribe to an asynchronous method will receive the method's declared return value each time a particular event occurs.
The MethodSubscription
constructor for synchronous method subscriptions requires an interval parameter. It is used to specify a desired subscription service rate. Subscriptions made of synchronous methods will use this value as a hint to determine how often to deliver data to service a subscription. Most microagents will usually enforce a minimum rate, which will be used if the supplied value is below their minimum.
The MethodSubscription
constructor for asynchronous method subscriptions does not accept an interval parameter. Asynchronous methods deliver data at a rate determined by the microagent, typically, whenever it is available.