a46ed9a4bf373870118a50228f87630a22ebce46
[transportpce.git] / tests / honeynode / 2.2.1 / netconf-impl / src / main / java / org / opendaylight / netconf / impl / NetconfServerSessionNegotiatorFactoryBuilder.java
1 /*
2  * Copyright (c) 2016 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.impl;
10
11 import com.google.common.base.Preconditions;
12 import io.netty.util.Timer;
13 import java.util.Set;
14 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
15 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
16
17 public class NetconfServerSessionNegotiatorFactoryBuilder {
18     private Timer timer;
19     private SessionIdProvider idProvider;
20     private NetconfOperationServiceFactory aggregatedOpService;
21     private long connectionTimeoutMillis;
22     private NetconfMonitoringService monitoringService;
23     private Set<String> baseCapabilities;
24
25     public NetconfServerSessionNegotiatorFactoryBuilder() {
26     }
27
28     public NetconfServerSessionNegotiatorFactoryBuilder setTimer(final Timer timer) {
29         this.timer = timer;
30         return this;
31     }
32
33     public NetconfServerSessionNegotiatorFactoryBuilder setIdProvider(final SessionIdProvider idProvider) {
34         this.idProvider = idProvider;
35         return this;
36     }
37
38     public NetconfServerSessionNegotiatorFactoryBuilder setAggregatedOpService(
39             final NetconfOperationServiceFactory aggregatedOpService) {
40         this.aggregatedOpService = aggregatedOpService;
41         return this;
42     }
43
44     public NetconfServerSessionNegotiatorFactoryBuilder setConnectionTimeoutMillis(final long connectionTimeoutMillis) {
45         this.connectionTimeoutMillis = connectionTimeoutMillis;
46         return this;
47     }
48
49     public NetconfServerSessionNegotiatorFactoryBuilder setMonitoringService(
50             final NetconfMonitoringService monitoringService) {
51         this.monitoringService = monitoringService;
52         return this;
53     }
54
55     public NetconfServerSessionNegotiatorFactoryBuilder setBaseCapabilities(final Set<String> baseCapabilities) {
56         this.baseCapabilities = baseCapabilities;
57         return this;
58     }
59
60
61     public NetconfServerSessionNegotiatorFactory build() {
62         validate();
63         return new NetconfServerSessionNegotiatorFactory(timer, aggregatedOpService, idProvider,
64                 connectionTimeoutMillis, monitoringService, baseCapabilities);
65     }
66
67
68     private void validate() {
69         Preconditions.checkNotNull(timer, "timer not initialized");
70         Preconditions.checkNotNull(aggregatedOpService, "NetconfOperationServiceFactory not initialized");
71         Preconditions.checkNotNull(idProvider, "SessionIdProvider not initialized");
72         Preconditions.checkArgument(connectionTimeoutMillis > 0, "connection time out <=0");
73         Preconditions.checkNotNull(monitoringService, "NetconfMonitoringService not initialized");
74
75         baseCapabilities = (baseCapabilities == null) ? NetconfServerSessionNegotiatorFactory
76                 .DEFAULT_BASE_CAPABILITIES : baseCapabilities;
77     }
78 }