BUG 2854 : Do not add empty read write transactions to the replicable journal
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / rpc / impl / MountPointRpcExecutor.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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.controller.sal.restconf.rpc.impl;
9
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.concurrent.Future;
13 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
14 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
15 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19
20 /**
21  * Provides an implementation which invokes rpc methods via a mounted yang data model.
22  *
23  * @author Devin Avery
24  *
25  */
26 public class MountPointRpcExecutor extends AbstractRpcExecutor {
27     private final DOMMountPoint mountPoint;
28
29     public MountPointRpcExecutor(RpcDefinition rpcDef, DOMMountPoint mountPoint) {
30         super(rpcDef);
31         this.mountPoint = mountPoint;
32         Preconditions.checkNotNull(mountPoint, "MountInstance can not be null.");
33     }
34
35     @Override
36     protected Future<RpcResult<CompositeNode>> invokeRpcUnchecked(CompositeNode rpcRequest) {
37         Optional<RpcProvisionRegistry> service = mountPoint.getService(RpcProvisionRegistry.class);
38         if (service.isPresent()) {
39             return service.get().invokeRpc(getRpcDefinition().getQName(), rpcRequest);
40         }
41         throw new RestconfDocumentedException("Rpc service is missing.");
42     }
43 }