f4cad4e3627b27f9c1acec7f3ea2b70b450cacbc
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / ErrorHandlerSimpleImpl.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.openflow.md.core;
10
11 import java.util.Arrays;
12
13 import org.opendaylight.openflowplugin.ConnectionException;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.ErrorHandler;
15 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * dumping all exceptions to log
21  * @author mirehak
22  */
23 public class ErrorHandlerSimpleImpl implements ErrorHandler {
24
25     private static final Logger LOG = LoggerFactory
26             .getLogger(ErrorHandlerSimpleImpl.class);
27
28     @Override
29     public void handleException(Throwable e, SessionContext sessionContext) {
30         String sessionKeyId = null;
31         if (sessionContext != null) {
32             sessionKeyId = Arrays.toString(sessionContext.getSessionKey().getId());
33         }
34         
35         if (e instanceof ConnectionException) {
36             LOG.warn("exception -> {}, session -> {}", e.getMessage(), sessionKeyId, e);
37         } else {
38             LOG.error("exception -> {}, session -> {}", e.getMessage(), sessionKeyId, e);
39         }
40     }
41 }