blob: cc4735d5c8171601007deaf9e482672b84938123 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 */
tome33cc1a2014-08-25 21:59:41 -070016package org.onlab.onos.event;
17
tom1a176032014-09-10 12:21:23 -070018import static com.google.common.base.MoreObjects.toStringHelper;
19
tome33cc1a2014-08-25 21:59:41 -070020/**
tom96dfcab2014-08-28 09:26:03 -070021 * Base event implementation.
tome33cc1a2014-08-25 21:59:41 -070022 */
23public 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
tom1a176032014-09-10 12:21:23 -070068 @Override
69 public String toString() {
70 return toStringHelper(this).add("time", time).add("type", type())
71 .add("subject", subject()).toString();
72 }
73
tome33cc1a2014-08-25 21:59:41 -070074}