2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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 package org.opendaylight.mdsal.binding.dom.adapter.invoke;
10 import com.google.common.annotations.VisibleForTesting;
11 import com.google.common.base.Throwables;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.lang.invoke.MethodHandle;
14 import java.lang.invoke.MethodHandles;
15 import java.lang.invoke.MethodType;
16 import java.lang.reflect.Method;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.RpcService;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
22 @Deprecated(since = "11.0.0", forRemoval = true)
23 public final class RpcMethodInvoker {
24 private static final MethodType INVOCATION_SIGNATURE = MethodType.methodType(ListenableFuture.class,
25 RpcService.class, DataObject.class);
27 private final MethodHandle handle;
30 RpcMethodInvoker(final MethodHandle handle) {
31 this.handle = handle.asType(INVOCATION_SIGNATURE);
34 public static @NonNull RpcMethodInvoker from(final Method method) {
36 return new RpcMethodInvoker(MethodHandles.publicLookup().unreflect(method));
37 } catch (IllegalAccessException e) {
38 throw new IllegalStateException("Lookup on public method failed.", e);
42 @SuppressWarnings("checkstyle:illegalCatch")
43 public @NonNull ListenableFuture<RpcResult<?>> invokeOn(final RpcService impl, final DataObject input) {
45 return (ListenableFuture<RpcResult<?>>) handle.invokeExact(impl, input);
46 } catch (Throwable e) {
47 Throwables.throwIfUnchecked(e);
48 throw new IllegalStateException(e);