Interface InvokerBuilder<T>

Type Parameters:
T - type of outcome of this builder; always represents an Invoker, but does not necessarily have to be an Invoker instance directly

public interface InvokerBuilder<T>
Builder of Invokers. Allows configuring additional behaviors on top of a plain method invocation.

Lookups

For the target bean instance (withInstanceLookup()) and for each target method parameter (withArgumentLookup(int)), it is possible to specify that the corresponding value passed to Invoker.invoke() shall be ignored and a value shall be looked up from the CDI container instead.

For example, assume the following managed bean exists:

 @Dependent
 public class MyService {
     public String hello(String name) {
         return "Hello " + name + "!";
     }
 }
 
A CDI-based framework may want to build an invoker for the hello() method that automatically looks up MyService from the CDI container, instead of having to obtain a contextual reference manually.

Assuming that builder is an InvokerBuilder for MyService.hello(), such invoker can be built:

 builder.withInstanceLookup().build();
 
Later, to invoke the hello() method, a framework could pass null as the instance:
 invoker.invoke(null, new Object[] { "world" })
 
The invoker would look up the instance of the target bean automatically, so the method would be invoked correctly and the return value would be "Hello world!".
Since:
4.1
  • Method Details

    • withInstanceLookup

      InvokerBuilder<T> withInstanceLookup()
      Enables lookup of the target bean instance.
      Returns:
      this builder
    • withArgumentLookup

      InvokerBuilder<T> withArgumentLookup(int position)
      Enables lookup of the argument on given position.
      Parameters:
      position - zero-based position of the target method parameter for which lookup should be enabled
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if position is less than 0 or greater than or equal to the number of parameters declared by the target method
    • build

      T build()
      Returns the built Invoker or some representation of it. Implementations are allowed but not required to reuse already built invokers when possible.
      Returns:
      the built invoker