blob: 30d35ee637d2007878a88136e7b795279ad64ffc [file] [log] [blame]
Sean Condon5548ce62018-07-30 16:00:10 +01001/*
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.protocol.rest;
18
19import org.onosproject.event.AbstractEvent;
20import org.onosproject.net.DeviceId;
21
22import javax.ws.rs.sse.InboundSseEvent;
23
24import java.util.Objects;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Event received on the REST SB interface as ServerSentEvent (SSE_INBOUND).
30 */
31public class RestSBServerSentEvent extends AbstractEvent<RestSBServerSentEvent.Type, DeviceId> {
32
33 private String id;
34 private String comment;
35 private String data;
36 private String name;
37
38 /**
39 * SSE Event types supported.
40 */
41 public enum Type {
42 SSE_INBOUND
43 }
44
45 public RestSBServerSentEvent(Type type, DeviceId deviceId, InboundSseEvent sseEvent) {
46 super(type, deviceId);
47 checkNotNull(sseEvent);
48 data = sseEvent.readData();
49 id = sseEvent.getId();
50 name = sseEvent.getName();
51 comment = sseEvent.getComment();
52 }
53
54 public String getData() {
55 return data;
56 }
57
58 public String getId() {
59 return id;
60 }
61
62 public String getComment() {
63 return comment;
64 }
65
66 public String getName() {
67 return name;
68 }
69
70 @Override
71 public String toString() {
72 return super.toString() + ", id=" + id + ", name=" + name + ", comment=" + comment;
73 }
74
75 @Override
76 public boolean equals(Object o) {
77 if (this == o) {
78 return true;
79 }
80 if (o == null || getClass() != o.getClass()) {
81 return false;
82 }
83 RestSBServerSentEvent that = (RestSBServerSentEvent) o;
84 return Objects.equals(id, that.id) &&
85 Objects.equals(comment, that.comment) &&
86 Objects.equals(data, that.data) &&
87 Objects.equals(name, that.name);
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hash(id, comment, data, name);
93 }
94}