Interface ProtocolExtension<T extends BabelProtocol>
- Type Parameters:
T- the protocol type this extension targets
- All Superinterfaces:
EventHandler<ProtocolEvent>
- All Known Implementing Classes:
BroadcastConsumerExtension, BroadcastProviderExtension, MembershipConsumerExtension, MembershipProviderExtension, ResolverProviderExtension, SignedMessageExtension
A pluggable cross-cutting extension that augments a
BabelProtocol
with
additional event handling capabilities.
Extensions allow the Babel runtime to wire up higher-level abstractions
(e.g., broadcast, membership) on top of raw ProtocolEvents without
requiring protocol implementations to extend a concrete base class. Each
extension declares:
- which method-level
Annotations it recognises viaannotationClass(), so thatSharedExecutorProtocolHoldercan invokeregister(Method, MethodHandles.Lookup, T, BabelProtocolHolder, Annotation)during initialisation; - which
ProtocolEventtypes it wants to intercept viaeventsClass(), so that the holder routes those events throughhandleEvent(ProtocolEvent)instead of the protocol's own handler map.
Concrete implementations are paired with a ProtocolExtensionFactory
and registered on the BabelBootstrap before building the runtime.
- See Also:
-
Field Summary
Fields inherited from interface EventHandler
HANDLER_METHOD_NAME -
Method Summary
Modifier and TypeMethodDescriptiondefault Set<Class<? extends Annotation>> Returns the set of method-level annotation types that this extension processes.default Set<Class<? extends ProtocolEvent>> Returns the set ofProtocolEventtypes that this extension handles.default voidhandleEvent(ProtocolEvent event) Dispatches aProtocolEventthat was previously claimed by this extension (because its type is listed ineventsClass()).default voidregister(Method method, MethodHandles.Lookup lookup, T protocol, BabelProtocolHolder holder, Annotation annotation) Called bySharedExecutorProtocolHolderduring initialisation for each method on the protocol that carries one of the annotations returned byannotationClass().
-
Method Details
-
register
default void register(Method method, MethodHandles.Lookup lookup, T protocol, BabelProtocolHolder holder, Annotation annotation) Called bySharedExecutorProtocolHolderduring initialisation for each method on the protocol that carries one of the annotations returned byannotationClass(). Implementations should build and store a handler for that method.- 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
Dispatches aProtocolEventthat was previously claimed by this extension (because its type is listed ineventsClass()).- Specified by:
handleEventin interfaceEventHandler<T extends BabelProtocol>- Parameters:
event- the event to handle; its runtime type is guaranteed to be one of the types returned byeventsClass()
-
annotationClass
Returns the set of method-level annotation types that this extension processes. The framework scans protocol methods for these annotations during initialisation and callsregister(Method, MethodHandles.Lookup, T, BabelProtocolHolder, Annotation)for each match.- Returns:
- a list of annotation classes; may be empty if the extension does not use method annotations
-
eventsClass
Returns the set ofProtocolEventtypes that this extension handles. Events of these types are routed tohandleEvent(ProtocolEvent)instead of the protocol's own@UponBabelEvent-annotated handlers.- Returns:
- a list of event classes; may be empty
-