tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 1 | package org.onlab.onos.event; |
| 2 | |
| 3 | /** |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 4 | * Base event implementation. |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 5 | */ |
| 6 | public class AbstractEvent<T extends Enum, S extends Object> implements Event<T, S> { |
| 7 | |
| 8 | private final long time; |
| 9 | private final T type; |
| 10 | private S subject; |
| 11 | |
| 12 | /** |
| 13 | * Creates an event of a given type and for the specified subject and the |
| 14 | * current time. |
| 15 | * |
| 16 | * @param type event type |
| 17 | * @param subject event subject |
| 18 | */ |
| 19 | protected AbstractEvent(T type, S subject) { |
| 20 | this(type, subject, System.currentTimeMillis()); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Creates an event of a given type and for the specified subject and time. |
| 25 | * |
| 26 | * @param type event type |
| 27 | * @param subject event subject |
| 28 | * @param time occurrence time |
| 29 | */ |
| 30 | protected AbstractEvent(T type, S subject, long time) { |
| 31 | this.type = type; |
| 32 | this.subject = subject; |
| 33 | this.time = time; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public long time() { |
| 38 | return time; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public T type() { |
| 43 | return type; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public S subject() { |
| 48 | return subject; |
| 49 | } |
| 50 | |
| 51 | } |