org.opendaylight.jsonrpc.binding.OutboundHandler Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2018 Lumina Networks, Inc. All rights reserved.
*
* 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
*/
package org.opendaylight.jsonrpc.binding;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.gson.JsonElement;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import org.opendaylight.jsonrpc.bus.jsonrpc.JsonRpcReplyMessage;
import org.opendaylight.jsonrpc.bus.messagelib.RequesterSession;
import org.opendaylight.yangtools.binding.DataContainer;
import org.opendaylight.yangtools.binding.DataObject;
import org.opendaylight.yangtools.binding.Rpc;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Handler that intercept local method invocation and make RPC call to remote responder.
*
* @author Richard Kosegi
* @since Sep 20, 2018
*/
public class OutboundHandler> extends AbstractHandler {
private static final Logger LOG = LoggerFactory.getLogger(OutboundHandler.class);
private final RequesterSession session;
public OutboundHandler(Class type, RpcInvocationAdapter adapter, RequesterSession session) {
super(type, adapter);
this.session = session;
}
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressFBWarnings("DCN_NULLPOINTER_EXCEPTION")
@Override
Object doHandleInvocation(Object proxy, Method method, Object[] args) {
try {
return handleInvocationInternal(method, args);
} catch (NullPointerException | IllegalArgumentException e) {
return Futures.immediateFuture(
RpcResultBuilder.