Interface Extension
- All Superinterfaces:
HasName
- All Known Implementing Classes:
AbstractExtension
AbstractExtension
instead.
An extension is like a "plugin" of sorts - basically, it gives a standardized way to provide extra functionality on top of catnip that is *not* user-level application code. An example of this is providing a command library of some sort. Your library code would be implemented as an extension that an end-user could then optionally load in.
Note that the lifecycle callbacks are called SYNCHRONOUSLY by the default extension manager, and as such you should take care to not block the event loop in those callbacks!
- Since:
- 9/6/18
- Author:
- amy
-
Method Summary
Modifier and TypeMethodDescriptioncatnip()
The catnip instance this extension is registered to.Inject a catnip instance into this extension.<T,
E> io.reactivex.rxjava3.core.Flowable<org.apache.commons.lang3.tuple.Pair<T, E>> flowable
(DoubleEventType<T, E> type) Add a reactive stream handler for events of the given type.<T> io.reactivex.rxjava3.core.Flowable<T>
Add a reactive stream handler for events of the given type.hooks()
default Extension
injectOptions
(UnaryOperator<CatnipOptions> optionsPatcher) Inject options into the catnip instance.Set<MessageConsumer<?>>
name()
The name of this extension.<T,
E> io.reactivex.rxjava3.core.Observable<org.apache.commons.lang3.tuple.Pair<T, E>> observable
(DoubleEventType<T, E> type) Add a reactive stream handler for events of the given type.<T> io.reactivex.rxjava3.core.Observable<T>
observable
(EventType<T> type) Add a reactive stream handler for events of the given type.default io.reactivex.rxjava3.core.Completable
onLoaded()
Callback called once the Extension has been loaded by theExtensionManager
.default io.reactivex.rxjava3.core.Completable
Callback called once the Extension has been unloaded by theExtensionManager
.registerHook
(CatnipHook hook) Register a hook into catnip.unregisterHook
(CatnipHook hook) Unregister a hook from catnip.
-
Method Details
-
name
The name of this extension. Note that an extension's name is NOT guaranteed unique, and so your code should NOT rely on this for uniqueness! -
catnip
The catnip instance this extension is registered to. This will not benull
, as a proper extension manager implementation should inject the current catnip instance BEFORE deploying the extension.- Returns:
- The catnip instance this extension is registered to.
-
catnip
Inject a catnip instance into this extension. This should be the same as the catnip version that is deploying this extension, and must not benull
. A proper extension manager implementation will call this method to inject a catnip instance BEFORE deploying the extension, ie.onLoaded()
will be called AFTER this method.- Parameters:
catnip
- The catnip instance to inject. May not benull
.
-
registerHook
Register a hook into catnip. Hooks are registered by extension, so unloading an extension will also unload all of its hooks.- Parameters:
hook
- The hook to register.- Returns:
- The extension instance.
-
hooks
Set<CatnipHook> hooks()- Returns:
- All hooks registered by this extension instance.
-
listeners
Set<MessageConsumer<?>> listeners()- Returns:
- All listeners registered by this extension instance. Used for things like automatic unregistration of listeners on shutdown.
-
unregisterHook
Unregister a hook from catnip.- Parameters:
hook
- The hook to unregister.- Returns:
- The extension instance.
-
injectOptions
Inject options into the catnip instance. You cannot overridetoken
orlogExtensionOverrides
from this.- Parameters:
optionsPatcher
- A function that makes changes to the provided default options object.- Returns:
- The extension instance.
-
onLoaded
default io.reactivex.rxjava3.core.Completable onLoaded()Callback called once the Extension has been loaded by theExtensionManager
.- Returns:
- a
Completable
which will be waited by the calling thread for its completion, or null if none.
-
onUnloaded
default io.reactivex.rxjava3.core.Completable onUnloaded()Callback called once the Extension has been unloaded by theExtensionManager
.- Returns:
- a
Completable
which will be waited by the calling thread for its completion, or null if none.
-
observable
Add a reactive stream handler for events of the given type. Can be disposed of withObservable.unsubscribeOn(Scheduler)
. Thescheduler
argument can be created withCatnip.rxScheduler()
.This method automatically subscribes on
Catnip.rxScheduler()
.- Type Parameters:
T
- The object type of the event being streamed.- Parameters:
type
- The type of event to stream.- Returns:
- The observable.
-
flowable
Add a reactive stream handler for events of the given type. Can be disposed of withFlowable.unsubscribeOn(Scheduler)
. Thescheduler
argument can be created withCatnip.rxScheduler()
.This method automatically subscribes on
Catnip.rxScheduler()
.- Type Parameters:
T
- The object type of the event being streamed.- Parameters:
type
- The type of event to stream.- Returns:
- The flowable.
-
observable
<T,E> io.reactivex.rxjava3.core.Observable<org.apache.commons.lang3.tuple.Pair<T,E>> observable(@Nonnull DoubleEventType<T, E> type) Add a reactive stream handler for events of the given type. Can be disposed of withObservable.unsubscribeOn(Scheduler)
. Thescheduler
argument can be created withCatnip.rxScheduler()
.This method automatically subscribes on
Catnip.rxScheduler()
.- Type Parameters:
T
- The object type of the event being streamed.E
- The object type of the event being streamed.- Parameters:
type
- The type of event to stream.- Returns:
- The observable.
-
flowable
<T,E> io.reactivex.rxjava3.core.Flowable<org.apache.commons.lang3.tuple.Pair<T,E>> flowable(@Nonnull DoubleEventType<T, E> type) Add a reactive stream handler for events of the given type. Can be disposed of withFlowable.unsubscribeOn(Scheduler)
. Thescheduler
argument can be created withCatnip.rxScheduler()
.This method automatically subscribes on
Catnip.rxScheduler()
.- Type Parameters:
T
- The object type of the event being streamed.E
- The object type of the event being streamed.- Parameters:
type
- The type of event to stream.- Returns:
- The flowable.
-