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
ConstructorDescriptionPluginComponentBinding
(Class<? extends I> inter, T impl) Creates an instance of aPluginComponentBinding
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.impl()
Returns the value of theimpl
record component.inter()
Returns the value of theinter
record component.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
PluginComponentBinding
Creates an instance of aPluginComponentBinding
record class.- Parameters:
inter
- the value for theinter
record componentimpl
- the value for theimpl
record 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 theinter
record component.- Returns:
- the value of the
inter
record component
-
impl
Returns the value of theimpl
record component.- Returns:
- the value of the
impl
record component
-