NetConf test tool improved so now it can be
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / rpchandler / SettableOperationRpcProvider.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.netconf.test.tool.rpchandler;
10
11 import java.util.Collections;
12 import java.util.Set;
13 import org.opendaylight.controller.config.util.capability.Capability;
14 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
15 import org.opendaylight.netconf.mapping.api.NetconfOperation;
16 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
17 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
18
19 public class SettableOperationRpcProvider implements NetconfOperationServiceFactory {
20
21     private final RpcHandler rpcHandler;
22
23     public SettableOperationRpcProvider(RpcHandler rpcHandler) {
24         this.rpcHandler = rpcHandler;
25     }
26
27     @Override
28     public Set<Capability> getCapabilities() {
29         return Collections.emptySet();
30     }
31
32     @Override
33     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
34         return () -> {
35             //no op
36         };
37     }
38
39     @Override
40     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
41         return new SettableOperationService(rpcHandler);
42     }
43
44     private static class SettableOperationService implements NetconfOperationService {
45
46         private final SettableRpc rpc;
47
48         private SettableOperationService(RpcHandler rpcHandler) {
49             this.rpc = new SettableRpc(rpcHandler);
50         }
51
52         @Override
53         public Set<NetconfOperation> getNetconfOperations() {
54             return Collections.singleton(rpc);
55         }
56
57         @Override
58         public void close() {
59             // no op
60         }
61     }
62 }