1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.invoke;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.commons.scxml.SCXMLExecutor;
22 import org.apache.commons.scxml.TriggerEvent;
23 import org.apache.commons.scxml.model.ModelException;
24
25 /***
26 * Trigger the given {@link TriggerEvent} (or array of) on the given
27 * state machine executor asynchronously, once.
28 */
29 class AsyncTrigger implements Runnable {
30
31 /*** The state machine executor. */
32 private final SCXMLExecutor executor;
33 /*** The event(s) to be triggered. */
34 private final TriggerEvent[] events;
35 /*** The log. */
36 private final Log log = LogFactory.getLog(AsyncTrigger.class);
37
38 /***
39 * Constructor.
40 *
41 * @param executor The {@link SCXMLExecutor} to trigger the event on.
42 * @param event The {@link TriggerEvent}.
43 */
44 AsyncTrigger(final SCXMLExecutor executor, final TriggerEvent event) {
45 this.executor = executor;
46 this.events = new TriggerEvent[1];
47 this.events[0] = event;
48 }
49
50 /***
51 * Fire the trigger(s) asynchronously.
52 */
53 public void start() {
54 new Thread(this).start();
55 }
56
57 /***
58 * Fire the event(s).
59 */
60 public void run() {
61 try {
62 synchronized (executor) {
63 executor.triggerEvents(events);
64 }
65 } catch (ModelException me) {
66 log.error(me.getMessage(), me);
67 }
68 }
69
70 }
71