Merge "Remove unused isMaster variable in ClusteredNetconfDevice"
[netconf.git] / 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.NetconfServerSessionNegotiatorFactoryBuilder;
19 import org.opendaylight.netconf.impl.SessionIdProvider;
20 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
21 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
26     private static final Logger LOG = LoggerFactory.getLogger(TesttoolNegotiationFactory.class);
27
28     private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
29
30     public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
31                                       final SessionIdProvider idProvider, final long connectionTimeoutMillis,
32                                       final NetconfMonitoringService monitoringService) {
33         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
34     }
35
36     public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
37                                       final SessionIdProvider idProvider, final long connectionTimeoutMillis,
38                                       final NetconfMonitoringService monitoringService, final Set<String> baseCapabilities) {
39         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, baseCapabilities);
40     }
41
42     @Override
43     protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
44         if (cachedOperationServices.containsKey(socketAddress)) {
45             LOG.debug("Session {}: Getting cached operation service factory for test tool device on address {}",
46                     netconfSessionIdForReporting, socketAddress);
47             return cachedOperationServices.get(socketAddress);
48         } else {
49             final NetconfOperationService service = getOperationServiceFactory().createService(netconfSessionIdForReporting);
50             cachedOperationServices.put(socketAddress, service);
51             LOG.debug("Session {}: Creating new operation service factory for test tool device on address {}",
52                     netconfSessionIdForReporting, socketAddress);
53             return service;
54         }
55     }
56 }