Interface LazyContext
- All Superinterfaces:
AccessValidator
,CommandContext
- All Known Implementing Classes:
MessageContextImpl
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 Summary
Modifier and TypeMethodDescriptioninitialize
(io.micrometer.observation.ObservationRegistry observations) Partially initializes internal state, making the context minimally ready for handling to start.load()
Loads remaining internal state, making the context fully ready for use.Methods inherited from interface dev.sympho.modular_commands.api.permission.AccessValidator
hasAccess, validate
Methods inherited from interface dev.sympho.modular_commands.api.command.context.CommandContext
belongs, belongs, getArgument, getArgument, getArgument, getCaller, getCallerMember, getChannel, getChannelId, getClient, getCommandInvocation, getContext, getEvent, getGuild, getGuildId, getInvocation, isPrivate, replies, reply, reply, reply, reply, reply, reply, requireArgument, requireArgument, requireArgument, requireContext, setContext, setContext
-
Method Details
-
initialize
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
Mono<CommandResult> load()Loads remaining internal state, making the context fully ready for use. It must only be called afterinitialize(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.
-