T
- The type of data associated with this attribute.public final class ExecutionAttribute<T> extends Object
ExecutionAttributes
.
This is typically used as a static final field in an ExecutionInterceptor
:
class MyExecutionInterceptor implements ExecutionInterceptor {
private static final ExecutionAttribute<String> DATA = new ExecutionAttribute<>();
public void beforeExecution(Context.BeforeExecution execution, ExecutionAttributes executionAttributes) {
executionAttributes.put(DATA, "Request: " + execution.request());
}
public void afterExecution(Context.AfterExecution execution, ExecutionAttributes executionAttributes) {
String data = executionAttributes.get(DATA); // Retrieve the value saved in beforeExecution.
}
}
Modifier and Type | Class and Description |
---|---|
static class |
ExecutionAttribute.DerivedAttributeBuilder<T,U> |
protected static class |
ExecutionAttribute.MappedAttributeBuilder<T,U> |
Constructor and Description |
---|
ExecutionAttribute(String name)
Creates a new
ExecutionAttribute bound to the provided type param. |
Modifier and Type | Method and Description |
---|---|
static <T,U> ExecutionAttribute.DerivedAttributeBuilder<T,U> |
derivedBuilder(String name,
Class<T> attributeType,
ExecutionAttribute<U> realAttribute)
Create an execution attribute whose value is derived from another attribute.
|
boolean |
equals(Object o)
This override considers execution attributes with the same name
to be the same object for the purpose of attribute merge.
|
int |
hashCode()
This override considers execution attributes with the same name
to be the same object for the purpose of attribute merge.
|
protected static <T,U> ExecutionAttribute.MappedAttributeBuilder<T,U> |
mappedBuilder(String name,
Class<T> attributeType,
Supplier<ExecutionAttribute<U>> realAttributeSupplier)
Create an execution attribute whose value get mapped to another execution attribute.
|
String |
toString() |
public ExecutionAttribute(String name)
ExecutionAttribute
bound to the provided type param.name
- Descriptive name for the attribute, used primarily for debugging purposes.public static <T,U> ExecutionAttribute.DerivedAttributeBuilder<T,U> derivedBuilder(String name, Class<T> attributeType, ExecutionAttribute<U> realAttribute)
Whenever this value is read, its value is read from a different "real" attribute, and whenever this value is written its value is written to the "real" attribute, instead.
This is useful when new attributes are created to replace old attributes, but for backwards-compatibility those old attributes still need to be made available.
name
- The name of the attribute to createattributeType
- The type of the attribute being createdrealAttribute
- The "real" attribute from which this attribute is derivedprotected static <T,U> ExecutionAttribute.MappedAttributeBuilder<T,U> mappedBuilder(String name, Class<T> attributeType, Supplier<ExecutionAttribute<U>> realAttributeSupplier)
Whenever this value is read, its value is read from the given attribute, but whenever this value is written its value is written to the given attribute AND the mapped attribute.
This is useful when you have some attribute that depends on the value of another.
name
- The name of the attribute to createattributeType
- The type of the attribute being createdrealAttributeSupplier
- The supplier for the mapped attribute which is mapped from this attributepublic boolean equals(Object o)
Copyright © 2023. All rights reserved.