Package discord4j.common.store
Class Store
java.lang.Object
discord4j.common.store.Store
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:
-
Method Summary
Modifier and TypeMethodDescription<R> Publisher<R>execute(StoreAction<R> action) Executes the given action.static StorefromLayout(StoreLayout layout) Creates a newStorethat will handle actions according to the given layout.static StorefromLayouts(StoreLayout... layouts) Creates a newStorethat will merge actions from multiple layouts.static StorenoOp()Returns aStorethat will ignore all actions.
-
Method Details
-
noOp
Returns aStorethat will ignore all actions.- Returns:
- a no-op
Store
-
fromLayout
Creates a newStorethat will handle actions according to the given layout.- Parameters:
layout- aStoreLayout- Returns:
- a new
Store
-
fromLayouts
Creates a newStorethat will merge actions from multiple layouts. OverlappingStoreActionsfrom each layout will be merged by keeping the first layout that declared it.- Parameters:
layouts- aStoreLayoutarray- Returns:
- a new
Store
-
execute
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.
-