2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core;
11 import java.util.Arrays;
12 import java.util.concurrent.LinkedBlockingQueue;
14 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * dumping all exceptions to log
22 public class ErrorHandlerQueueImpl implements ErrorHandler {
24 private static final Logger LOG = LoggerFactory
25 .getLogger(ErrorHandlerQueueImpl.class);
27 private LinkedBlockingQueue<Exception> errorQueue;
32 public ErrorHandlerQueueImpl() {
33 this.errorQueue = new LinkedBlockingQueue<>();
41 error = errorQueue.take();
42 if (error instanceof QueueShutdownItem) {
45 Throwable cause = error.getCause();
46 LOG.error(error.getMessage()+" -> "+cause.getMessage(), cause);
47 } catch (InterruptedException e) {
48 LOG.warn(e.getMessage());
54 public void handleException(Throwable e, SessionContext sessionContext) {
55 String sessionKeyId = null;
56 if (sessionContext != null) {
57 sessionKeyId = Arrays.toString(sessionContext.getSessionKey().getId());
60 Exception causeAndThread = new Exception(
61 "IN THREAD: "+Thread.currentThread().getName() +
62 "; session:"+sessionKeyId, e);
64 errorQueue.put(causeAndThread);
65 } catch (InterruptedException e1) {
66 LOG.error(e1.getMessage(), e1);
72 // add special exception to queue and recognize it in run method
73 errorQueue.add(new QueueShutdownItem());
76 static class QueueShutdownItem extends Exception {
77 private static final long serialVersionUID = 1L;