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/api/src/main/java/org/onosproject/kafkaintegration/api/EventConversionService.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventConversionService.java
new file mode 100644
index 0000000..4c73d96
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventConversionService.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2016-present 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.api;
+
+import org.onosproject.event.Event;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent;
+
+/**
+ * API for conversion of various ONOS events to Protobuf.
+ *
+ */
+public interface EventConversionService {
+ OnosEvent convertEvent(Event<?, ?> event);
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventSubscriptionService.java
similarity index 85%
rename from apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java
rename to apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventSubscriptionService.java
index e203697..07b03de 100644
--- a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventExporterService.java
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/EventSubscriptionService.java
@@ -16,16 +16,19 @@
import org.onosproject.kafkaintegration.api.dto.EventSubscriber;
import org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
import org.onosproject.kafkaintegration.errors.InvalidApplicationException;
import org.onosproject.kafkaintegration.errors.InvalidGroupIdException;
import com.google.common.annotations.Beta;
+import java.util.List;
+
/**
* APIs for subscribing to Onos Event Messages.
*/
@Beta
-public interface EventExporterService {
+public interface EventSubscriptionService {
/**
* Registers the external application to receive events generated in ONOS.
@@ -61,4 +64,12 @@
*/
void unsubscribe(EventSubscriber subscriber)
throws InvalidGroupIdException, InvalidApplicationException;
+
+ /**
+ * Returns the event subscriber for various event types.
+ *
+ * @param type ONOS event type.
+ * @return List of event subscribers
+ */
+ List<EventSubscriber> getEventSubscribers(Type type);
}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/KafkaPublisherService.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/KafkaPublisherService.java
new file mode 100644
index 0000000..b92b890
--- /dev/null
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/KafkaPublisherService.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2016-present 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.api;
+
+import com.google.protobuf.GeneratedMessage;
+import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
+
+/**
+ * API for dispatching ONOS events.
+ */
+public interface KafkaPublisherService {
+
+ /**
+ * Publish the ONOS Event to all listeners.
+ *
+ * @param eventType the ONOS eventtype
+ * @param message generated Protocol buffer message from ONOS event data
+ */
+ void publish(Type eventType, GeneratedMessage message);
+}
diff --git a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java
index ff1d27e..2d51c7c 100644
--- a/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java
+++ b/apps/kafka-integration/api/src/main/java/org/onosproject/kafkaintegration/api/dto/OnosEvent.java
@@ -19,7 +19,7 @@
import com.google.protobuf.GeneratedMessage;
/**
- * Represents the converted Onos Event data into GPB format.
+ * Represents the converted Onos Event data into protobuf format.
*
*/
public class OnosEvent extends AbstractEvent<OnosEvent.Type, GeneratedMessage> {
@@ -38,6 +38,19 @@
* List of Event Types supported.
*/
public enum Type {
- DEVICE, LINK;
+ /**
+ * Signifies Device events.
+ */
+ DEVICE("DEVICE"),
+
+ /**
+ * Signifies Link events.
+ */
+ LINK("LINK");
+ public String typeName;
+
+ Type(String name) {
+ typeName = name;
+ }
}
}