Interface ContextAccessor<READ,WRITE>

Type Parameters:
READ - type of context for reading
WRITE - type of context for writing

public interface ContextAccessor<READ,WRITE>
Contract to assist with access to an external, map-like context, such as the Project Reactor Context, including the ability to read values from it a Map and to write values to it from a Map.
Since:
1.0.0
  • Method Details

    • readableType

      Class<? extends READ> readableType()
      Class representing the type of context this accessor is capable of reading values from.
    • readValues

      void readValues(READ sourceContext, Predicate<Object> keyPredicate, Map<Object,Object> readValues)
      Read values from a source context into a Map.
      Parameters:
      sourceContext - the context to read from; the context type should be assignable from the type returned by readableType().

      When an ContextAccessor is used to populate a ContextSnapshot, the snapshot implementations are required to filter out null mappings, so it is not required to implement special handling in the accessor.

      keyPredicate - a predicate to decide which keys to read
      readValues - a map where to put read values
    • readValue

      @Nullable <T> T readValue(READ sourceContext, Object key)
      Read a single value from the source context.
      Parameters:
      sourceContext - the context to read from; the context type should be assignable from the type returned by readableType().
      key - the key to use to look up the context value
      Returns:
      the value, if present
    • writeableType

      Class<? extends WRITE> writeableType()
      Class representing the type of context this accessor can restore values to.
    • writeValues

      WRITE writeValues(Map<Object,Object> valuesToWrite, WRITE targetContext)
      Write values from a Map to a target context.
      Parameters:
      valuesToWrite - the values to write to the target context.
      targetContext - the context to write to; the context type should be assignable from the type returned by writeableType().
      Returns:
      a context with the written values