blob: 5f5b3b93a977221eef5a7ad5a0ba25e55d80360d [file] [log] [blame]
Andrea Campanella1e573442018-05-17 17:07:13 +02001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16
17package org.onosproject.p4runtime.ctl;
18
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.device.ChannelEvent.Type;
21import org.onosproject.p4runtime.api.P4RuntimeEventSubject;
22
23/**
24 * Default implementation of channel event in P4Runtime. It allows passing any type of event.
25 * If the event is an error a throwable can be directly passed.
26 * Any other type of event cause can be passed as string.
27 */
28public class DefaultChannelEvent implements P4RuntimeEventSubject {
29 private DeviceId deviceId;
30 private Type type;
31 private Throwable throwable;
32 private String message;
33
34 /**
35 * Creates channel event with given status and throwable.
36 *
37 * @param deviceId the device
38 * @param type error type
39 * @param throwable the cause
40 */
41 public DefaultChannelEvent(DeviceId deviceId, Type type, Throwable throwable) {
42 this.deviceId = deviceId;
43 this.type = type;
44 this.message = throwable.getMessage();
45 this.throwable = throwable;
46 }
47
48 /**
49 * Creates channel event with given status and string cause.
50 *
51 * @param deviceId the device
52 * @param type error type
53 * @param message the message
54 */
55 public DefaultChannelEvent(DeviceId deviceId, Type type, String message) {
56 this.deviceId = deviceId;
57 this.type = type;
58 this.message = message;
59 this.throwable = null;
60 }
61
62 /**
63 * Creates channel event with given status, cause and throwable.
64 *
65 * @param deviceId the device
66 * @param type error type
67 * @param message the message
68 * @param throwable the cause
69 */
70 public DefaultChannelEvent(DeviceId deviceId, Type type, String message, Throwable throwable) {
71 this.deviceId = deviceId;
72 this.type = type;
73 this.message = message;
74 this.throwable = throwable;
75 }
76
77 /**
78 * Gets the type of this event.
79 *
80 * @return the error type
81 */
82 public Type type() {
83 return type;
84 }
85
86 /**
87 * Gets the message related to this event.
88 *
89 * @return the message
90 */
91 public String message() {
92 return message;
93 }
94
95
96 /**
97 * Gets throwable of this event.
98 * If no throwable is present returns null.
99 *
100 * @return the throwable
101 */
102 public Throwable throwable() {
103 return throwable;
104 }
105
106 @Override
107 public DeviceId deviceId() {
108 return deviceId;
109 }
110}