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
10 package org.opendaylight.ovsdb.lib.jsonrpc;
\r
12 import com.fasterxml.jackson.databind.JsonNode;
\r
13 import com.google.common.base.Strings;
\r
14 import com.google.common.collect.Maps;
\r
15 import com.google.common.util.concurrent.SettableFuture;
\r
17 import io.netty.channel.ChannelHandlerContext;
\r
18 import io.netty.channel.ChannelInboundHandlerAdapter;
\r
20 import org.opendaylight.controller.sal.core.Node;
\r
21 import org.slf4j.Logger;
\r
22 import org.slf4j.LoggerFactory;
\r
24 import java.util.Map;
\r
26 public class JsonRpcServiceBinderHandler extends ChannelInboundHandlerAdapter {
\r
27 protected static final Logger logger = LoggerFactory.getLogger(JsonRpcServiceBinderHandler.class);
\r
28 Map<Object, SettableFuture<Object>> waitingForReply = Maps.newHashMap();
\r
29 JsonRpcEndpoint factory = null;
\r
32 public Node getNode() {
\r
36 public void setNode(Node node) {
\r
40 public JsonRpcServiceBinderHandler(JsonRpcEndpoint factory) {
\r
41 this.factory = factory;
\r
45 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
\r
47 if (msg instanceof JsonNode) {
\r
48 JsonNode jsonNode = (JsonNode) msg;
\r
50 if (jsonNode.has("result")) {
\r
51 factory.processResult(jsonNode);
\r
52 } else if (jsonNode.hasNonNull("method")) {
\r
53 if (jsonNode.has("id") && !Strings.isNullOrEmpty(jsonNode.get("id").asText())) {
\r
54 factory.processRequest(node, jsonNode);
\r
61 ctx.channel().close();
\r
65 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
\r