Squashed commit of the following:
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractHandler.java
index 791c9f026740a0aebcc3656b810248be1a20708f..b9c5e5436934be8c293b0c913de7e8c3bc19559d 100644 (file)
@@ -9,16 +9,20 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt;
 
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
+import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
 
+import com.google.common.base.Preconditions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.net.HttpURLConnection;
 
 /**
- * Abstract class for utility functions used by neutron handlers.
+ * OpenStack related events originate from multiple north callbacks as well as south.
+ * This interface provides a layer of abstraction between the event dispatcher and the
+ * handlers.
  */
 public abstract class AbstractHandler {
 
@@ -27,6 +31,13 @@ public abstract class AbstractHandler {
      */
     static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
 
+    // The implementation for each of these services is resolved by the OSGi Service Manager
+    private volatile EventDispatcher eventDispatcher;
+
+    void init() {
+        logger.info(">>>>> init {}", this.getClass());
+    }
+
     /**
      * Convert failure status returned by the  manager into
      * neutron API service errors.
@@ -57,4 +68,24 @@ public abstract class AbstractHandler {
 
         return result;
     }
+
+    /**
+     * Enqueue the event.
+     *
+     * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+     * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
+     */
+    protected void enqueueEvent(AbstractEvent abstractEvent) {
+        Preconditions.checkNotNull(eventDispatcher);
+        eventDispatcher.enqueueEvent(abstractEvent);
+    }
+
+    /**
+     * Process the event.
+     *
+     * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+     * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
+     */
+    public abstract void processEvent(AbstractEvent abstractEvent);
+
 }