1 package xuml.tools.model.compiler.runtime;
2
3 import java.io.Serializable;
4
5 import scala.concurrent.duration.Duration;
6
7 public interface Entity<T> {
8
9 Serializable getId();
10
11 /**
12 * Returns a string that uniquely represents an individual entity in the
13 * database.
14 *
15 * @return
16 */
17 String uniqueId();
18
19 /**
20 * Signals the entity with the given event. ThreadLocal will be used to
21 * detect if an event is to self or not. Events to self are queued up to run
22 * synchronously after the on-entry procedure on this entity associated with
23 * the event is run and before the transaction is committed. Only after the
24 * transaction is committed successfully will the signals to other entities
25 * that were made by the on-entry procedure be sent.
26 *
27 * @param event
28 */
29 T signal(Event<T> event);
30
31 /**
32 * Signals the entity with the given event after the given delay.
33 * ThreadLocal will be used to detect if an event is to self or not. Events
34 * to self are queued up to run synchronously after the on-entry procedure
35 * on this entity associated with the event is run and before the
36 * transaction is committed. Only after the transaction is committed
37 * successfully will the signals to other entities that were made by the
38 * on-entry procedure be sent.
39 *
40 * @param event
41 */
42 T signal(Event<T> event, Duration delay);
43
44 /**
45 * Signals the entity with the given event at the given epoch time in ms.
46 * ThreadLocal will be used to detect if an event is to self or not. Events
47 * to self are queued up to run synchronously after the on-entry procedure
48 * on this entity associated with the event is run and before the
49 * transaction is committed. Only after the transaction is committed
50 * successfully will the signals to other entities that were made by the
51 * on-entry procedure be sent.
52 *
53 * @param event
54 */
55 T signal(Event<T> event, long time);
56
57 /**
58 * Runs the on-entry procedure associated with this event. No transaction is
59 * opened around the on-entry procedure. This method should be used for unit
60 * testing purposes only. Please use the signal method instead.
61 *
62 * @param event
63 */
64 T event(Event<T> event);
65
66 /**
67 * Returns a helper instance for this entity. The helper keeps track of
68 * calls to self and to other entities during an on-entry procedure and
69 * ensures they are run at the appropriate time.
70 *
71 * @return
72 */
73 EntityHelper helper();
74
75 }