Interface Introspection
- All Known Implementing Classes:
IntrospectionImpl
The introspection api provides read-only access to JDA-Commands property system and allows
subscribing to FrameworkEvents in the frameworks interaction execution process.
To access the api, you can either
- use
JDACommands.introspection()orEvent.introspection() - use
accessScoped()that will return the current instance of this scope
When accessing trough accessScoped(), you have to pay attention where you do so.
An Introspection instance is set in most but not in all places, to know where you can use it take a look at the
IntrospectionAccess annotation on user implementable methods provided by the framework.
Inside of interaction controller methods
(the ones having ComponentEvent, CommandEvent etc. as a parameter and are defined inside a class annotated with Interaction )
the Introspection instance is always set with the stage Stage.INTERACTION, providing access to all Propertys.
Stage and Properties access
The Property API allows accessing all public components and configuration options of JDA-Commands.
It can be used to retrieve framework services like MessageResolver, config options like Property.GLOBAL_REPLY_CONFIG
or context dependent information like InvocationContext.
Please note that access is read-only, you can't set the value of a Property after starting the framework.
Based on the location (in code) where you access this api, the available Properties may very.
To know what property is accessible, take a look at currentStage() and compare it to Property.stage().
A hint on the current stage is also provided by IntrospectionAccess.value().
FrameworkEvents
Sometimes it's convenient to execute some custom code at some point during runtime based on events inside the framework.
An example can be found inside the guice extension, were we use a RuntimeCloseEvent to remove
the interaction controller instances inside the cache at the end of a conversation.
To subscribe to a FrameworkEvent you use subscribe(Class, Subscriber) which returns a Subscription allowing you
to "unsubscribe" from this event later. If an FrameworkEvent is fired by JDA-Commands all Subscribers of that event
are called.
It's important to know that the events are published by multiple threads perhaps concurrently, thus Subscribers
may be also called concurrently. They have to be written with threadsafety in mind!
- Implementation Note:
- Internally
accessScoped()usesScopedValues. For further clarification on how this works withThreads take a look there.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether anIntrospectioninstance can be access byaccessScoped()static IntrospectionGets the currentIntrospectioninstance of this scope if set.Returns the currentStageof this introspection instance.<T> TGets the value of a property.static <T> TShorthand forIntrospection.access().get(Property).<T extends FrameworkEvent>
Subscriptionsubscribe(Class<T> event, Subscriber<T> subscriber) Subscribes to specificFrameworkEventallowing you to execute custom logic at multiple points during runtime.
-
Method Details
-
accessible
static boolean accessible()Checks whether anIntrospectioninstance can be access byaccessScoped()- Returns:
truewhen you can useaccessScoped(),falsewhen not.- See Also:
-
accessScoped
Gets the current
Introspectioninstance of this scope if set. For further information on when this is available take a look at the class docs.The available properties are based on the
Stageof the current instance, you can check the currently available stage viacurrentStage().- Throws:
NoSuchElementException- if noIntrospectioninstance is set- See Also:
-
scopedGet
Shorthand for
Introspection.access().get(Property).This method is scope dependent, see
accessScoped().- Parameters:
property- the requestedProperty- Returns:
- the property's value
- Throws:
NoSuchElementException- if noIntrospectioninstance is set- See Also:
-
currentStage
-
get
Gets the value of a property. At that point practically all properties should be resolved and caches, you can expect nearly instant access time.
To exactly know what this does take a look at
PropertyProviderandPropertyProvider.Context.get(Property).- Parameters:
property- the requestedProperty- Returns:
- the property's value
-
subscribe
Subscribes to specificFrameworkEventallowing you to execute custom logic at multiple points during runtime.- Parameters:
event- the concrete class ofFrameworkEvent, e.g.RuntimeCloseEvent.classsubscriber- theSubscriberholding the logic to be executed- Returns:
- the
Subscriptioninstance as a unique reference to your subscription, allowing you to later cancel it.
-