Interface Extension

All Superinterfaces:
HasName
All Known Implementing Classes:
AbstractExtension

public interface Extension extends HasName
If you are unsure if you need to implement this interface, you probably want 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 Details

    • name

      @Nonnull String 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!
      Specified by:
      name in interface HasName
      Returns:
      The name of this extension.
    • catnip

      @Nonnull Catnip catnip()
      The catnip instance this extension is registered to. This will not be null, 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

      Extension catnip(@Nonnull Catnip 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 be null. 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 be null.
    • registerHook

      Extension registerHook(@Nonnull CatnipHook hook)
      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

      Extension unregisterHook(@Nonnull CatnipHook hook)
      Unregister a hook from catnip.
      Parameters:
      hook - The hook to unregister.
      Returns:
      The extension instance.
    • injectOptions

      default Extension injectOptions(@Nonnull UnaryOperator<CatnipOptions> optionsPatcher)
      Inject options into the catnip instance. You cannot override token or logExtensionOverrides 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 the ExtensionManager.
      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 the ExtensionManager.
      Returns:
      a Completable which will be waited by the calling thread for its completion, or null if none.
    • observable

      <T> io.reactivex.rxjava3.core.Observable<T> observable(@Nonnull EventType<T> type)
      Add a reactive stream handler for events of the given type. Can be disposed of with Observable.unsubscribeOn(Scheduler). The scheduler argument can be created with Catnip.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

      <T> io.reactivex.rxjava3.core.Flowable<T> flowable(@Nonnull EventType<T> type)
      Add a reactive stream handler for events of the given type. Can be disposed of with Flowable.unsubscribeOn(Scheduler). The scheduler argument can be created with Catnip.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 with Observable.unsubscribeOn(Scheduler). The scheduler argument can be created with Catnip.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 with Flowable.unsubscribeOn(Scheduler). The scheduler argument can be created with Catnip.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.