Package discord4j.common.store
Class Store
- java.lang.Object
-
- discord4j.common.store.Store
-
public final class Store extends Object
AStore
represents a container that holds, retrieves, and updates data received from Discord throughout the life of a bot application. Any operation performed on aStore
(whether it's to read data, update data upon receiving a gateway event, etc) is represented by aStoreAction
object, that can be passed to theexecute(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 aStoreLayout
, 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> Publisher<R>
execute(StoreAction<R> action)
Executes the given action.static Store
fromLayout(StoreLayout layout)
Creates a newStore
that will handle actions according to the given layout.static Store
noOp()
Returns aStore
that will ignore all actions.
-
-
-
Method Detail
-
noOp
public static Store noOp()
Returns aStore
that will ignore all actions.- Returns:
- a no-op
Store
-
fromLayout
public static Store fromLayout(StoreLayout layout)
Creates a newStore
that will handle actions according to the given layout.- Parameters:
layout
- aStoreLayout
- 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 thisStore
. If the concrete type of the action is unknown and no custom mapping was defined for it, it will return empty.
-
-