/* Ċ Ġ* ĠCopyright Ġ@ Ġ 2 0 1 8 Ġ- Ġpresent Ġ 8 x 8 , ĠInc . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . j its i . j ibri . service . impl Ċ Ċ import Ġorg . j its i . j ibri . service . J ibri Service Ċ import Ġorg . j its i . j ibri . service . J ibri Service StateMachine Ċ import Ġorg . j its i . j ibri . service . to J ibri Service Event Ċ import Ġorg . j its i . j ibri . status . Component State Ċ import Ġorg . j its i . j ibri . util . Status Publisher Ċ import Ġjava . util . logging . Logger Ċ Ċ abstract Ġclass ĠStateful J ibri Service ( private Ġval Ġname : ĠString ) Ġ: ĠJ ibri Service () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġstate Machine Ġ= ĠJ ibri Service StateMachine () ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠThe Ġ[ Logger ] Ġfor Ġthis Ġclass ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġprotected Ġval Ġlogger Ġ= ĠLogger . getLogger ( this :: class . qualified Name ) ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġstate Machine . on State Transition ( this :: on Service StateChange ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Service StateChange ( old State : ĠComponent State , ĠnewState : ĠComponent State ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info ("$ name Ġservice Ġtransition ing Ġfrom Ġstate Ġ$ old State Ġto Ġ$ newState ") ĊĠĠĠĠĠĠĠ Ġpublish Status ( newState ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprotected Ġfun Ġregister Sub Component ( sub Component Id : ĠString , Ġsub Component : ĠStatus Publisher < Component State >) Ġ{ ĊĠĠĠĠĠĠĠ Ġstate Machine . register Sub Component ( sub Component Id ) ĊĠĠĠĠĠĠĠ Ġsub Component . add Status Handler Ġ{ Ġstate Update Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstate Machine . transition ( state Update . to J ibri Service Event ( sub Component Id )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }