Move netconf-dom-api
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / conf / NetconfClientConfigurationBuilder.java
1 /*
2  * Copyright (c) 2014 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.client.conf;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import java.net.InetSocketAddress;
13 import java.util.List;
14 import org.checkerframework.checker.index.qual.NonNegative;
15 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
16 import org.opendaylight.netconf.client.NetconfClientSessionListener;
17 import org.opendaylight.netconf.client.SslHandlerFactory;
18 import org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator;
19 import org.opendaylight.netconf.nettyutil.ReconnectStrategy;
20 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
21 import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfSshClient;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
23
24 public class NetconfClientConfigurationBuilder {
25
26     public static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000;
27     public static final NetconfClientConfiguration.NetconfClientProtocol DEFAULT_CLIENT_PROTOCOL =
28             NetconfClientConfiguration.NetconfClientProtocol.TCP;
29
30     private InetSocketAddress address;
31     private long connectionTimeoutMillis = DEFAULT_CONNECTION_TIMEOUT_MILLIS;
32     private NetconfHelloMessageAdditionalHeader additionalHeader;
33     private NetconfClientSessionListener sessionListener;
34     private ReconnectStrategy reconnectStrategy;
35     private AuthenticationHandler authHandler;
36     private NetconfClientConfiguration.NetconfClientProtocol clientProtocol = DEFAULT_CLIENT_PROTOCOL;
37     private SslHandlerFactory sslHandlerFactory;
38     private NetconfSshClient sshClient;
39     private List<Uri> odlHelloCapabilities;
40     private @NonNegative int maximumIncomingChunkSize =
41         AbstractNetconfSessionNegotiator.DEFAULT_MAXIMUM_INCOMING_CHUNK_SIZE;
42     private String name;
43
44     protected NetconfClientConfigurationBuilder() {
45     }
46
47     public static NetconfClientConfigurationBuilder create() {
48         return new NetconfClientConfigurationBuilder();
49     }
50
51     @SuppressWarnings("checkstyle:hiddenField")
52     public NetconfClientConfigurationBuilder withAddress(final InetSocketAddress address) {
53         this.address = address;
54         return this;
55     }
56
57     @SuppressWarnings("checkstyle:hiddenField")
58     public NetconfClientConfigurationBuilder withConnectionTimeoutMillis(final long connectionTimeoutMillis) {
59         this.connectionTimeoutMillis = connectionTimeoutMillis;
60         return this;
61     }
62
63     @SuppressWarnings("checkstyle:hiddenField")
64     public NetconfClientConfigurationBuilder withProtocol(
65             final NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
66         this.clientProtocol = clientProtocol;
67         return this;
68     }
69
70     @SuppressWarnings("checkstyle:hiddenField")
71     public NetconfClientConfigurationBuilder withAdditionalHeader(
72             final NetconfHelloMessageAdditionalHeader additionalHeader) {
73         this.additionalHeader = additionalHeader;
74         return this;
75     }
76
77     @SuppressWarnings("checkstyle:hiddenField")
78     public NetconfClientConfigurationBuilder withSessionListener(final NetconfClientSessionListener sessionListener) {
79         this.sessionListener = sessionListener;
80         return this;
81     }
82
83     @SuppressWarnings("checkstyle:hiddenField")
84     public NetconfClientConfigurationBuilder withReconnectStrategy(final ReconnectStrategy reconnectStrategy) {
85         this.reconnectStrategy = reconnectStrategy;
86         return this;
87     }
88
89     @SuppressWarnings("checkstyle:hiddenField")
90     public NetconfClientConfigurationBuilder withAuthHandler(final AuthenticationHandler authHandler) {
91         this.authHandler = authHandler;
92         return this;
93     }
94
95     @SuppressWarnings("checkstyle:hiddenField")
96     public NetconfClientConfigurationBuilder withSslHandlerFactory(final SslHandlerFactory sslHandlerFactory) {
97         this.sslHandlerFactory = sslHandlerFactory;
98         return this;
99     }
100
101     @SuppressWarnings("checkstyle:hiddenField")
102     public NetconfClientConfigurationBuilder withSshClient(final NetconfSshClient sshClient) {
103         this.sshClient = sshClient;
104         return this;
105     }
106
107     @SuppressWarnings("checkstyle:hiddenField")
108     public NetconfClientConfigurationBuilder withName(final String name) {
109         this.name = name;
110         return this;
111     }
112
113     @SuppressWarnings("checkstyle:hiddenField")
114     public NetconfClientConfigurationBuilder withOdlHelloCapabilities(final List<Uri> odlHelloCapabilities) {
115         this.odlHelloCapabilities = odlHelloCapabilities;
116         return this;
117     }
118
119     @SuppressWarnings("checkstyle:hiddenField")
120     public NetconfClientConfigurationBuilder withMaximumIncomingChunkSize(
121             final @NonNegative int maximumIncomingChunkSize) {
122         checkArgument(maximumIncomingChunkSize > 0);
123         this.maximumIncomingChunkSize  = maximumIncomingChunkSize;
124         return this;
125     }
126
127     final InetSocketAddress getAddress() {
128         return address;
129     }
130
131     final long getConnectionTimeoutMillis() {
132         return connectionTimeoutMillis;
133     }
134
135     final NetconfHelloMessageAdditionalHeader getAdditionalHeader() {
136         return additionalHeader;
137     }
138
139     final NetconfClientSessionListener getSessionListener() {
140         return sessionListener;
141     }
142
143     final ReconnectStrategy getReconnectStrategy() {
144         return reconnectStrategy;
145     }
146
147     final AuthenticationHandler getAuthHandler() {
148         return authHandler;
149     }
150
151     final NetconfClientConfiguration.NetconfClientProtocol getProtocol() {
152         return clientProtocol;
153     }
154
155     final SslHandlerFactory getSslHandlerFactory() {
156         return sslHandlerFactory;
157     }
158
159     public NetconfSshClient getSshClient() {
160         return sshClient;
161     }
162
163     final List<Uri> getOdlHelloCapabilities() {
164         return odlHelloCapabilities;
165     }
166
167     final @NonNegative int getMaximumIncomingChunkSize() {
168         return maximumIncomingChunkSize;
169     }
170
171     final String getName() {
172         return name;
173     }
174
175     public NetconfClientConfiguration build() {
176         return new NetconfClientConfiguration(clientProtocol, address, connectionTimeoutMillis, additionalHeader,
177                 sessionListener, reconnectStrategy, authHandler, sslHandlerFactory, sshClient, odlHelloCapabilities,
178                 maximumIncomingChunkSize, name);
179     }
180 }