blob: d211458dfedb21830245d49acc9c30304aa93573 [file] [log] [blame]
Shravan Ambatibb6b4452016-05-04 13:25:28 -07001/**
2 * Copyright 2016 Open Networking Laboratory
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6
7 * http://www.apache.org/licenses/LICENSE-2.0
8
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15package org.onosproject.kafkaintegration.impl;
16
17import org.onosproject.event.AbstractListenerManager;
18import org.onosproject.kafkaintegration.api.ExportableEventListener;
19import org.onosproject.kafkaintegration.api.dto.OnosEvent;
20import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import com.google.protobuf.GeneratedMessage;
25
26/**
27 * Dispatch ONOS Events to all interested Listeners.
28 *
29 */
30public final class Dispatcher
31 extends AbstractListenerManager<OnosEvent, ExportableEventListener> {
32
33 private final Logger log = LoggerFactory.getLogger(getClass());
34
35 // Exists to defeat instantiation
36 private Dispatcher() {
37 }
38
39 private static class SingletonHolder {
40 private static final Dispatcher INSTANCE = new Dispatcher();
41 }
42
43 /**
44 * Returns a static reference to the Listener Factory.
45 *
46 * @return singleton object
47 */
48 public static Dispatcher getInstance() {
49 return SingletonHolder.INSTANCE;
50 }
51
52 /**
53 * Publish the ONOS Event to all listeners.
54 *
55 * @param eventType the ONOS eventtype
56 * @param message generated Protocol buffer message from ONOS event data
57 */
58 public void publish(Type eventType, GeneratedMessage message) {
59 log.debug("Dispatching ONOS Event {}", eventType);
60 post(new OnosEvent(eventType, message));
61 }
62}