Example usage for org.springframework.statemachine ExtendedState getVariables

List of usage examples for org.springframework.statemachine ExtendedState getVariables

Introduction

In this page you can find the example usage for org.springframework.statemachine ExtendedState getVariables.

Prototype

Map<Object, Object> getVariables();

Source Link

Document

Gets the extended state variables.

Usage

From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java

@OnTransition(target = "BUSY")
public void busy(ExtendedState extendedState) {
    Object cd = extendedState.getVariables().get(Application.Variables.CD);
    if (cd != null) {
        cdStatus = ((Cd) cd).getName();//from  w  w  w.  j  a  v  a 2 s.com
    }
}

From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java

@Application.StatesOnTransition(target = { Application.States.CLOSED, Application.States.IDLE })
public void closed(ExtendedState extendedState) {
    Object cd = extendedState.getVariables().get(Application.Variables.CD);
    if (cd != null) {
        cdStatus = ((Cd) cd).getName();/*from w  w w.j a v a 2  s.c  om*/
    } else {
        cdStatus = "No CD";
    }
    trackStatus = "";
}

From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java

@Application.StatesOnTransition(target = Application.States.PLAYING)
public void playing(ExtendedState extendedState) {
    Object elapsed = extendedState.getVariables().get(Application.Variables.ELAPSEDTIME);
    Object cd = extendedState.getVariables().get(Application.Variables.CD);
    Object track = extendedState.getVariables().get(Application.Variables.TRACK);
    if (elapsed instanceof Long && track instanceof Integer && cd instanceof Cd) {
        SimpleDateFormat format = new SimpleDateFormat("mm:ss");
        trackStatus = ((Cd) cd).getTracks()[((Integer) track)] + " " + format.format(new Date((Long) elapsed));
    }/*from w ww  . jav  a2  s  . co m*/
}

From source file:demo.scorch.task.TaskStateMachine.java

/**
 * Get the task's ID from the state machine's context.
 *
 * @param extendedState is the context for the state machine.
 * @param state         is the state that the state machine has transitioned to.
 * @return the ID of the state machine's task.
 *///from w  ww  .  ja v a  2s.c o m
private String getTaskId(ExtendedState extendedState, String state) {

    // Get taskId
    String taskId = (String) extendedState.getVariables().getOrDefault("id", null);

    // Perform action associated with state change to running
    log.info(String.format("Task %s state transitioned to %s: %s", taskId, state,
            extendedState.getVariables().keySet()));

    return taskId;
}

From source file:demo.scorch.task.TaskStateMachine.java

/**
 * Send a state change notification to RabbitMQ if the state machine is transitioning state
 * for the first time on the Scorch cluster.
 *
 * @param extendedState is the context of the state machine.
 * @param taskId        is the ID of the task.
 * @param from          is the state that the task is transitioning from.
 * @param to            is the state that the task is transitioning to.
 *///from   w  w  w. j  av a  2 s.c om
private void sendStateChange(ExtendedState extendedState, String taskId, Status from, Status to) {

    Boolean sendMessage = (Boolean) extendedState.getVariables().get(String.format("%s--%s", taskId, from));

    if (taskId != null && sendMessage != null) {
        try {
            rabbitTemplate.convertAndSend(QUEUE_NAME,
                    objectMapper.writeValueAsString(new StateChange(taskId, from, to)));
        } catch (JsonProcessingException e) {
            log.error(e);
        }
    }
}

From source file:demo.scorch.task.TaskStateMachine.java

/**
 * Dispatches an action for a task that is transitioning to FINISH.
 *
 * @param extendedState is the context of the state machine.
 * @param taskId        is the ID of the task.
 * @param task          is the task of the state machine.
 *///w w w .ja v a  2 s . co  m
private void dispatchFinish(ExtendedState extendedState, String taskId, Task task) {
    switch (task.getType()) {
    case JOB:
        if (task.getStatus() != Status.SUCCESS) {
            extendedState.getVariables().put(String.format("%s--%s", taskId, Status.RUNNING), true);
        }
        break;
    case STAGE:
        if (task.getStatus() != Status.SUCCESS) {
            extendedState.getVariables().put(String.format("%s--%s", taskId, Status.RUNNING), true);
        }
        break;
    }
}

From source file:demo.tasks.Tasks.java

@StatesOnTransition(target = States.AUTOMATIC)
public void automaticFix(ExtendedState extendedState) {
    Map<Object, Object> variables = extendedState.getVariables();
    variables.put("T1", true);
    tasks.put("T1", true);
}

From source file:demo.tasks.Tasks.java

private void runTask(String task, ExtendedState extendedState) {
    log.info("run task on " + task);
    sleep(2000);/* ww  w.j a v a 2s  .co  m*/
    extendedState.getVariables().put(task, tasks.get(task));
    log.info("run task on " + task + " done");
}