Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 16 | package org.onlab.onos.event; |
| 17 | |
tom | 1a17603 | 2014-09-10 12:21:23 -0700 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 20 | /** |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 21 | * Base event implementation. |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 22 | */ |
| 23 | public class AbstractEvent<T extends Enum, S extends Object> implements Event<T, S> { |
| 24 | |
| 25 | private final long time; |
| 26 | private final T type; |
| 27 | private S subject; |
| 28 | |
| 29 | /** |
| 30 | * Creates an event of a given type and for the specified subject and the |
| 31 | * current time. |
| 32 | * |
| 33 | * @param type event type |
| 34 | * @param subject event subject |
| 35 | */ |
| 36 | protected AbstractEvent(T type, S subject) { |
| 37 | this(type, subject, System.currentTimeMillis()); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Creates an event of a given type and for the specified subject and time. |
| 42 | * |
| 43 | * @param type event type |
| 44 | * @param subject event subject |
| 45 | * @param time occurrence time |
| 46 | */ |
| 47 | protected AbstractEvent(T type, S subject, long time) { |
| 48 | this.type = type; |
| 49 | this.subject = subject; |
| 50 | this.time = time; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public long time() { |
| 55 | return time; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public T type() { |
| 60 | return type; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public S subject() { |
| 65 | return subject; |
| 66 | } |
| 67 | |
tom | 1a17603 | 2014-09-10 12:21:23 -0700 | [diff] [blame] | 68 | @Override |
| 69 | public String toString() { |
| 70 | return toStringHelper(this).add("time", time).add("type", type()) |
| 71 | .add("subject", subject()).toString(); |
| 72 | } |
| 73 | |
tom | e33cc1a | 2014-08-25 21:59:41 -0700 | [diff] [blame] | 74 | } |