Class Store


  • public final class Store
    extends Object
    A Store represents a container that holds, retrieves, and updates data received from Discord throughout the life of a bot application. Any operation performed on a Store (whether it's to read data, update data upon receiving a gateway event, etc) is represented by a StoreAction object, that can be passed to the execute(StoreAction) method. Actions are in charge of encoding all information needed for the store to operate on the data accordingly.

    A Store is constructed by passing a StoreLayout, which defines handlers for the different types of actions, whether they are Discord4J-specific or user-defined. The layout interface allows to enforce support for a minimal set of actions in order to fulfill the caching expectations of the Discord client.

    See Also:
    fromLayout(StoreLayout)
    • Method Detail

      • noOp

        public static Store noOp()
        Returns a Store that will ignore all actions.
        Returns:
        a no-op Store
      • fromLayout

        public static Store fromLayout​(StoreLayout layout)
        Creates a new Store that will handle actions according to the given layout.
        Parameters:
        layout - a StoreLayout
        Returns:
        a new Store
      • execute

        public <R> Publisher<R> execute​(StoreAction<R> action)
        Executes the given action. The action will be routed based on the concrete type of the action, and handled according to the layout given when creating this Store. If the concrete type of the action is unknown and no custom mapping was defined for it, it will return empty.
        Type Parameters:
        R - the type of data returned by the action
        Parameters:
        action - the action to execute
        Returns:
        a Publisher where, upon successful completion, emits the result(s) produced by the execution of the action, if any. If an error is received, it is emitted through the Publisher.