View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.actors.event;
25  
26  import zeus.util.*;
27  
28  public abstract class Event {
29     protected static final int FACT_FIRST = 0;
30     protected static final int FACT_LAST = 3;
31  
32     protected static final int TASK_FIRST = 4;
33     protected static final int TASK_LAST = 7;
34  
35     protected static final int ABILITY_FIRST = 8;
36     protected static final int ABILITY_LAST = 11;
37  
38     protected static final int RELATION_FIRST = 12;
39     protected static final int RELATION_LAST = 15;
40  
41     protected static final int MESSAGE_FIRST = 16;
42     protected static final int MESSAGE_LAST = 19;
43  
44     protected static final int AGENT_FIRST = 20;
45     protected static final int AGENT_LAST = 23;
46  
47     protected static final int PLANNING_FIRST = 24;
48     protected static final int PLANNING_LAST = 26;
49  
50     protected static final int PLANSTEP_FIRST = 27;
51     protected static final int PLANSTEP_LAST = 29;
52  
53     protected static final int CLOCK_FIRST = 30;
54     protected static final int CLOCK_LAST = 30;
55  
56     protected static final int HANDLER_FIRST = 31;
57     protected static final int HANDLER_LAST = 34;
58  
59     protected static final int NODE_FIRST = 35;
60     protected static final int NODE_LAST = 38;
61  
62     protected static final int ARC_FIRST = 39;
63     protected static final int ARC_LAST = 42;
64  
65     protected static final int GRAPH_FIRST = 43;
66     protected static final int GRAPH_LAST = 46;
67  
68     protected static final int PROTOCOL_FIRST = 47;
69     protected static final int PROTOCOL_LAST = 50;
70  
71     protected static final int CONVERSATION_FIRST = 51;
72     protected static final int CONVERSATION_LAST = 52;
73  
74     protected static final int RETE_FIRST = 53;
75     protected static final int RETE_LAST = 57;
76  
77     public static final int  MAX_ID    = 57;
78     public static final long NULL_MASK = 0L;
79     public static final long ALL_MASK  = ~0L;
80  
81     protected static final String[] event_type = {
82        "FactAddedEvent",
83        "FactModifiedEvent",
84        "FactDeletedEvent",
85        "FactAccessedEvent",
86  
87        "TaskAddedEvent",
88        "TaskModifiedEvent",
89        "TaskDeletedEvent",
90        "TaskAccessedEvent",
91  
92        "AbilityAddedEvent",
93        "AbilityModifiedEvent",
94        "AbilityDeletedEvent",
95        "AbilityAccessedEvent",
96  
97        "RelationAddedEvent",
98        "RelationModifiedEvent",
99        "RelationDeletedEvent",
100       "RelationAccessedEvent",
101 
102       "MessageReceivedEvent",
103       "MessageQueuedEvent",
104       "MessageDispatchedEvent",
105       "MessageNotDispatchedEvent",
106 
107       "AgentCreatedEvent",
108       "AgentDeathEvent",
109       "AgentSuspendedEvent",
110       "AgentResumedEvent",
111 
112       "PlanningStartedEvent",
113       "PlanningFailedEvent",
114       "PlanningSucceededEvent",
115 
116       "PlanStepCreatedEvent",
117       "PlanStepDisposedEvent",
118       "PlanStepStateChangedEvent",
119 
120       "ClockTickEvent",
121 
122       "MessageRuleAddedEvent",
123       "MessageRuleDeletedEvent",
124       "MessageRuleFiredEvent",
125       "MessageRuleFailedEvent",
126 
127       "NodeCreatedEvent",
128       "NodeDisposedEvent",
129       "NodeStateChangedEvent",
130 
131       "ArcCreatedEvent",
132       "ArcDisposedEvent",
133       "ArcFailedEvent",
134       "ArcSucceededEvent",
135 
136       "GraphCreatedEvent",
137       "GraphDisposedEvent",
138       "GraphStateChangedEvent",
139 
140       "ProtocolAddedEvent",
141       "ProtocolModifiedEvent",
142       "ProtocolDeletedEvent",
143       "ProtocolAccessedEvent",
144 
145       "ConversationInitiatedEvent",
146       "ConversationContinuedEvent",
147 
148       "ReteRuleAddedEvent",
149       "ReteRuleDeletedEvent",
150       "ReteRuleActivatedEvent",
151       "ReteRuleDeactivatedEvent",
152       "ReteRuleFiredEvent"
153    };
154 
155    protected long   time = 0;
156    protected int    id = -1;
157    protected Object source = null;
158    protected Object object = null;
159 
160    public long   getTime()        { return time; }
161    public int    getID()          { return id; }
162    public String getDescription() { return event_type[id]; }
163    public Object getSource()      { return source; }
164    public Object getObject()      { return object; }
165 
166    protected Event(Object source, Object object, int first,
167                    int last, long mask) {
168       id = (int)(Math.log((double)mask)/Math.log(2.0)) + first;
169       Assert.notNull(source);
170       Assert.notNull(object);
171       Assert.notFalse(0 <= first && first <= id &&
172                       id <= last && last <= MAX_ID);
173       this.time = System.currentTimeMillis();
174       this.source = source;
175       this.object = object;
176    }
177    public String toString() {
178       return getDescription() + ":\n\tTime: " + time +
179                                  "\n\tSource: " + source +
180                                  "\n\tObject: " + object;
181    }
182 }