Add copyright headers to sal-rest-connector
[netconf.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / config / yang / config / netconf / northbound / impl / NetconfServerDispatcherModule.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.controller.config.yang.config.netconf.northbound.impl;
10
11 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
12 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
13 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
14 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
15 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
16 import org.opendaylight.netconf.impl.SessionIdProvider;
17 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
18
19 public class NetconfServerDispatcherModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerDispatcherModule {
20     public NetconfServerDispatcherModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
21         super(identifier, dependencyResolver);
22     }
23
24     public NetconfServerDispatcherModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfServerDispatcherModule oldModule, java.lang.AutoCloseable oldInstance) {
25         super(identifier, dependencyResolver, oldModule, oldInstance);
26     }
27
28     @Override
29     public void customValidation() {
30         JmxAttributeValidationException.checkCondition(getConnectionTimeoutMillis() > 0, "Invalid connection timeout", connectionTimeoutMillisJmxAttribute);
31     }
32
33     @Override
34     public java.lang.AutoCloseable createInstance() {
35
36         final AggregatedNetconfOperationServiceFactory aggregatedOpProvider = getAggregatedOpProvider();
37         final NetconfMonitoringService monitoringService = getServerMonitorDependency();
38         final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
39                 getTimerDependency(), aggregatedOpProvider, new SessionIdProvider(), getConnectionTimeoutMillis(), monitoringService);
40         final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer(
41                 serverNegotiatorFactory);
42
43         return new NetconfServerDispatcherImpl(serverChannelInitializer, getBossThreadGroupDependency(), getWorkerThreadGroupDependency()) {
44
45             @Override
46             public void close() {
47                 // NOOP, close should not be present here, the deprecated method closes injected evet loop groups
48             }
49         };
50
51     }
52
53     private AggregatedNetconfOperationServiceFactory getAggregatedOpProvider() {
54         final AggregatedNetconfOperationServiceFactory netconfOperationProvider = new AggregatedNetconfOperationServiceFactory();
55         for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getMappersDependency()) {
56             netconfOperationProvider.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
57         }
58         return netconfOperationProvider;
59     }
60
61
62 }