Introduce NetconfTimer
[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 package org.opendaylight.netconf.test.tool;
9
10 import java.net.SocketAddress;
11 import java.util.Set;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import org.opendaylight.netconf.common.NetconfTimer;
15 import org.opendaylight.netconf.server.NetconfServerSessionNegotiatorFactory;
16 import org.opendaylight.netconf.server.api.SessionIdProvider;
17 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
18 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
19 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
25     private static final Logger LOG = LoggerFactory.getLogger(TesttoolNegotiationFactory.class);
26
27     private final ConcurrentMap<SocketAddress, NetconfOperationService> operationServices = new ConcurrentHashMap<>();
28
29     public TesttoolNegotiationFactory(final NetconfTimer timer,
30             final NetconfOperationServiceFactory netconfOperationProvider, final SessionIdProvider idProvider,
31             final long connectionTimeoutMillis, final NetconfMonitoringService monitoringService) {
32         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService,
33             NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
34     }
35
36     public TesttoolNegotiationFactory(final NetconfTimer timer,
37             final NetconfOperationServiceFactory netconfOperationProvider, final SessionIdProvider idProvider,
38             final long connectionTimeoutMillis, final NetconfMonitoringService monitoringService,
39             final Set<String> baseCapabilities) {
40         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis,
41             monitoringService, baseCapabilities);
42     }
43
44     @Override
45     protected NetconfOperationService getOperationServiceForAddress(final SessionIdType sessionId,
46             final SocketAddress socketAddress) {
47         return operationServices.computeIfAbsent(socketAddress, addr -> {
48             LOG.debug("Session {}: Creating new operation service factory for test tool device on address {}",
49                 sessionId.getValue(), addr);
50             return getOperationServiceFactory().createService(sessionId);
51         });
52     }
53 }