forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActEvent.java
More file actions
54 lines (46 loc) · 1.55 KB
/
ActEvent.java
File metadata and controls
54 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package act.event;
import org.osgl.$;
import java.util.EventObject;
/**
* An {@code ActEvent} is a generic version of {@link EventObject}
* @param <T> the generic type (the sub class type) of the event source
*/
public class ActEvent<T> extends EventObject {
private final long ts;
public ActEvent(T source) {
super(source);
ts = $.ms();
}
/**
* Unlike the {@link Object#getClass()} method, which always return
* the java class of the current instance. This {@code eventType()}
* method allow a certain implementation of the class terminate the
* return value of the method. For example, suppose you have a event
* class {@code MyEvent} and you might have some anonymous class
* of {@code MyEvent}. If you implement the {@code eventType()} of
* {@code MyEvent} class as follows:
* <pre>
* public class<MyEvent> eventType() {
* return MyEvent.class;
* }
* </pre>
* Then all the anonymous sub class will return the {@code MyEvent.class}
* instead of their own class.
* <p>This allows the ActFramework properly handle the event class registration</p>
* @return the type of the event
*/
public Class<? extends ActEvent<T>> eventType() {
return $.cast(getClass());
}
public final T source() {
return $.cast(getSource());
}
/**
* Return the timestamp of the event
* @return the timestamp
* @see System#currentTimeMillis()
*/
public final long timestamp() {
return ts;
}
}