a77dd35b9ea1c8a4d6239178eae5d7c2f5b04e26
[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 = MethodType.methodType(Future.class, RpcService.class,DataObject.class);
21     private final MethodHandle handle;
22
23     RpcMethodInvokerWithInput(MethodHandle methodHandle) {
24         this.handle = methodHandle.asType(INVOCATION_SIGNATURE);
25     }
26
27     @Override
28     public Future<RpcResult<?>> invokeOn(RpcService impl, DataObject input) {
29         try {
30             return (Future<RpcResult<?>>) handle.invokeExact(impl,input);
31         } catch (Throwable e) {
32             throw Throwables.propagate(e);
33         }
34     }
35
36 }