blob: 339912d852ee9ca6fff4d9b2c0d03602ce96803e [file] [log] [blame]
Carmelo Cascone75a9a892019-04-22 12:12:23 -07001/*
2 * Copyright 2019-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.net.pi.service;
18
19import org.onosproject.event.AbstractEvent;
20import org.onosproject.net.pi.model.PiPipeconf;
21import org.onosproject.net.pi.model.PiPipeconfId;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Event related to the PiPipeconfService.
27 */
28public class PiPipeconfEvent extends AbstractEvent<PiPipeconfEvent.Type, PiPipeconfId> {
29
30 private final PiPipeconf pipeconf;
31
32 /**
33 * Type of pipeconf event.
34 */
35 public enum Type {
36 REGISTERED,
37 UNREGISTERED
38 }
39
40 /**
41 * Creates anew pipeconf event for the given type and pipeconf.
42 *
43 * @param type type of event
44 * @param pipeconf pipeconf
45 */
46 public PiPipeconfEvent(Type type, PiPipeconf pipeconf) {
47 super(type, checkNotNull(pipeconf).id());
48 this.pipeconf = pipeconf;
49 }
50
51
52 /**
53 * Creates anew pipeconf event for the given type and pipeconf ID.
54 *
55 * @param type type of event
56 * @param pipeconfId pipeconf ID
57 */
58 public PiPipeconfEvent(Type type, PiPipeconfId pipeconfId) {
59 super(type, pipeconfId);
60 pipeconf = null;
61 }
62
63 /**
64 * Returns the pipeconf instance associated to this event, or null if one
65 * was not provided. For example, {@link Type#UNREGISTERED} events are not
66 * expected to carry the pipeconf instance that was unregistered, but just
67 * the ID (via {@link #subject()}).
68 *
69 * @return pipeconf instance or null
70 */
71 public PiPipeconf pipeconf() {
72 return pipeconf;
73 }
74}