Module org.elasticsearch.server
Package org.elasticsearch.node
Record Class PluginComponentBinding<I,T extends I>
java.lang.Object
java.lang.Record
org.elasticsearch.node.PluginComponentBinding<I,T>
- Type Parameters:
I- The interface classT- 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.
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
ConstructorsConstructorDescriptionPluginComponentBinding(Class<? extends I> inter, T impl) Creates an instance of aPluginComponentBindingrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.impl()Returns the value of theimplrecord component.inter()Returns the value of theinterrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PluginComponentBinding
Creates an instance of aPluginComponentBindingrecord class.- Parameters:
inter- the value for theinterrecord componentimpl- the value for theimplrecord component
-
-
Method Details
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
inter
Returns the value of theinterrecord component.- Returns:
- the value of the
interrecord component
-
impl
Returns the value of theimplrecord component.- Returns:
- the value of the
implrecord component
-