blob: 9213a6d30a25daa4fd97dad422eb31a27fd4aa23 [file] [log] [blame]
Shravan Ambatibb6b4452016-05-04 13:25:28 -07001/**
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Shravan Ambatibb6b4452016-05-04 13:25:28 -07003 * 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;
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070019import org.onosproject.kafkaintegration.api.KafkaPublisherService;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070020import org.onosproject.kafkaintegration.api.dto.OnosEvent;
21import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
Yuta HIGUCHI9efba1e2016-07-09 11:07:13 -070025import com.google.protobuf.GeneratedMessageV3;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070026
27/**
28 * Dispatch ONOS Events to all interested Listeners.
29 *
30 */
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070031
32public final class KafkaPublisherManager
33 extends AbstractListenerManager<OnosEvent, ExportableEventListener> implements KafkaPublisherService {
Shravan Ambatibb6b4452016-05-04 13:25:28 -070034
35 private final Logger log = LoggerFactory.getLogger(getClass());
36
37 // Exists to defeat instantiation
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070038 private KafkaPublisherManager() {
Shravan Ambatibb6b4452016-05-04 13:25:28 -070039 }
40
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070041 //TODO: If possible, get rid of Singleton implementation.
Shravan Ambatibb6b4452016-05-04 13:25:28 -070042 private static class SingletonHolder {
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070043 private static final KafkaPublisherManager INSTANCE = new KafkaPublisherManager();
Shravan Ambatibb6b4452016-05-04 13:25:28 -070044 }
45
46 /**
47 * Returns a static reference to the Listener Factory.
48 *
49 * @return singleton object
50 */
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070051 public static KafkaPublisherManager getInstance() {
Shravan Ambatibb6b4452016-05-04 13:25:28 -070052 return SingletonHolder.INSTANCE;
53 }
54
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070055 @Override
Yuta HIGUCHI9efba1e2016-07-09 11:07:13 -070056 public void publish(Type eventType, GeneratedMessageV3 message) {
Shravan Ambatibb6b4452016-05-04 13:25:28 -070057 log.debug("Dispatching ONOS Event {}", eventType);
58 post(new OnosEvent(eventType, message));
59 }
60}