Class AbstractBabelProtocolHolder
java.lang.Object
pt.unl.fct.di.novasys.babel2.core.AbstractBabelProtocolHolder
- All Implemented Interfaces:
BabelProtocolHolder
- Direct Known Subclasses:
DedicatedExecutorProtocolHolder, NettyExecutorProtocolHolder, SharedExecutorProtocolHolder
Abstract base implementation of
BabelProtocolHolder providing handler discovery
via reflection, dynamic lambda generation, and dispatch routines.-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractBabelProtocolHolder(BabelProtocol protocol, Set<ProtocolExtension<? extends BabelProtocol>> extensions) Constructs a holder forprotocol, wiring up all handlers discovered via reflection and the provided extensions. -
Method Summary
Modifier and TypeMethodDescription<T> TcreateHandler(Method method, MethodHandles.Lookup lookup, Class<? extends BabelProtocol> protocolClass, Class<T> handlerInterface, String handlerMethodName, Class<?>[] erasedParamType, Class<?>[] actualParamType) Creates a typed functional-interface handler for the given method usingLambdaMetafactory.Map<Class<? extends ProtocolEvent>, EventHandler<? extends ProtocolEvent>> Returns the mapping of handledProtocolEventclasses to their compiled event handlers.Returns the underlying protocol instance managed by this holder.booleanholdsProtocol(Class<? extends BabelProtocol> protocolClass) Returns whether this holder manages a protocol that is an instance of or assignable to the given protocol class.Set<Class<? extends ProtocolEvent>> Returns the set ofProtocolEventclasses that this protocol has registered interest in.Set<Class<? extends BabelMessage>> Returns the set ofBabelMessageclasses that this protocol is interested in receiving.Set<Class<? extends BabelMessage>> Returns the set ofBabelMessageclasses for which this protocol handles delivery failure.Set<Class<? extends BabelMessage>> Returns the set ofBabelMessageclasses for which this protocol handles successful delivery.protected voidinvokeHandler(MessageInEvent event) Invokes the compiled handler for the specified inbound message event.protected voidInvokes the compiled handler for the specified outbound message failure event.protected voidInvokes the compiled handler for the specified outbound message success event.protected voidinvokeHandler(ProtocolEvent event) Invokes the compiled handler for the specified protocol event.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BabelProtocolHolder
deliverEventModifier and TypeMethodDescriptionvoiddeliverEvent(BabelEvent event) Enqueues or delivers an event to the underlying protocol.
-
Field Details
-
protocol
The managed protocol instance.
-
-
Constructor Details
-
AbstractBabelProtocolHolder
protected AbstractBabelProtocolHolder(BabelProtocol protocol, Set<ProtocolExtension<? extends BabelProtocol>> extensions) Constructs a holder forprotocol, wiring up all handlers discovered via reflection and the provided extensions.This constructor is called exclusively by the
Babelruntime during initialisation and should not be invoked directly.- Parameters:
protocol- the protocol instance to manageextensions- pre-built extension instances applicable toprotocol
-
-
Method Details
-
createHandler
public <T> T createHandler(Method method, MethodHandles.Lookup lookup, Class<? extends BabelProtocol> protocolClass, Class<T> handlerInterface, String handlerMethodName, Class<?>[] erasedParamType, Class<?>[] actualParamType) Creates a typed functional-interface handler for the given method usingLambdaMetafactory.This method is exposed so that
ProtocolExtensionimplementations can create strongly-typed handlers for annotated protocol methods discovered during initialisation.- Specified by:
createHandlerin interfaceBabelProtocolHolder- Type Parameters:
T- the functional interface type to produce- Parameters:
method- the protocol method to wraplookup- aMethodHandles.Lookupscoped to the protocol's classprotocolClass- the protocol's concrete classhandlerInterface- the target functional interface classhandlerMethodName- the single abstract method name of the functional interfaceerasedParamType- the erased parameter types expected by the functional interfaceactualParamType- the concrete (specialised) parameter types of the method- Returns:
- a functional-interface instance delegating to
method - Throws:
RuntimeException- if the handler cannot be created
-
invokeHandler
Invokes the compiled handler for the specified protocol event.- Parameters:
event- the protocol event to handle- Throws:
IllegalArgumentException- if no handler is registered for the event's type
-
invokeHandler
Invokes the compiled handler for the specified inbound message event.- Parameters:
event- the inbound message event to handle- Throws:
IllegalArgumentException- if no handler is registered for the message's type
-
invokeHandler
Invokes the compiled handler for the specified outbound message success event.- Parameters:
event- the message delivery success event- Throws:
IllegalArgumentException- if no handler is registered for the message's type
-
invokeHandler
Invokes the compiled handler for the specified outbound message failure event.- Parameters:
event- the message delivery failure event- Throws:
IllegalArgumentException- if no handler is registered for the message's type
-
interestedEvents
Description copied from interface:BabelProtocolHolderReturns the set ofProtocolEventclasses that this protocol has registered interest in.- Specified by:
interestedEventsin interfaceBabelProtocolHolder- Returns:
- set of handled event classes
-
interestedInMessages
Description copied from interface:BabelProtocolHolderReturns the set ofBabelMessageclasses that this protocol is interested in receiving.- Specified by:
interestedInMessagesin interfaceBabelProtocolHolder- Returns:
- set of handled inbound message classes
-
interestedOutSuccessMessages
Description copied from interface:BabelProtocolHolderReturns the set ofBabelMessageclasses for which this protocol handles successful delivery.- Specified by:
interestedOutSuccessMessagesin interfaceBabelProtocolHolder- Returns:
- set of message classes with outbound success handlers
-
interestedOutFailedMessages
Description copied from interface:BabelProtocolHolderReturns the set ofBabelMessageclasses for which this protocol handles delivery failure.- Specified by:
interestedOutFailedMessagesin interfaceBabelProtocolHolder- Returns:
- set of message classes with outbound failure handlers
-
eventHandlers
Description copied from interface:BabelProtocolHolderReturns the mapping of handledProtocolEventclasses to their compiled event handlers.- Specified by:
eventHandlersin interfaceBabelProtocolHolder- Returns:
- map of event types to handlers
-
holdsProtocol
Description copied from interface:BabelProtocolHolderReturns whether this holder manages a protocol that is an instance of or assignable to the given protocol class.- Specified by:
holdsProtocolin interfaceBabelProtocolHolder- Parameters:
protocolClass- the protocol class to check- Returns:
trueif this holder manages a matching protocol,falseotherwise
-
getInnerProtocol
Description copied from interface:BabelProtocolHolderReturns the underlying protocol instance managed by this holder.- Specified by:
getInnerProtocolin interfaceBabelProtocolHolder- Returns:
- the managed
BabelProtocol
-