Class SignedMessageExtension
java.lang.Object
pt.unl.fct.di.novasys.babel2.core.signed.SignedMessageExtension
- All Implemented Interfaces:
ProtocolExtension<SignedMessageBabelProtocol>, EventHandler<ProtocolEvent>
public class SignedMessageExtension
extends Object
implements ProtocolExtension<SignedMessageBabelProtocol>
Protocol extension that enables reflective dispatching of signed messages to handler methods
annotated with
UponSignedMessageIn, UponSignedMessageOutSuccess, and
UponSignedMessageOutFailed.-
Field Summary
Fields inherited from interface EventHandler
HANDLER_METHOD_NAME -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a signed message extension for the specified 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.static Class<?> getFirstTypeArgument(Method method, int parameterIndex) Extracts the first generic type argument of the parameter at the specified index.voidhandleEvent(ProtocolEvent event) Dispatches aProtocolEventthat was previously claimed by this extension (because its type is listed inProtocolExtension.eventsClass()).voidregister(Method method, MethodHandles.Lookup lookup, SignedMessageBabelProtocol 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
-
SignedMessageExtension
Constructs a signed message extension for the specified protocol.- Parameters:
protocol- the protocol instance to be augmented
-
-
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<SignedMessageBabelProtocol>- Returns:
- a list of annotation classes; may be empty if the extension does not use method annotations
-
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<SignedMessageBabelProtocol>- Returns:
- a list of event classes; may be empty
-
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<SignedMessageBabelProtocol>- Parameters:
event- the event to handle; its runtime type is guaranteed to be one of the types returned byProtocolExtension.eventsClass()
-
register
public void register(Method method, MethodHandles.Lookup lookup, SignedMessageBabelProtocol 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<SignedMessageBabelProtocol>- 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.
-
getFirstTypeArgument
Extracts the first generic type argument of the parameter at the specified index.- Parameters:
method- the method to inspectparameterIndex- the index of the parameter- Returns:
- the resolved
Classof the type argument - Throws:
IllegalArgumentException- if the parameter has no resolvable type argument
-