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 TypeMethodDescriptionvoidaddOverride(NodeOverride override) Add an override callback to the associated node.voidaddOverride(NodeOverride override, boolean update) Add an override callback to the associated node.voidTrigger an async rebuild of the graph.getBeverageNode(String nodeId) Return theBeverageNodewith the specified id.getGraph()com.tccc.kos.commons.core.service.handle.HandlegetIngredientNode(String nodeId) Return theIngredientNodewith the specified id.The nozzle the engine is associated with.The pipeline the engine is part of.abstract PourablegetPourable(String definitionStr) Given adefinitionStrstring, return a pourable.booleanisAvailable(String nodeId) Return true if the specified graph node exists and is available.booleanisAvailable(List<String> nodeIds) Return true if all the specified graph nodes exist and are available.abstract booleanisPourable(Pourable pourable) Return true if the specified pourable can currently be poured.voidIndicate that any changes in availability / visibility have been completed and the changes should be processed.voidonAvailabilityChange(List<Pump<?>> pumps) Called when pump availability changes on the nozzle.voidonConfigChanged(com.tccc.kos.commons.core.service.config.BeanChanges changes) voidonContainerInserted(Container container, Pump<?> pump) Called when a container is inserted all the way to a pump.voidonContainerRemoved(Container container, Pump<?> pump) Called when a container is removed.voidonIngredientChange(IngredientService svc, String name, IngredientSource source) Called when a newIngredientSourceis installed intoIngredientService.final voidonNozzleAvailabilityChange(Nozzle nozzle, List<Pump<?>> pumps) Called when there are changes to pump availability.voidonRebuildGraph(BevGraph graph) Called afterrebuildGraph()returns so the engine can populate any state into the newly created graph.abstract voidrebuildGraph(BevGraphBuilder builder) Callback at key events that require the beverage graph to be rebuilt.voidremoveOverride(NodeOverride override) Remove an override from the the engine.voidremoveOverride(NodeOverride override, boolean update) Remove an override from the the engine with ability to control the graph update.voidabstract voidstart()Called once the pipeline is installed and the engine has been autowired.abstract voidstop()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, waitMethods inherited from interface com.tccc.kos.commons.core.service.config.ConfigAware
onConfigSetMethods 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 adefinitionStrstring, 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
Pourableis 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 aBeveageNodeas the node can be looked up when it's time to perform the pour.The implementation can support different styles of pouring. The
definitionStrpassed 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 ofPourableor even custom builtPourableinstances, such as if thedefinitionStrcontains 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 theBeverageNodewith the specified id.- Parameters:
nodeId- id of the node to return
-
getIngredientNode
Return theIngredientNodewith 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 theBevGrapheach 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 theBevGrapheach 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:NozzleAvailabilityListenerCalled when there are changes to pump availability. This will include the nozzle that changed and a list of pumps that changed availability. TheingredientPourandbeveragePourflags in the pump indicate whether the pump can be used for ingredient / beverage pouring. If not available, theunavailableReasonsprovides information about the limitation which can be useful for debugging.- Specified by:
onNozzleAvailabilityChangein interfaceNozzleAvailabilityListener- Parameters:
nozzle- the nozzle the changedpumps- the pumps that changed availability
-
onIngredientChange
Description copied from interface:IngredientChangeListenerCalled when a newIngredientSourceis 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:
onIngredientChangein interfaceIngredientChangeListener- Parameters:
svc- the ingredient servicename- id of the sourcesource- theIngrediengSourcethat was added or changed, null for removed
-
onContainerInserted
Description copied from interface:InsertionPumpListenerCalled 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:
onContainerInsertedin interfaceInsertionPumpListener- Parameters:
container- the container that was insertedpump- the pump inserted into
-
onContainerRemoved
Description copied from interface:InsertionPumpListenerCalled when a container is removed. This callback will be called prior to the holder remove callback.- Specified by:
onContainerRemovedin 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:
onConfigChangedin 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:
getHandlein interfacecom.tccc.kos.commons.core.service.handle.HandleAware
-
getGraph
-
getConfig
- Specified by:
getConfigin interfacecom.tccc.kos.commons.core.service.config.ConfigAware<T extends BeveragePourEngineConfig>
-
setConfig
- Specified by:
setConfigin interfacecom.tccc.kos.commons.core.service.config.ConfigAware<T extends BeveragePourEngineConfig>
-