blob: f5c96913c4dccfc1797ab819089449fa4d83ce50 [file] [log] [blame]
tome33cc1a2014-08-25 21:59:41 -07001package org.onlab.onos.event;
2
tom1a176032014-09-10 12:21:23 -07003import static com.google.common.base.MoreObjects.toStringHelper;
4
tome33cc1a2014-08-25 21:59:41 -07005/**
tom96dfcab2014-08-28 09:26:03 -07006 * Base event implementation.
tome33cc1a2014-08-25 21:59:41 -07007 */
8public class AbstractEvent<T extends Enum, S extends Object> implements Event<T, S> {
9
10 private final long time;
11 private final T type;
12 private S subject;
13
14 /**
15 * Creates an event of a given type and for the specified subject and the
16 * current time.
17 *
18 * @param type event type
19 * @param subject event subject
20 */
21 protected AbstractEvent(T type, S subject) {
22 this(type, subject, System.currentTimeMillis());
23 }
24
25 /**
26 * Creates an event of a given type and for the specified subject and time.
27 *
28 * @param type event type
29 * @param subject event subject
30 * @param time occurrence time
31 */
32 protected AbstractEvent(T type, S subject, long time) {
33 this.type = type;
34 this.subject = subject;
35 this.time = time;
36 }
37
38 @Override
39 public long time() {
40 return time;
41 }
42
43 @Override
44 public T type() {
45 return type;
46 }
47
48 @Override
49 public S subject() {
50 return subject;
51 }
52
tom1a176032014-09-10 12:21:23 -070053 @Override
54 public String toString() {
55 return toStringHelper(this).add("time", time).add("type", type())
56 .add("subject", subject()).toString();
57 }
58
tome33cc1a2014-08-25 21:59:41 -070059}