Record Class PluginComponentBinding<I,T extends I>

java.lang.Object
java.lang.Record
org.elasticsearch.node.PluginComponentBinding<I,T>
Type Parameters:
I - The interface class
T - The implementation class

public record PluginComponentBinding<I,T extends I>(Class<? extends I> inter, T extends I impl) extends Record

Describes the relationship between an interface and an implementation for a Plugin component. All Plugin's provide a collection of components via the createComponents(...) that are made available for dependency injection. An ExtensiblePlugin may want to expose an interface such that extensions can change the implementation. Usage of this class allows the interface to made available for dependency injection where the implementation is defined at runtime.

Usage:

public class MyPlugin extends Plugin implements ExtensiblePlugin
{
    @Override
    public Collection<Object> createComponents(...) {
        List<Object> components = new ArrayList<>();
        components.add(new PluginComponentBinding<>(MyInterface.class, this.myImplementation));
        ...
        return components;
    }
    @Override
    public void loadExtensions(ExtensionLoader loader) {
        List<MyInterface> myImplementations = loader.loadExtensions(MyInterface.class);
        if(myImplementations.size() > 0) {
            this.myImplementation = myImplementations.get(0); //use extension provided implementation
        } else {
            this.myImplementation = new StandardMyImplementation()
        }
    }
...
}
public class TransportMyAction extends TransportMasterNodeAction<MyRequest, MyResponse> {
    @Inject
    public TransportMyAction(MyInterface myInterface) {
        this.myInterface = myInterface; //implementation may vary depending on extensions defined for
    }
    ...
}

Note - usage of the class does not change any class loader isolation strategies nor visibility of the provided classes.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PluginComponentBinding(Class<? extends I> inter, T impl)
    Creates an instance of a PluginComponentBinding record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the impl record component.
    Class<? extends I>
    Returns the value of the inter record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PluginComponentBinding

      public PluginComponentBinding(Class<? extends I> inter, T impl)
      Creates an instance of a PluginComponentBinding record class.
      Parameters:
      inter - the value for the inter record component
      impl - the value for the impl record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • inter

      public Class<? extends I> inter()
      Returns the value of the inter record component.
      Returns:
      the value of the inter record component
    • impl

      public T impl()
      Returns the value of the impl record component.
      Returns:
      the value of the impl record component