Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
55 lines (42 sloc)
1.41 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package koob.actor.device | |
import akka.actor.Cancellable | |
import koob.actor.BaseActor | |
import koob.command.* | |
import koob.fsm.FSM | |
import koob.fsm.state.* | |
import grails.util.Holders | |
import groovy.util.logging.Log | |
import scala.concurrent.duration.Duration | |
import java.util.concurrent.TimeUnit | |
@Log | |
class Smoke extends BaseActor implements FSM { | |
def jsonService = Holders.applicationContext.getBean("jsonService") | |
def mqttClientService = Holders.applicationContext.getBean("mqttClientService") | |
Cancellable smokeCoolOffTimer | |
Smoke(){ | |
log.info "smoke machine started" | |
startStateMachine(Off) | |
configureFsmDsl() | |
} | |
@Override | |
void onReceive(Object message) throws Exception { | |
if (message instanceof String && message == "SHOW_CURRENT_STATE") | |
fsm.showState() | |
else if (message instanceof Command) | |
fsm.fire(message) | |
} | |
@Override | |
void configureFsmDsl() { | |
log.info "!!!! configure configureFsmDsl() | currentState: ${fsm.currentState}" | |
} | |
void smokeCoolOffTimer(){ | |
smokeCoolOffTimer = context.system().scheduler().scheduleOnce(Duration.create(20, TimeUnit.SECONDS), | |
new Runnable() { | |
@Override | |
public void run() { | |
smokeCoolOffTimer = null | |
log.info "smoke machine ready" | |
} | |
}, context.system().dispatcher()) | |
} | |
} |