Merge "Bug 4736 - Add null poiner check of getFixedIPs()"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractHandler.java
index 2283bc7b22659a12a24cda7934e63ef6d5576010..7566091e6193579e1ff9acdcd3a9a117df814abf 100644 (file)
@@ -1,17 +1,16 @@
 /*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Authors : Madhu Venugopal, Brent Salisbury
  */
+
 package org.opendaylight.ovsdb.openstack.netvirt;
 
-import org.opendaylight.ovsdb.plugin.api.Status;
-import org.opendaylight.ovsdb.plugin.api.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;
@@ -25,14 +24,10 @@ import java.net.HttpURLConnection;
  * handlers.
  */
 public abstract class AbstractHandler {
-
-    /**
-     * Logger instance.
-     */
-    static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractHandler.class);
 
     // The implementation for each of these services is resolved by the OSGi Service Manager
-    private volatile EventDispatcher eventDispatcher;
+    protected volatile EventDispatcher eventDispatcher;
 
     /**
      * Convert failure status returned by the  manager into
@@ -41,37 +36,35 @@ public abstract class AbstractHandler {
      * @param status  manager status
      * @return  An error to be returned to neutron API service.
      */
-    protected static final int getException(Status status) {
-        int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
-
+    protected static int getException(Status status) {
         assert !status.isSuccess();
 
         StatusCode code = status.getCode();
-        logger.debug(" Exception code - {}, description - {}",
+        LOG.debug(" Exception code - {}, description - {}",
                 code, status.getDescription());
 
-        if (code == StatusCode.BADREQUEST) {
-            result = HttpURLConnection.HTTP_BAD_REQUEST;
-        } else if (code == StatusCode.CONFLICT) {
-            result = HttpURLConnection.HTTP_CONFLICT;
-        } else if (code == StatusCode.NOTACCEPTABLE) {
-            result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
-        } else if (code == StatusCode.NOTFOUND) {
-            result = HttpURLConnection.HTTP_NOT_FOUND;
-        } else {
-            result = HttpURLConnection.HTTP_INTERNAL_ERROR;
+        switch(code) {
+            case BADREQUEST:
+                return HttpURLConnection.HTTP_BAD_REQUEST;
+            case CONFLICT:
+                return HttpURLConnection.HTTP_CONFLICT;
+            case NOTACCEPTABLE:
+                return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
+            case NOTFOUND:
+                return HttpURLConnection.HTTP_NOT_FOUND;
+            default:
+                return HttpURLConnection.HTTP_INTERNAL_ERROR;
         }
-
-        return result;
     }
 
     /**
      * Enqueue the event.
      *
-     * @param event the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+     * @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) {
+        LOG.info("enqueueEvent: evenDispatcher: {} - {}", eventDispatcher, abstractEvent);
         Preconditions.checkNotNull(eventDispatcher);
         eventDispatcher.enqueueEvent(abstractEvent);
     }
@@ -79,7 +72,7 @@ public abstract class AbstractHandler {
     /**
      * Process the event.
      *
-     * @param event the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+     * @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);