Bug 6163: fixed number of argument when resolving rpc input
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / util / RpcMethodInvokerWithInput.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.binding.util;
9
10 import com.google.common.base.Throwables;
11 import java.lang.invoke.MethodHandle;
12 import java.lang.invoke.MethodType;
13 import java.util.concurrent.Future;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17
18 class RpcMethodInvokerWithInput extends RpcMethodInvoker {
19
20     private static final MethodType INVOCATION_SIGNATURE =
21             MethodType.methodType(Future.class, RpcService.class, DataObject.class);
22     private final MethodHandle handle;
23
24     RpcMethodInvokerWithInput(MethodHandle methodHandle) {
25         this.handle = methodHandle.asType(INVOCATION_SIGNATURE);
26     }
27
28     @Override
29     public Future<RpcResult<?>> invokeOn(RpcService impl, DataObject input) {
30         try {
31             return (Future<RpcResult<?>>) handle.invokeExact(impl,input);
32         } catch (Throwable e) {
33             throw Throwables.propagate(e);
34         }
35     }
36
37 }