l3 support (partial): move event dispatch from southBoundHandler
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractHandler.java
index 791c9f026740a0aebcc3656b810248be1a20708f..36969bb9dc23b473a5b1d75e5d1a095325e9a6cc 100644 (file)
@@ -11,14 +11,18 @@ 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 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,9 @@ 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;
+
     /**
      * Convert failure status returned by the  manager into
      * neutron API service errors.
@@ -57,4 +64,24 @@ public abstract class AbstractHandler {
 
         return result;
     }
+
+    /**
+     * Enqueue the event.
+     *
+     * @param event 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 event 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);
+
 }