Search in sources :

Example 1 with RpcInput

use of org.opendaylight.yangtools.yang.binding.RpcInput in project mdsal by opendaylight.

the class ActionAdapter method invoke.

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws NoSuchMethodError {
    switch(method.getName()) {
        case "equals":
            if (args.length == 1) {
                return proxy == args[0];
            }
            break;
        case "hashCode":
            if (args.length == 0) {
                return System.identityHashCode(proxy);
            }
            break;
        case "toString":
            if (args.length == 0) {
                return spec.type().getName() + "$Adapter{delegate=" + getDelegate() + "}";
            }
            break;
        case "invoke":
            if (args.length == 2) {
                final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
                checkArgument(!path.isWildcarded(), "Cannot invoke action on wildcard path %s", path);
                final RpcInput input = (RpcInput) requireNonNull(args[1]);
                final CurrentAdapterSerializer serializer = currentSerializer();
                final ListenableFuture<? extends DOMActionResult> future = getDelegate().invokeAction(actionPath, new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, serializer.toYangInstanceIdentifier(path)), serializer.toLazyNormalizedNodeActionInput(spec.type(), inputName, input));
                // Invocation returned a future we know about -- return that future instead
                if (ENABLE_CODEC_SHORTCUT && future instanceof BindingRpcFutureAware) {
                    return ((BindingRpcFutureAware) future).getBindingFuture();
                }
                return Futures.transform(future, dom -> RpcResultUtil.rpcResultFromDOM(dom.getErrors(), dom.getOutput().map(output -> serializer.fromNormalizedNodeActionOutput(spec.type(), output)).orElse(null)), MoreExecutors.directExecutor());
            }
            break;
        default:
            break;
    }
    throw new NoSuchMethodError("Method " + method.toString() + "is unsupported.");
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangConstants.operationInputQName(org.opendaylight.yangtools.yang.common.YangConstants.operationInputQName) ActionSpec(org.opendaylight.mdsal.binding.api.ActionSpec) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Objects.requireNonNull(java.util.Objects.requireNonNull) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InvocationHandler(java.lang.reflect.InvocationHandler) RpcInput(org.opendaylight.yangtools.yang.binding.RpcInput) ENABLE_CODEC_SHORTCUT(org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT) Method(java.lang.reflect.Method) NonNull(org.eclipse.jdt.annotation.NonNull) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) RpcInput(org.opendaylight.yangtools.yang.binding.RpcInput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 ActionSpec (org.opendaylight.mdsal.binding.api.ActionSpec)1 ENABLE_CODEC_SHORTCUT (org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT)1 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)1 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)1 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1 RpcInput (org.opendaylight.yangtools.yang.binding.RpcInput)1 YangConstants.operationInputQName (org.opendaylight.yangtools.yang.common.YangConstants.operationInputQName)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)1