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