- 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>
* @author mirehak
*
*/
-public interface ErrorHandler extends Runnable, AutoCloseable {
+public interface ErrorHandler {
/**
* @param e cause
+++ /dev/null
-/**
- * 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
- }
-}
--- /dev/null
+/**
+ * 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);
+ }
+}
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;
SwitchConnectionHandlerImpl switchConnectionHandler = new SwitchConnectionHandlerImpl();
switchConnectionHandler.setMessageSpy(messageSpyCounter);
- errorHandler = new ErrorHandlerQueueImpl();
- new Thread(errorHandler).start();
+ errorHandler = new ErrorHandlerSimpleImpl();
switchConnectionHandler.setErrorHandler(errorHandler);
switchConnectionHandler.init();
}
switchConnectionProviders = null;
OFSessionUtil.releaseSessionManager();
- errorHandler.close();
+ errorHandler = null;
}
}
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;
private int errorMessageCounter;
@Mock
- private ErrorHandlerQueueImpl errorHandler;
+ private ErrorHandlerSimpleImpl errorHandler;
private int expectedErrors = 0;
connectionConductor = new ConnectionConductorImpl(adapter);
connectionConductor.setQueueKeeper(queueKeeper);
connectionConductor.init();
- pool.execute(errorHandler);
connectionConductor.setErrorHandler(errorHandler);
controller = new MDController();
controller.init();