Class BroadcastConsumerExtension
java.lang.Object
pt.unl.fct.di.novasys.babel2.core.broadcast.BroadcastConsumerExtension
- All Implemented Interfaces:
ProtocolExtension<BroadcastConsumerBabelProtocol>, EventHandler<ProtocolEvent>
public class BroadcastConsumerExtension
extends Object
implements ProtocolExtension<BroadcastConsumerBabelProtocol>
ProtocolExtension that wires up broadcast-delivery handling for
BroadcastConsumerBabelProtocol instances.
During initialisation it scans the protocol for methods annotated with
@UponBroadcastDeliver
and builds a typed
BroadcastDeliverHandler for each one. At runtime, incoming
BroadcastDeliverEvent events are dispatched to the matching handler
based on the carried message type.
Register via BroadcastConsumerExtensionFactory on the
BabelBootstrap.
-
Field Summary
Fields inherited from interface EventHandler
HANDLER_METHOD_NAME -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aBroadcastConsumerExtensionfor the given protocol. -
Method Summary
Modifier and TypeMethodDescriptionSet<Class<? extends Annotation>> Returns the set of method-level annotation types that this extension processes.Set<Class<? extends ProtocolEvent>> Returns the set ofProtocolEventtypes that this extension handles.voidhandleEvent(ProtocolEvent event) Dispatches aProtocolEventthat was previously claimed by this extension (because its type is listed inProtocolExtension.eventsClass()).voidregister(Method method, MethodHandles.Lookup lookup, BroadcastConsumerBabelProtocol protocol, BabelProtocolHolder holder, Annotation annotation) Called bySharedExecutorProtocolHolderduring initialisation for each method on the protocol that carries one of the annotations returned byProtocolExtension.annotationClass().
-
Constructor Details
-
BroadcastConsumerExtension
Constructs aBroadcastConsumerExtensionfor the given protocol.- Parameters:
protocol- the consumer protocol this extension will augment; must not benull
-
-
Method Details
-
annotationClass
Description copied from interface:ProtocolExtensionReturns the set of method-level annotation types that this extension processes. The framework scans protocol methods for these annotations during initialisation and callsProtocolExtension.register(Method, MethodHandles.Lookup, T, BabelProtocolHolder, Annotation)for each match.- Specified by:
annotationClassin interfaceProtocolExtension<BroadcastConsumerBabelProtocol>- Returns:
- a list of annotation classes; may be empty if the extension does not use method annotations
-
register
public void register(Method method, MethodHandles.Lookup lookup, BroadcastConsumerBabelProtocol protocol, BabelProtocolHolder holder, Annotation annotation) Description copied from interface:ProtocolExtensionCalled bySharedExecutorProtocolHolderduring initialisation for each method on the protocol that carries one of the annotations returned byProtocolExtension.annotationClass(). Implementations should build and store a handler for that method.- Specified by:
registerin interfaceProtocolExtension<BroadcastConsumerBabelProtocol>- Parameters:
method- the annotated method on the protocol classlookup- aMethodHandles.Lookupscoped to the protocol's class, suitable for creating lambda method handlesprotocol- the concrete protocol instanceholder- theSharedExecutorProtocolHolderwrapping the protocol, which exposesAbstractBabelProtocolHolder.createHandler(Method, MethodHandles.Lookup, Class, Class, String, Class[], Class[])for building typed functional-interface handlersannotation- theAnnotationthat is associated with this method.
-
handleEvent
Description copied from interface:ProtocolExtensionDispatches aProtocolEventthat was previously claimed by this extension (because its type is listed inProtocolExtension.eventsClass()).- Specified by:
handleEventin interfaceEventHandler<ProtocolEvent>- Specified by:
handleEventin interfaceProtocolExtension<BroadcastConsumerBabelProtocol>- Parameters:
event- the event to handle; its runtime type is guaranteed to be one of the types returned byProtocolExtension.eventsClass()
-
eventsClass
Description copied from interface:ProtocolExtensionReturns the set ofProtocolEventtypes that this extension handles. Events of these types are routed toProtocolExtension.handleEvent(ProtocolEvent)instead of the protocol's own@UponBabelEvent-annotated handlers.- Specified by:
eventsClassin interfaceProtocolExtension<BroadcastConsumerBabelProtocol>- Returns:
- a list of event classes; may be empty
-