List of usage examples for org.apache.commons.scxml2 TriggerEvent SIGNAL_EVENT
int SIGNAL_EVENT
To view the source code for org.apache.commons.scxml2 TriggerEvent SIGNAL_EVENT.
Click Source Link
SIGNAL_EVENT
. From source file:com.github.woonsan.commons.scxml.examples.stopwatch.StopWatchFrame.java
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); try {//from ww w . j a v a 2s.com if ("START".equals(command)) { executor.triggerEvent(new TriggerEvent("watch.start", TriggerEvent.SIGNAL_EVENT)); startButton.setEnabled(false); stopButton.setEnabled(true); resetButton.setEnabled(false); } else if ("STOP".equals(command)) { executor.triggerEvent(new TriggerEvent("watch.stop", TriggerEvent.SIGNAL_EVENT)); startButton.setEnabled(true); stopButton.setEnabled(false); resetButton.setEnabled(true); } else if ("RESET".equals(command)) { executor.triggerEvent(new TriggerEvent("watch.reset", TriggerEvent.SIGNAL_EVENT)); startButton.setEnabled(true); stopButton.setEnabled(false); resetButton.setEnabled(false); } } catch (ModelException e) { e.printStackTrace(); } }
From source file:it.polito.elite.dog.drivers.appliances.base.ApplianceDriverInstance.java
/** * Handles notifications coming from the meter associated to the device * handled by this driver. Currently on// w ww . ja v a2 s.c o m * {@link SinglePhaseActivePowerMeasurementNotification} are supported. * * @param currentNotification * The {@link Notification} to handle. */ public void handleNotification(Notification currentNotification) { //check if an executor is available if (this.executor != null) { // default behavior, only handle single phase active power // notifications, can be overridden if (currentNotification instanceof SinglePhaseActivePowerMeasurementNotification) { // get the notification name String name = SinglePhaseActivePowerMeasurementNotification.notificationName; // converts to a power measure @SuppressWarnings("unchecked") DecimalMeasure<Power> value = (DecimalMeasure<Power>) ((SinglePhaseActivePowerMeasurementNotification) currentNotification) .getPowerValue(); // build an event representing the new measure in Watt... // TODO check if it could be generalized to all notifications? // maybe using evaluators? TriggerEvent event = new TriggerEvent(name, TriggerEvent.SIGNAL_EVENT, new Double(value.to(SI.WATT).getValue().doubleValue())); // trigger the event in the state machine try { this.executor.triggerEvent(event); } catch (ModelException e) { // log the error, and continue this.logger.log(LogService.LOG_WARNING, "Error while triggering a new event on the device state machine for device: " + device.getDeviceId(), e); } } } }
From source file:org.onehippo.repository.scxml.SCXMLWorkflowExecutor.java
/** * Invokes {@link SCXMLExecutor#triggerEvent(TriggerEvent)} with a {@link TriggerEvent#SIGNAL_EVENT}, the provided * action as event name and payload as event payload * <p>//w w w .j a v a2s . c o m * The action will first be validated against the provided custom actions map which must * have this action defined with value Boolean.TRUE, otherwise a WorkflowException is thrown before even invoking * the state machine. * </p> * @return {@link SCXMLWorkflowContext#getResult()} if there's no exception. */ public Object triggerAction(String action, Map<String, Boolean> actionsMap, Map<String, Object> payload) throws WorkflowException { if (!started) { throw new WorkflowException("Workflow " + scxmlId + " not started"); } if (terminated) { throw new WorkflowException("Workflow " + scxmlId + " already terminated"); } try { Boolean allowed = actionsMap.get(action); if (allowed == null || !allowed) { throw new WorkflowException("Cannot invoke workflow " + scxmlId + " action " + action + ": action not allowed or undefined"); } TriggerEvent event = new TriggerEvent(action, TriggerEvent.SIGNAL_EVENT, payload); if (payload == null) { log.debug("Invoking workflow {} action {}", scxmlId, action); } else { log.debug("Invoking workflow {} action {} with payload {}", scxmlId, action, payload.toString()); } // reset result context.setResult(null); executor.triggerEvent(event); if (executor.getCurrentStatus().isFinal()) { terminated = true; } } catch (Exception e) { handleException(e); } // only reached when no exception return context.getResult(); }