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;
12 import io.netty.channel.ChannelHandlerContext;
13 import io.netty.channel.ChannelInboundHandlerAdapter;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import com.fasterxml.jackson.databind.JsonNode;
21 import com.google.common.base.Strings;
22 import com.google.common.collect.Maps;
23 import com.google.common.util.concurrent.SettableFuture;
25 public class JsonRpcServiceBinderHandler extends ChannelInboundHandlerAdapter {
26 protected static final Logger logger = LoggerFactory.getLogger(JsonRpcServiceBinderHandler.class);
27 Map<Object, SettableFuture<Object>> waitingForReply = Maps.newHashMap();
28 JsonRpcEndpoint factory = null;
29 Object context = null;
31 public Object getContext() {
35 public void setContext(Object context) {
36 this.context = context;
39 public JsonRpcServiceBinderHandler(JsonRpcEndpoint factory) {
40 this.factory = factory;
44 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
46 if (msg instanceof JsonNode) {
47 JsonNode jsonNode = (JsonNode) msg;
49 if (jsonNode.has("result")) {
50 factory.processResult(jsonNode);
51 } else if (jsonNode.hasNonNull("method")) {
52 if (jsonNode.has("id") && !Strings.isNullOrEmpty(jsonNode.get("id").asText())) {
53 factory.processRequest(context, jsonNode);
60 ctx.channel().close();
64 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {