View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.scxml.invoke;
18  
19  import java.util.Map;
20  
21  import org.apache.commons.scxml.SCInstance;
22  import org.apache.commons.scxml.TriggerEvent;
23  
24  /***
25   * <p>The Invoker interface is used to define the possible interactions
26   * between the parent state machine (executor) and the types of invocable
27   * activities.</p>
28   *
29   * <p>Invocable activities must first register an Invoker implementation class
30   * for the appropriate "targettype" (attribute of &lt;invoke&gt;) with the
31   * parent <code>SCXMLExecutor</code>.</p>
32   *
33   * <p>The communication link between the parent state machine executor and
34   * the invoked activity is a bi-directional events pipe.</p>
35   *
36   * <p>All events triggered on the parent state machine get forwarded to the
37   * invoked activity. The processing semantics for these events depend
38   * upon the "targettype", and thereby vary per concrete implementation of
39   * this interface.</p>
40   *
41   * <p>The invoked activity in turn must fire a special "done" event
42   * when it concludes. It may fire additional events before the "done"
43   * event. The semantics of any additional events depend upon the
44   * "targettype". The invoked activity must not fire any events after the
45   * "done" event. The name of the special "done" event must be
46   * the ID of the parent state wherein the corresponding &lt;invoke&gt;
47   * resides, with the String ".invoke.done" appended.</p>
48   *
49   * <p>The Invoker "lifecycle" is outlined below:
50   *  <ol>
51   *   <li>Instantiation via {@link Class#newInstance()}
52   *       (Invoker implementation requires accessible constructor).</li>
53   *   <li>Configuration (setters for parent state ID and
54   *       {@link SCInstance}).</li>
55   *   <li>Initiation of invoked activity via invoke() method, passing
56   *       the source URI and the map of params.</li>
57   *   <li>Zero or more bi-directional event triggering.</li>
58   *   <li>Either completion or cancellation.</li>
59   *  </ol>
60   * </p>
61   */
62  public interface Invoker {
63  
64      /***
65       * Set the state ID of the owning state for the &lt;invoke&gt;.
66       * Implementations must use this ID for constructing the event name for
67       * the special "done" event (and optionally, for other event names
68       * as well).
69       *
70       * @param parentStateId The ID of the parent state.
71       */
72      void setParentStateId(String parentStateId);
73  
74      /***
75       * Set the "context" of the parent state machine, which provides the
76       * channel.
77       *
78       * @param scInstance The "context" of the parent state machine.
79       */
80      void setSCInstance(SCInstance scInstance);
81  
82      /***
83       * Begin this invocation.
84       *
85       * @param source The source URI of the activity being invoked.
86       * @param params The &lt;param&gt; values
87       * @throws InvokerException In case there is a fatal problem with
88       *                          invoking the source.
89       */
90      void invoke(String source, Map params)
91      throws InvokerException;
92  
93      /***
94       * Forwards the events triggered on the parent state machine
95       * on to the invoked activity.
96       *
97       * @param evts
98       *            an array of external events which triggered during the last
99       *            time quantum
100      *
101      * @throws InvokerException In case there is a fatal problem with
102      *                          processing the events forwarded by the
103      *                          parent state machine.
104      */
105     void parentEvents(TriggerEvent[] evts)
106     throws InvokerException;
107 
108     /***
109      * Cancel this invocation.
110      *
111      * @throws InvokerException In case there is a fatal problem with
112      *                          canceling this invoke.
113      */
114     void cancel()
115     throws InvokerException;
116 
117 }
118