tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 1 | package org.onlab.onos.event; |
| 2 | |
tom | 1a17603 | 2014-09-10 12:21:23 -0700 | [diff] [blame] | 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 4 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 5 | /** |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 6 | * Base event implementation. |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 7 | */ |
| 8 | public 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 | |
tom | 1a17603 | 2014-09-10 12:21:23 -0700 | [diff] [blame] | 53 | @Override |
| 54 | public String toString() { |
| 55 | return toStringHelper(this).add("time", time).add("type", type()) |
| 56 | .add("subject", subject()).toString(); |
| 57 | } |
| 58 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 59 | } |