Separate out notification handling
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / invoke / RpcMethodInvokerWithoutInput.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.mdsal.binding.dom.adapter.invoke;
9
10 import com.google.common.base.Throwables;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.lang.invoke.MethodHandle;
13 import java.lang.invoke.MethodType;
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 RpcMethodInvokerWithoutInput extends RpcMethodInvoker {
19
20     private static final MethodType INVOCATION_SIGNATURE = MethodType.methodType(ListenableFuture.class,
21         RpcService.class);
22     private final MethodHandle handle;
23
24     RpcMethodInvokerWithoutInput(final MethodHandle methodHandle) {
25         this.handle = methodHandle.asType(INVOCATION_SIGNATURE);
26     }
27
28     @Override
29     @SuppressWarnings("checkstyle:illegalCatch")
30     ListenableFuture<RpcResult<?>> invokeOn(final RpcService impl, final DataObject input) {
31         try {
32             return (ListenableFuture<RpcResult<?>>) handle.invokeExact(impl);
33         } catch (Throwable e) {
34             Throwables.throwIfUnchecked(e);
35             throw new IllegalStateException(e);
36         }
37     }
38 }