blob: e2e9e86368176652e7bc45ee26deddb115abe771 [file] [log] [blame]
YuanyouZhangebe12612015-08-05 18:19:09 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
YuanyouZhangebe12612015-08-05 18:19:09 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ovsdb.controller.impl;
17
18import io.netty.buffer.ByteBuf;
19import io.netty.channel.ChannelHandlerContext;
20import io.netty.handler.codec.ByteToMessageDecoder;
21
22import java.util.List;
23
24import org.onosproject.ovsdb.rfc.jsonrpc.JsonReadContext;
25import org.onosproject.ovsdb.rfc.utils.JsonRpcReaderUtil;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29/**
30 * Decoder for inbound messages.
31 */
32public class MessageDecoder extends ByteToMessageDecoder {
33
34 private final Logger log = LoggerFactory.getLogger(MessageDecoder.class);
35 private final JsonReadContext context = new JsonReadContext();
36
37 /**
38 * Default constructor.
39 */
40 public MessageDecoder() {
41 }
42
43 @Override
44 protected void decode(ChannelHandlerContext ctx, ByteBuf buf,
45 List<Object> out) throws Exception {
46 log.debug("Message decoder");
47 JsonRpcReaderUtil.readToJsonNode(buf, out, context);
48 }
49
50 @Override
51 public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
52 log.error("Exception inside channel handling pipeline.", cause);
53 context.close();
54 }
55}