Make mdsal datastore persist through different sessions
[netconf.git] / opendaylight / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / TesttoolNegotiationFactory.java
1 /*
2  * Copyright (c) 2015 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;
10
11 import io.netty.util.Timer;
12 import java.net.SocketAddress;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Set;
16 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
17 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
18 import org.opendaylight.netconf.impl.SessionIdProvider;
19 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
20 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
21
22 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
23
24     private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
25
26     public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
27                                       final SessionIdProvider idProvider, final long connectionTimeoutMillis,
28                                       final NetconfMonitoringService monitoringService) {
29         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService);
30     }
31
32     public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
33                                       final SessionIdProvider idProvider, final long connectionTimeoutMillis,
34                                       final NetconfMonitoringService monitoringService, final Set<String> baseCapabilities) {
35         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, baseCapabilities);
36     }
37
38     @Override
39     protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
40         if (cachedOperationServices.containsKey(socketAddress)) {
41             return cachedOperationServices.get(socketAddress);
42         } else {
43             final NetconfOperationService service = getOperationServiceFactory().createService(netconfSessionIdForReporting);
44             cachedOperationServices.put(socketAddress, service);
45             return service;
46         }
47     }
48 }