2 * Copyright (C) 2013 EBay Software Foundation
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
8 * Authors : Ashwin Raveendran, Madhu Venugopal, Thomas Bachman
10 package org.opendaylight.groupbasedpolicy.renderer.opflex.jsonrpc;
12 import com.fasterxml.jackson.databind.JsonNode;
14 import io.netty.channel.ChannelHandlerContext;
15 import io.netty.channel.ChannelInboundHandlerAdapter;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class JsonRpcServiceBinderHandler extends ChannelInboundHandlerAdapter {
21 protected static final Logger logger = LoggerFactory.getLogger(JsonRpcServiceBinderHandler.class);
22 JsonRpcEndpoint endpoint = null;
24 public JsonRpcServiceBinderHandler(JsonRpcEndpoint endpoint) {
25 this.endpoint = endpoint;
28 // Setter to facilitate unit testing
29 public void setEndpoint(JsonRpcEndpoint endpoint) {
30 this.endpoint = endpoint;
34 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
36 if (msg instanceof JsonNode) {
37 JsonNode jsonNode = (JsonNode) msg;
39 if (jsonNode.has("result")) {
40 endpoint.processResult(jsonNode);
41 } else if (jsonNode.hasNonNull("method")) {
42 if (jsonNode.has("id") && (jsonNode.get("id") != null)) {
43 endpoint.processRequest(jsonNode);
50 ctx.channel().close();
54 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {