org.opendaylight.ovsdb.lib.jsonrpc.ExceptionHandler.java Source code

Java tutorial

Introduction

Here is the source code for org.opendaylight.ovsdb.lib.jsonrpc.ExceptionHandler.java

Source

/*
 * Copyright (C) 2013 EBay Software Foundation
 *
 * 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
 *
 * Authors : Ashwin Raveendran
 */
package org.opendaylight.ovsdb.lib.jsonrpc;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.TooLongFrameException;
import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;

import java.io.IOException;

public class ExceptionHandler extends ChannelHandlerAdapter {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        if ((cause instanceof InvalidEncodingException) || (cause instanceof TooLongFrameException)) {
            ctx.channel().disconnect();
        }
        /* In cases where a connection is quickly established and the closed
        Catch the IOException and close the channel
         */
        if (cause instanceof IOException) {
            ctx.channel().close();
        }
    }
}