Class AbstractBabelProtocolHolder

java.lang.Object
pt.unl.fct.di.novasys.babel2.core.AbstractBabelProtocolHolder
All Implemented Interfaces:
BabelProtocolHolder
Direct Known Subclasses:
DedicatedExecutorProtocolHolder, NettyExecutorProtocolHolder, SharedExecutorProtocolHolder

public abstract class AbstractBabelProtocolHolder extends Object implements BabelProtocolHolder
Abstract base implementation of BabelProtocolHolder providing handler discovery via reflection, dynamic lambda generation, and dispatch routines.
  • Field Details

    • protocol

      protected final BabelProtocol protocol
      The managed protocol instance.
  • Constructor Details

    • AbstractBabelProtocolHolder

      protected AbstractBabelProtocolHolder(BabelProtocol protocol, Set<ProtocolExtension<? extends BabelProtocol>> extensions)
      Constructs a holder for protocol, wiring up all handlers discovered via reflection and the provided extensions.

      This constructor is called exclusively by the Babel runtime during initialisation and should not be invoked directly.

      Parameters:
      protocol - the protocol instance to manage
      extensions - pre-built extension instances applicable to protocol
  • 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 using LambdaMetafactory.

      This method is exposed so that ProtocolExtension implementations can create strongly-typed handlers for annotated protocol methods discovered during initialisation.

      Specified by:
      createHandler in interface BabelProtocolHolder
      Type Parameters:
      T - the functional interface type to produce
      Parameters:
      method - the protocol method to wrap
      lookup - a MethodHandles.Lookup scoped to the protocol's class
      protocolClass - the protocol's concrete class
      handlerInterface - the target functional interface class
      handlerMethodName - the single abstract method name of the functional interface
      erasedParamType - the erased parameter types expected by the functional interface
      actualParamType - 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

      protected void invokeHandler(ProtocolEvent event)
      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

      protected void invokeHandler(MessageInEvent event)
      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

      protected void invokeHandler(MessageOutSuccessEvent event)
      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

      protected void invokeHandler(MessageOutFailedEvent event)
      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

      public Set<Class<? extends ProtocolEvent>> interestedEvents()
      Description copied from interface: BabelProtocolHolder
      Returns the set of ProtocolEvent classes that this protocol has registered interest in.
      Specified by:
      interestedEvents in interface BabelProtocolHolder
      Returns:
      set of handled event classes
    • interestedInMessages

      public Set<Class<? extends BabelMessage>> interestedInMessages()
      Description copied from interface: BabelProtocolHolder
      Returns the set of BabelMessage classes that this protocol is interested in receiving.
      Specified by:
      interestedInMessages in interface BabelProtocolHolder
      Returns:
      set of handled inbound message classes
    • interestedOutSuccessMessages

      public Set<Class<? extends BabelMessage>> interestedOutSuccessMessages()
      Description copied from interface: BabelProtocolHolder
      Returns the set of BabelMessage classes for which this protocol handles successful delivery.
      Specified by:
      interestedOutSuccessMessages in interface BabelProtocolHolder
      Returns:
      set of message classes with outbound success handlers
    • interestedOutFailedMessages

      public Set<Class<? extends BabelMessage>> interestedOutFailedMessages()
      Description copied from interface: BabelProtocolHolder
      Returns the set of BabelMessage classes for which this protocol handles delivery failure.
      Specified by:
      interestedOutFailedMessages in interface BabelProtocolHolder
      Returns:
      set of message classes with outbound failure handlers
    • eventHandlers

      public Map<Class<? extends ProtocolEvent>, EventHandler<? extends ProtocolEvent>> eventHandlers()
      Description copied from interface: BabelProtocolHolder
      Returns the mapping of handled ProtocolEvent classes to their compiled event handlers.
      Specified by:
      eventHandlers in interface BabelProtocolHolder
      Returns:
      map of event types to handlers
    • holdsProtocol

      public boolean holdsProtocol(Class<? extends BabelProtocol> protocolClass)
      Description copied from interface: BabelProtocolHolder
      Returns whether this holder manages a protocol that is an instance of or assignable to the given protocol class.
      Specified by:
      holdsProtocol in interface BabelProtocolHolder
      Parameters:
      protocolClass - the protocol class to check
      Returns:
      true if this holder manages a matching protocol, false otherwise
    • getInnerProtocol

      public BabelProtocol getInnerProtocol()
      Description copied from interface: BabelProtocolHolder
      Returns the underlying protocol instance managed by this holder.
      Specified by:
      getInnerProtocol in interface BabelProtocolHolder
      Returns:
      the managed BabelProtocol