Updating fix for bug 3989 based on discussion in OVSDB meeting
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / jsonrpc / ExceptionHandler.java
1 /*
2  * Copyright (c) 2013, 2015 EBay Software Foundation 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.ovsdb.lib.jsonrpc;
10
11 import io.netty.channel.ChannelHandlerAdapter;
12 import io.netty.channel.ChannelHandlerContext;
13 import io.netty.handler.codec.TooLongFrameException;
14 import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
15
16 import java.io.IOException;
17
18 public class ExceptionHandler extends ChannelHandlerAdapter {
19
20     @Override
21     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
22         if ((cause instanceof InvalidEncodingException)
23                 || (cause instanceof TooLongFrameException)) {
24             ctx.channel().disconnect();
25         }
26         /* In cases where a connection is quickly established and the closed
27         Catch the IOException and close the channel
28          */
29         if (cause instanceof IOException) {
30             ctx.channel().close();
31         }
32     }
33 }