package Ġtech . ef xl abs . akka . iot Ċ Ċ import Ġakka . actor . typed . Actor Ref Ċ import Ġakka . actor . typed . Behavior Ċ import Ġakka . actor . typed . Post Stop Ċ import Ġakka . actor . typed . Signal Ċ import Ġakka . actor . typed . jav ad sl .* Ċ import Ġjava . util .* Ċ Ċ class ĠDevice Ġprivate Ġconstructor ( context : Actor Context < Command >, Ġprivate Ġval ĠgroupId : String , Ġprivate Ġval ĠdeviceId : String ) ĊĠĠĠ Ġ: ĠAbstract Behavior < Device . Command >( context ){ ĊĊĠĠĠ Ġprivate Ġvar Ġlast Temperature Reading : ĠOptional < Double > Ġ= ĠOptional . empty () ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext . log . info (" Device [ Ġ$ deviceId , Ġ$ groupId Ġ] Ġstarted !") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsealed Ġclass ĠCommand Ġ{ ĊĠĠĠĠĠĠĠ Ġclass ĠRead Temperature ( val ĠrequestId : ĠLong , Ġval Ġreply To : ĠActor Ref < Respond Temperature >) Ġ: ĠCommand () ĊĠĠĠĠĠĠĠ Ġclass ĠRespond Temperature ( val ĠrequestId : ĠLong , Ġval Ġtemperature Value : ĠOptional < Double >) ĊĠĠĠĠĠĠĠ Ġclass ĠRecord Temperature ( val ĠrequestId : ĠLong , Ġval Ġtemperature Value : Double , Ġval Ġreply To : Actor Ref < Temperature Re corded >) Ġ: ĠCommand () ĊĠĠĠĠĠĠĠ Ġclass ĠTemperature Re corded ( val ĠrequestId : ĠLong ) ĊĠĠĠĠĠĠĠ Ġclass ĠPass ivate ( val ĠrequestId : ĠLong ): Command () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġcreate Receive (): ĠReceive < Command > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġnew Receive Builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. on Message ( Command . Read Temperature :: class . java , Ġthis :: read Temperature ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. on Message ( Command . Record Temperature :: class . java , Ġthis :: record Temperature ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. on Message ( Command . Pass ivate :: class . java ){ Be haviors . stopped ()} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. on Signal ( Post Stop :: class . java , Ġthis :: on Stop ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġread Temperature ( command : ĠCommand . Read Temperature ): Behavior < Command > Ġ{ ĊĠĠĠĠĠĠĠ Ġcommand . reply To . tell ( Command . Respond Temperature ( command . requestId , last Temperature Reading )) ĊĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrecord Temperature ( command : ĠCommand . Record Temperature ): ĠBehavior < Command > Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext . log . info (" Temperature Ġrecorded Ġwith Ġvalue : Ġ${ command . temperature Value }, ĠrequestId : Ġ${ command . requestId } Ġby ĠDevice Ġ[$ deviceId , Ġ$ groupId ]") ĊĠĠĠĠĠĠĠ Ġlast Temperature Reading Ġ= ĠOptional . of ( command . temperature Value ) ĊĠĠĠĠĠĠĠ Ġcommand . reply To . tell ( Command . Temperature Re corded ( command . requestId )) ĊĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Stop ( signal : ĠSignal ): Behavior < Command > Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext . log . info (" Device [ Ġ$ deviceId , Ġ$ groupId Ġ] Ġstopped !") ĊĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġcreate ( groupId : ĠString , ĠdeviceId : ĠString ): ĠBehavior < Command > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠBe haviors . setup Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcontext Ġ-> ĠDevice ( context , groupId , ĠdeviceId )} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ /** Ċ Ġ* ĠDevice ĠAct ors Ġrespond Ġto ĠRead Temperature Ġand ĠRecord Temperature ĠCommands Ċ Ġ* ĠRead Temperature Ġwill Ġhave Ġa Ġreply Ġto Ġactor Ġreference Ġof ĠRespond Temperature . Ċ Ġ* ĠRecord Temperature Ġwill Ġhave Ġa Ġreply Ġto Ġactor Ġreference Ġof Ġtype ĠTemperature Re corded Ċ Ġ*/ Ċ