Interface LazyContext

All Superinterfaces:
AccessValidator, CommandContext
All Known Implementing Classes:
MessageContextImpl

public interface LazyContext extends CommandContext
A command context whose values (particularly arguments) are lazy-loaded (that is, are not loaded until requested by initialize(ObservationRegistry) and load()).

This interface is not involved in the creation of commands in any way. It is only used internally to decouple initialization/parsing/validation from instantiation and from eachother.

Since:
1.0
Version:
1.0
  • Method Details

    • initialize

      Mono<Void> initialize(io.micrometer.observation.ObservationRegistry observations)
      Partially initializes internal state, making the context minimally ready for handling to start.

      The only parts of the context API that are guaranteed to be ready to use before this method is called are the ones that retrieve pieces of the invocation context, that is CommandContext.getEvent(), CommandContext.getCaller(), CommandContext.getChannel(), etc, as well as this method itself. All other methods have undefined behavior.

      After this method is called and the returned mono completes successfully, the following pieces of the API also become ready to be used:

      • Reply manager
      • Access and group checking
      • load()

      Calling any part of the API other than those listed will continue to result in undefined behavior until load() is called and successfully completes.

      This method is idempotent; if it is called multiple times, the context will still be initialized only once, and all the returned Monos will only complete once it has finished loading.

      Parameters:
      observations - The registry to use for observations.
      Returns:
      A Mono that completes once the context is initialized.
    • load

      Loads remaining internal state, making the context fully ready for use. It must only be called after initialize(ObservationRegistry) completes successfully, otherwise its behavior is undefined.

      Until this method is called and the returned mono completes successfully, all methods other than this one (and those specified in initialize(ObservationRegistry) have undefined behavior.

      This method is idempotent; if it is called multiple times, the context will still be loaded only once, and all the returned Monos will only complete once it has finished loading, with the same result.

      Returns:
      A Mono that completes empty once internal values are successfully loaded. If a situation where the invocation should be terminated is encountered, it emits the appropriate failure result.
      API Note:
      This is split from initialize(ObservationRegistry) for performance reasons; only a very limited subset of the API is necessary for early processing of the command, and things such as argument parsing can be relatively expensive, thus it is beneficial to delay the latter until later in the processing pipeline once they are actually needed.