Made changes as per comments.
kafkaProducer is now non-static.
TODO: KafkaPublisherManager Service and not Singleton.
Kafka event publishing.
Change-Id: I5ec20a6e4950c38e822468d343521ab77475b7d3
diff --git a/apps/kafka-integration/core/src/main/java/org/onosproject/kafkaintegration/impl/KafkaPublisherManager.java b/apps/kafka-integration/core/src/main/java/org/onosproject/kafkaintegration/impl/KafkaPublisherManager.java
new file mode 100644
index 0000000..104619a
--- /dev/null
+++ b/apps/kafka-integration/core/src/main/java/org/onosproject/kafkaintegration/impl/KafkaPublisherManager.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2016 Open Networking Laboratory
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kafkaintegration.impl;
+
+import org.onosproject.event.AbstractListenerManager;
+import org.onosproject.kafkaintegration.api.ExportableEventListener;
+import org.onosproject.kafkaintegration.api.KafkaPublisherService;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.protobuf.GeneratedMessage;
+
+/**
+ * Dispatch ONOS Events to all interested Listeners.
+ *
+ */
+
+public final class KafkaPublisherManager
+ extends AbstractListenerManager<OnosEvent, ExportableEventListener> implements KafkaPublisherService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ // Exists to defeat instantiation
+ private KafkaPublisherManager() {
+ }
+
+ //TODO: If possible, get rid of Singleton implementation.
+ private static class SingletonHolder {
+ private static final KafkaPublisherManager INSTANCE = new KafkaPublisherManager();
+ }
+
+ /**
+ * Returns a static reference to the Listener Factory.
+ *
+ * @return singleton object
+ */
+ public static KafkaPublisherManager getInstance() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ @Override
+ public void publish(Type eventType, GeneratedMessage message) {
+ log.debug("Dispatching ONOS Event {}", eventType);
+ post(new OnosEvent(eventType, message));
+ }
+}