ProxyInvoker class final

The runtime engine behind one proxy: it runs each call of a proxied member through the advice that matches that member.

Generated proxy classes contain no advice logic. Each member forwards to invoke (or invokeAsync for members returning a Future, invokeFutureOr for FutureOr ones) with its index in signatures, its arguments and a closure that calls the real member. The invoker works out, once per member, which advisors match, runs them in order, and also handles self-calls, AopContext.currentProxy() and the @DeclareParents delegates. It also stores the proxy's advisors, so Advised methods forward to it. Only generated code uses it.

// The shape of a generated wrapper proxy.
class CalculatorProxy implements Calculator, Advised {
  CalculatorProxy(this._target, this._invoker);

  final SimpleCalculator _target;
  final ProxyInvoker _invoker;

  @override
  Object get aopTarget => _target;

  @override
  List<PointcutAdvisor> get aopAdvisors => _invoker.advisors;

  @override
  int add(int a, int b) => _invoker.invoke(this, _target, 0, [a, b],
      (args) => _target.add(args[0]! as int, args[1]! as int))! as int;

  @override
  Future<int> slowAdd(int a, int b) => _invoker.invokeAsync<int>(
      this, _target, 1, [a, b],
      (args) => _target.slowAdd(args[0]! as int, args[1]! as int));
}

Spring (Java):

// The runtime equivalent is JdkDynamicAopProxy.invoke(), which builds
// a ReflectiveMethodInvocation over the advisor chain:
List<Object> chain = advised
    .getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
new ReflectiveMethodInvocation(proxy, target, method, args,
    targetClass, chain).proceed();

Constructors

ProxyInvoker(List<MethodSignature> signatures, List<PointcutAdvisor> advisors, String beanName, {List<String> beanAliases = const [], List<Introduction> introductions = const []})
An invoker running advisors (outermost first) on the members signatures of the bean named beanName; beanAliases (aliases and qualifier values) also count for bean(...) pointcuts.

Properties

advisors → List<PointcutAdvisor>
The advisors of the proxy, outermost first. It is a read-only view that follows addAdvisor and removeAdvisor.
latefinal
beanAliases → List<String>
The aliases and qualifier values of the proxied bean, which bean(...) pointcuts also match.
final
beanName → String
The name of the proxied bean, which bean(...) pointcuts match.
final
hashCode → int
The hash code for this object.
no setterinherited
introducedTypes → List<String>
The names of the introductions interfaces, which this(...) pointcuts match.
latefinal
introductions → List<Introduction>
The @DeclareParents interfaces of the proxy; generated code refers to each by its index.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
signatures → List<MethodSignature>
The proxied members; generated code refers to each by its index.
final

Methods

addAdvice(MethodInterceptor advice) → void
Appends advice as the innermost advice of every member.
addAdvisor(PointcutAdvisor advisor) → void
Appends advisor as the innermost one; the next calls use it.
chainFor(int index) → List<MethodInterceptor>
The interceptors for member index, outermost first, computed on the first call and cached until the advisors change.
introduction(int index) → Object
The object implementing introduction index for this proxy, created on first use and reused afterwards.
invoke(Object proxy, Object target, int index, List<Object?> arguments, Object? call(List<Object?> arguments)) → Object?
Calls the synchronous member index through its advice and returns the result.
invokeAsync<T>(Object proxy, Object target, int index, List<Object?> arguments, Future<T> call(List<Object?> arguments)) → Future<T>
Calls member index, which returns Future<T>, through its advice.
invokeFutureOr<T>(Object proxy, Object target, int index, List<Object?> arguments, FutureOr<T> call(List<Object?> arguments)) → FutureOr<T>
Calls member index, which returns FutureOr<T>, through its advice.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAdvice(MethodInterceptor advice) → bool
Removes the first advisor whose advice is advice (the same object); returns false when there is none.
removeAdvisor(PointcutAdvisor advisor) → bool
Removes advisor; returns false when it was not there.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

notAdvised(Object proxy) → Never
Throws the AopConfigException for a call of an Advised method on a generated subclass proxy that no advice matched when the bean was created, so it has no invoker and no advisors to change.
notIntroduced(Object proxy, String interfaceName) → Never
Throws the AopConfigException for a call of a member of the introduced interface interfaceName on a generated subclass proxy without an invoker: the aspect declaring the introduction is not registered (a condition or profile left it out).