AbstractMethodDispatcher class abstract

A foundational implementation of MethodInterceptorDispatcher and MethodInterceptor providing a unified interception pipeline for JetLeaf's runtime and AOP subsystems.

The AbstractMethodDispatcher acts as the core interception orchestrator that coordinates method invocations, dynamic dispatching, and chained interceptor execution for runtime-managed objects. It defines the general interception workflow but delegates the actual interceptor configuration to concrete subclasses.

Responsibilities

  1. Delegation: If a custom dispatcher is configured (via getMethodInterceptorDispatcher), it delegates all interception logic to it.
  2. Resolution: If no custom dispatcher exists, it locates the target Method metadata from the reflected target type.
  3. Invocation Management: Wraps the call in a SimpleMethodInvocation and triggers the interceptor chain created by _ChainedMethodInterceptor.
  4. Error Diagnostics: Produces rich diagnostic feedback when the requested method cannot be found, aiding in debugging reflection and metadata issues.

Framework Context

This abstract class is part of JetLeaf’s Aspect-Oriented Programming (AOP) engine. It provides the essential interception entry point for features like:

  • Logging and tracing decorators
  • Security or authorization guards
  • Caching and transactional operations
  • Cross-cutting concerns resolved via proxy mechanisms

Custom Implementation Example

class MyServiceDispatcher extends AbstractMethodDispatcher {
  final List<MethodInterceptor> _interceptors;

  MyServiceDispatcher(this._interceptors);

  @override
  List<MethodInterceptor> getMethodInterceptors() => _interceptors;

  @override
  MethodInterceptorDispatcher? getMethodInterceptorDispatcher() => null;
}

Invocation Flow

sequenceDiagram
  participant Client
  participant Dispatcher as AbstractMethodDispatcher
  participant Interceptor as _ChainedMethodInterceptor
  participant Target as ServiceClass

  Client->>Dispatcher: when(fn, target, methodName)
  Dispatcher->>Interceptor: intercept(invocation)
  Interceptor->>Target: invoke method or chain next interceptor
  Target-->>Dispatcher: result or null
  Dispatcher-->>Client: final result

References

Implemented types

Constructors

AbstractMethodDispatcher()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getMethodInterceptorDispatcher() MethodInterceptorDispatcher?
Retrieves the active MethodInterceptorDispatcher responsible for managing method-level interception logic.
getMethodInterceptors() List<MethodInterceptor>
Retrieves the list of method interceptors to be applied by this dispatcher.
intercept<T>(MethodInvocation<T> invocation) Future<T>
Executes a method invocation through the configured interceptor chain.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<T>(AsyncMethodInvocator<T> function, Object target, String methodName, [ExecutableArgument? arguments, Class? targetClass]) Future<T>
Executes a function with interception support and conditional routing.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited