422b81c5ae785defced9fb75a954404b09048c25
[transportpce.git] / tests / honeynode / 2.2.1 / netconf / src / main / java / io / fd / honeycomb / northbound / netconf / NetconfServerDispatcherProvider.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.northbound.netconf;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.binding.init.ProviderTrait;
22 import io.netty.channel.nio.NioEventLoopGroup;
23 import io.netty.util.Timer;
24 import java.util.concurrent.TimeUnit;
25 import org.opendaylight.netconf.api.NetconfServerDispatcher;
26 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
27 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
28 import org.opendaylight.netconf.impl.ServerChannelInitializer;
29 import org.opendaylight.netconf.impl.SessionIdProvider;
30 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
31 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
32
33 public final class NetconfServerDispatcherProvider extends ProviderTrait<NetconfServerDispatcher> {
34     private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20);
35
36     @Inject
37     @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR)
38     private NetconfOperationServiceFactory aggregator;
39     @Inject
40     private NetconfMonitoringService monitoringService;
41     @Inject
42     private Timer timer;
43     @Inject
44     private NioEventLoopGroup nettyThreadgroup;
45
46     @Override
47     protected NetconfServerDispatcherImpl create() {
48         AggregatedNetconfOperationServiceFactory netconfOperationProvider =
49                 new AggregatedNetconfOperationServiceFactory();
50         netconfOperationProvider.onAddNetconfOperationServiceFactory(aggregator);
51
52         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory =
53                 new NetconfServerSessionNegotiatorFactory(timer, netconfOperationProvider, new SessionIdProvider(),
54                         CONNECTION_TIMEOUT_MILLIS, monitoringService);
55         ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer(serverNegotiatorFactory);
56
57         return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
58     }
59
60     private static final class NetconfServerSessionNegotiatorFactory extends
61             org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory {
62
63         NetconfServerSessionNegotiatorFactory(final Timer timer,
64                                                      final AggregatedNetconfOperationServiceFactory netconfOperationProvider,
65                                                      final SessionIdProvider sessionIdProvider,
66                                                      final long connectionTimeoutMillis,
67                                                      final NetconfMonitoringService monitoringService) {
68             super(timer, netconfOperationProvider, sessionIdProvider, connectionTimeoutMillis, monitoringService,
69                     org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
70         }
71     }
72 }