Class BeveragePourEngine<T extends BeveragePourEngineConfig>
- All Implemented Interfaces:
com.tccc.kos.commons.core.service.config.ConfigAware<T>
,com.tccc.kos.commons.core.service.handle.HandleAware
,IngredientChangeListener
,InsertionListener
,InsertionPumpListener
,NozzleAvailabilityListener
- Since:
- 1.0
- Version:
- 2023-02-06
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOverride
(NodeOverride override) Add an override callback to the associated node.void
addOverride
(NodeOverride override, boolean update) Add an override callback to the associated node.void
Trigger an async rebuild of the graph.getBeverageNode
(String nodeId) Return theBeverageNode
with the specified id.getGraph()
com.tccc.kos.commons.core.service.handle.Handle
getIngredientNode
(String nodeId) Return theIngredientNode
with the specified id.The nozzle the engine is associated with.The pipeline the engine is part of.abstract Pourable
getPourable
(String definitionStr) Given adefinitionStr
string, return a pourable.boolean
isAvailable
(String nodeId) Return true if the specified graph node exists and is available.boolean
isAvailable
(List<String> nodeIds) Return true if all the specified graph nodes exist and are available.abstract boolean
isPourable
(Pourable pourable) Return true if the specified pourable can currently be poured.void
Indicate that any changes in availability / visibility have been completed and the changes should be processed.void
onAvailabilityChange
(List<Pump<?>> pumps) Called when pump availability changes on the nozzle.void
onConfigChanged
(com.tccc.kos.commons.core.service.config.BeanChanges changes) void
onContainerInserted
(Container container, Pump<?> pump) Called when a container is inserted all the way to a pump.void
onContainerRemoved
(Container container, Pump<?> pump) Called when a container is removed.void
onIngredientChange
(IngredientService svc, String name, IngredientSource source) Called when a newIngredientSource
is installed intoIngredientService
.final void
onNozzleAvailabilityChange
(Nozzle nozzle, List<Pump<?>> pumps) Called when there are changes to pump availability.void
onRebuildGraph
(BevGraph graph) Called afterrebuildGraph()
returns so the engine can populate any state into the newly created graph.abstract void
rebuildGraph
(BevGraphBuilder builder) Callback at key events that require the beverage graph to be rebuilt.void
removeOverride
(NodeOverride override) Remove an override from the the engine.void
removeOverride
(NodeOverride override, boolean update) Remove an override from the the engine with ability to control the graph update.void
abstract void
start()
Called once the pipeline is installed and the engine has been autowired.abstract void
stop()
Called to shutdown the engine when it is about to be uninstalled.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.service.config.ConfigAware
onConfigSet
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
-
Constructor Details
-
BeveragePourEngine
public BeveragePourEngine()
-
-
Method Details
-
getPipeline
The pipeline the engine is part of. -
getNozzle
The nozzle the engine is associated with. -
start
public abstract void start()Called once the pipeline is installed and the engine has been autowired. This can be used to setup the engine prior to use. -
stop
public abstract void stop()Called to shutdown the engine when it is about to be uninstalled. -
getPourable
Given adefinitionStr
string, return a pourable. The definition is opaque to all parts of the system other than the pour engine. In general the engine will expose beverage data via availability and the definition will be sent from the ui back to the engine based on user selection. However, it is also possible for a ui to gather multiple inputs from the user to include in the definition which the pour engine then uses to construct a complex pour process.A
Pourable
is intended to be long living and survive graph rebuilds. It's typical to hold an instance of a pourble to represent the selected beverage and then clone it for actual use. Based on this, the pourable should not contain references to graph nodes which may change over time. For example, a pourable may hold a beverageId instead of a reference to aBeveageNode
as the node can be looked up when it's time to perform the pour.The implementation can support different styles of pouring. The
definitionStr
passed to this method will never be used anywhere else and can represent complex data about the pour which is used by this method to construct one of potentially many types ofPourable
or even custom builtPourable
instances, such as if thedefinitionStr
contains recipe data.- Parameters:
definitionStr
- the string used to describe what to pour- Throws:
Exception
-
isPourable
Return true if the specified pourable can currently be poured.- Parameters:
pourable
- the pourable to check
-
rebuildGraph
Callback at key events that require the beverage graph to be rebuilt. Return the new graph and it will be installed automatically. The builder includes the list of pumps with ingredients assigned and the builder will already include pump nodes based on the pump paths.Most applications will also call
builder.addIngredientNodes()
to also create nodes for all the ingredients in the pumps which allows a graph to be constructed using ingredients, not pumps.- Parameters:
builder
- the graph builder used to build the graph
-
onRebuildGraph
Called afterrebuildGraph()
returns so the engine can populate any state into the newly created graph. Pump and ingredient nodes will be updated with state before this is called. Override as needed.- Parameters:
graph
- the graph to add state to
-
asyncRebuildGraph
public void asyncRebuildGraph()Trigger an async rebuild of the graph. -
notifyChanges
public void notifyChanges()Indicate that any changes in availability / visibility have been completed and the changes should be processed. -
getBeverageNode
Return theBeverageNode
with the specified id.- Parameters:
nodeId
- id of the node to return
-
getIngredientNode
Return theIngredientNode
with the specified id.- Parameters:
nodeId
- id of the node to return
-
isAvailable
Return true if the specified graph node exists and is available. This tends to be an easy way to verify a beverage is pourable by passing in the beverageId.- Parameters:
nodeId
- the beverage graph node id to check
-
isAvailable
Return true if all the specified graph nodes exist and are available. This is a convenient way to check a list of nodes at the same time such as when verifying that a list of flavors for a beverage are available.- Parameters:
nodeIds
- list of beveerage graph node ids to check
-
onAvailabilityChange
Called when pump availability changes on the nozzle. Any changes to pump availability will already be merged into the graph. Override this if application logic requires additional state changes as a side effect of pump availability changes.notifyChanges()
will be called when this returns which will cause any beverage / brand / group changes to be sent to external listeners.- Parameters:
pumps
- list of pumps that have changed availability
-
addOverride
Add an override callback to the associated node. Any time the node visibility / availability is recomputed the callback will be called and it will have the ability to override these values. This is useful for use cases such as external control of visibility of particular beverages. These callbacks will be automatically connected to theBevGraph
each time it is rebuilt. This will cause the existing graph to update.- Parameters:
override
- the override to attach to the node
-
addOverride
Add an override callback to the associated node. Any time the node visibility / availability is recomputed the callback will be called and it will have the ability to override these values. This is useful for use cases such as external control of visibility of particular beverages. These callbacks will be automatically connected to theBevGraph
each time it is rebuilt. The existing graph will only update based on the update flag.- Parameters:
override
- the override to attach to the nodeupdate
- if false, existing graph will not update
-
removeOverride
Remove an override from the the engine. -
removeOverride
Remove an override from the the engine with ability to control the graph update. In cases where overrides are being removed as part of constructing a new graph, there is no need to update the existing graph so update can be set to false.- Parameters:
override
- the override to removeupdate
- if false, existing graph will not update
-
onNozzleAvailabilityChange
Description copied from interface:NozzleAvailabilityListener
Called when there are changes to pump availability. This will include the nozzle that changed and a list of pumps that changed availability. TheingredientPour
andbeveragePour
flags in the pump indicate whether the pump can be used for ingredient / beverage pouring. If not available, theunavailableReasons
provides information about the limitation which can be useful for debugging.- Specified by:
onNozzleAvailabilityChange
in interfaceNozzleAvailabilityListener
- Parameters:
nozzle
- the nozzle the changedpumps
- the pumps that changed availability
-
onIngredientChange
Description copied from interface:IngredientChangeListener
Called when a newIngredientSource
is installed intoIngredientService
. This can mean that any existing ingredients may now be unknown. It may also mean that previously unknown ingredients are now known.- Specified by:
onIngredientChange
in interfaceIngredientChangeListener
- Parameters:
svc
- the ingredient servicename
- id of the sourcesource
- theIngrediengSource
that was added or changed, null for removed
-
onContainerInserted
Description copied from interface:InsertionPumpListener
Called when a container is inserted all the way to a pump. At this point the pump inserted flag is set the and pump can be used normally.- Specified by:
onContainerInserted
in interfaceInsertionPumpListener
- Parameters:
container
- the container that was insertedpump
- the pump inserted into
-
onContainerRemoved
Description copied from interface:InsertionPumpListener
Called when a container is removed. This callback will be called prior to the holder remove callback.- Specified by:
onContainerRemoved
in interfaceInsertionPumpListener
- Parameters:
container
- the container that was removedpump
- the associated pump
-
onConfigChanged
public void onConfigChanged(com.tccc.kos.commons.core.service.config.BeanChanges changes) - Specified by:
onConfigChanged
in interfacecom.tccc.kos.commons.core.service.config.ConfigAware<T extends BeveragePourEngineConfig>
-
getIngredientService
-
getHandle
public com.tccc.kos.commons.core.service.handle.Handle getHandle()- Specified by:
getHandle
in interfacecom.tccc.kos.commons.core.service.handle.HandleAware
-
getGraph
-
getConfig
- Specified by:
getConfig
in interfacecom.tccc.kos.commons.core.service.config.ConfigAware<T extends BeveragePourEngineConfig>
-
setConfig
- Specified by:
setConfig
in interfacecom.tccc.kos.commons.core.service.config.ConfigAware<T extends BeveragePourEngineConfig>
-