Record Class PythonReactiveContext

java.lang.Object
java.lang.Record
io.micronaut.context.python.PythonReactiveContext
Record Components:
reactorContext - The Reactor reactor.util.context.Context of the subscriber, or null when Reactor is not on the class path or the coroutine was started eagerly; typed as an object so the record loads without Reactor
propagatedContext - The propagated context of the subscriber or caller

@Internal public record PythonReactiveContext(@Nullable Object reactorContext, PropagatedContext propagatedContext) extends Record
The reactive context a subscriber (or the caller of an eager coroutine) hands to a Python coroutine: the Reactor context of the subscription (a reactive transaction status lives there) and the propagated context it carries. The asyncio task keeps it in a contextvars variable, so every publisher the coroutine awaits is subscribed within it and every callback of the task runs in its propagated context, whichever thread or task scheduled the callback.
Since:
5.2.0
  • Constructor Details

    • PythonReactiveContext

      public PythonReactiveContext(@Nullable Object reactorContext, PropagatedContext propagatedContext)
      Creates an instance of a PythonReactiveContext record class.
      Parameters:
      reactorContext - the value for the reactorContext record component
      propagatedContext - the value for the propagatedContext record component
  • Method Details

    • inheriting

      public PythonReactiveContext inheriting(PythonReactiveContext enclosing)
      The context of a coroutine started inside a task: this one, with the Reactor context of the enclosing task when this one has none (an eager start carries the propagated context of the caller only, and a nested coroutine must subscribe within the enclosing transaction). The propagated context of the caller is written into the inherited Reactor context, so a publisher looking it up there (a reactive transaction, tracing) finds the same context the thread runs in rather than the one of the enclosing subscription.
      Parameters:
      enclosing - The reactive context of the task the coroutine is started from
      Returns:
      The context of the new task
    • run

      public void run(Runnable callback)
      Run a callback of the task in the propagated context; called by the asyncio module for every call_soon/call_later callback of a task that carries this context.
      Parameters:
      callback - The callback
    • 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.
    • reactorContext

      public @Nullable Object reactorContext()
      Returns the value of the reactorContext record component.
      Returns:
      the value of the reactorContext record component
    • propagatedContext

      public PropagatedContext propagatedContext()
      Returns the value of the propagatedContext record component.
      Returns:
      the value of the propagatedContext record component