fix for BUG-947 - ErrorHandler classLoader issue 25/6725/4
authorMichal Rehak <mirehak@cisco.com>
Mon, 5 May 2014 15:05:20 +0000 (17:05 +0200)
committermichal rehak <mirehak@cisco.com>
Tue, 13 May 2014 07:12:42 +0000 (07:12 +0000)
- exception must be logged in the same thread as there is thread classLoader context, which might differ from the previously dedicated thread for exception logging

Change-Id: Ia2f911fdd5845280575fcb6a57c16aafdc0c2b53
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandler.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerQueueImpl.java [deleted file]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerSimpleImpl.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java

index bce5f2e8268ba84904f44b81c11865d961995b95..d31372a9efff59cb452da9dcef4e169d2b4835b9 100644 (file)
@@ -13,7 +13,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
  * @author mirehak
  *
  */
-public interface ErrorHandler extends Runnable, AutoCloseable {
+public interface ErrorHandler {
 
     /**
      * @param e cause
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerQueueImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerQueueImpl.java
deleted file mode 100644 (file)
index 42a8c67..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Copyright (c) 2013 Cisco Systems, 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
- */
-
-package org.opendaylight.openflowplugin.openflow.md.core;
-
-import java.util.Arrays;
-import java.util.concurrent.LinkedBlockingQueue;
-
-import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * dumping all exceptions to log
- * @author mirehak
- */
-public class ErrorHandlerQueueImpl implements ErrorHandler {
-
-    private static final Logger LOG = LoggerFactory
-            .getLogger(ErrorHandlerQueueImpl.class);
-
-    private LinkedBlockingQueue<Exception> errorQueue;
-
-    /**
-     * default ctor
-     */
-    public ErrorHandlerQueueImpl() {
-        this.errorQueue = new LinkedBlockingQueue<>();
-    }
-
-    @Override
-    public void run() {
-        while (true) {
-            Exception error;
-            try {
-                error = errorQueue.take();
-                if (error instanceof QueueShutdownItem) {
-                    break;
-                }
-                Throwable cause = error.getCause();
-                LOG.error(error.getMessage()+" -> "+cause.getMessage(), cause);
-            } catch (InterruptedException e) {
-                LOG.warn(e.getMessage());
-            }
-        }
-    }
-    
-    @Override
-    public void handleException(Throwable e, SessionContext sessionContext) {
-        String sessionKeyId = null;
-        if (sessionContext != null) {
-            sessionKeyId = Arrays.toString(sessionContext.getSessionKey().getId());
-        }
-        
-        Exception causeAndThread = new Exception(
-                "IN THREAD: "+Thread.currentThread().getName() +
-                "; session:"+sessionKeyId, e);
-        try {
-            errorQueue.put(causeAndThread);
-        } catch (InterruptedException e1) {
-            LOG.error(e1.getMessage(), e1);
-        }
-    }
-
-    @Override
-    public void close() {
-        // add special exception to queue and recognize it in run method
-        errorQueue.add(new QueueShutdownItem());
-    }
-    
-    static class QueueShutdownItem extends Exception {
-        private static final long serialVersionUID = 1L;
-        // nothing
-    }
-}
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerSimpleImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ErrorHandlerSimpleImpl.java
new file mode 100644 (file)
index 0000000..f9156eb
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, 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
+ */
+
+package org.opendaylight.openflowplugin.openflow.md.core;
+
+import java.util.Arrays;
+
+import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * dumping all exceptions to log
+ * @author mirehak
+ */
+public class ErrorHandlerSimpleImpl implements ErrorHandler {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(ErrorHandlerSimpleImpl.class);
+
+    @Override
+    public void handleException(Throwable e, SessionContext sessionContext) {
+        String sessionKeyId = null;
+        if (sessionContext != null) {
+            sessionKeyId = Arrays.toString(sessionContext.getSessionKey().getId());
+        }
+        
+        LOG.error("exception -> {}, session -> {}", e.getMessage(), sessionKeyId, e);
+    }
+}
index acd3814e7f192c9b1cb479794ae8fea1ff8bd6b8..5e0a6a923bfcffd117a4240b69337197d2b0996f 100644 (file)
@@ -107,7 +107,7 @@ public class MDController implements IMDController, AutoCloseable {
     final private int OF10 = OFConstants.OFP_VERSION_1_0;
     final private int OF13 = OFConstants.OFP_VERSION_1_3;
 
-    private ErrorHandlerQueueImpl errorHandler;
+    private ErrorHandlerSimpleImpl errorHandler;
     private ExecutorService rpcPool;
 
 
@@ -226,8 +226,7 @@ public class MDController implements IMDController, AutoCloseable {
         SwitchConnectionHandlerImpl switchConnectionHandler = new SwitchConnectionHandlerImpl();
         switchConnectionHandler.setMessageSpy(messageSpyCounter);
 
-        errorHandler = new ErrorHandlerQueueImpl();
-        new Thread(errorHandler).start();
+        errorHandler = new ErrorHandlerSimpleImpl();
         
         switchConnectionHandler.setErrorHandler(errorHandler);
         switchConnectionHandler.init();
@@ -351,6 +350,6 @@ public class MDController implements IMDController, AutoCloseable {
         }
         switchConnectionProviders = null;
         OFSessionUtil.releaseSessionManager();
-        errorHandler.close();
+        errorHandler = null;
     }
 }
index d06cbc0b5929d49403e9768734351a5213e43fae..73d5740a26e99f42a8d3dae1027f7508081a1559 100644 (file)
@@ -50,13 +50,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -92,7 +90,7 @@ public class ConnectionConductorImplTest {
     private int errorMessageCounter;
 
     @Mock
-    private ErrorHandlerQueueImpl errorHandler;
+    private ErrorHandlerSimpleImpl errorHandler;
 
     private int expectedErrors = 0;
 
@@ -139,7 +137,6 @@ public class ConnectionConductorImplTest {
         connectionConductor = new ConnectionConductorImpl(adapter);
         connectionConductor.setQueueKeeper(queueKeeper);
         connectionConductor.init();
-        pool.execute(errorHandler);
         connectionConductor.setErrorHandler(errorHandler);
         controller = new MDController();
         controller.init();