91013153797a4eb7893b46a55e261ddcbd51e3ca
[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 java.net.InetSocketAddress;
11 import java.util.List;
12 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
13 import org.opendaylight.netconf.client.NetconfClientSessionListener;
14 import org.opendaylight.netconf.client.SslHandlerFactory;
15 import org.opendaylight.netconf.nettyutil.ReconnectStrategy;
16 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
17 import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfSshClient;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
19
20 public class NetconfClientConfigurationBuilder {
21
22     public static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000;
23     public static final NetconfClientConfiguration.NetconfClientProtocol DEFAULT_CLIENT_PROTOCOL =
24             NetconfClientConfiguration.NetconfClientProtocol.TCP;
25
26     private InetSocketAddress address;
27     private long connectionTimeoutMillis = DEFAULT_CONNECTION_TIMEOUT_MILLIS;
28     private NetconfHelloMessageAdditionalHeader additionalHeader;
29     private NetconfClientSessionListener sessionListener;
30     private ReconnectStrategy reconnectStrategy;
31     private AuthenticationHandler authHandler;
32     private NetconfClientConfiguration.NetconfClientProtocol clientProtocol = DEFAULT_CLIENT_PROTOCOL;
33     private SslHandlerFactory sslHandlerFactory;
34     private NetconfSshClient sshClient;
35     private List<Uri> odlHelloCapabilities;
36
37
38     protected NetconfClientConfigurationBuilder() {
39     }
40
41     public static NetconfClientConfigurationBuilder create() {
42         return new NetconfClientConfigurationBuilder();
43     }
44
45     @SuppressWarnings("checkstyle:hiddenField")
46     public NetconfClientConfigurationBuilder withAddress(final InetSocketAddress address) {
47         this.address = address;
48         return this;
49     }
50
51     @SuppressWarnings("checkstyle:hiddenField")
52     public NetconfClientConfigurationBuilder withConnectionTimeoutMillis(final long connectionTimeoutMillis) {
53         this.connectionTimeoutMillis = connectionTimeoutMillis;
54         return this;
55     }
56
57     @SuppressWarnings("checkstyle:hiddenField")
58     public NetconfClientConfigurationBuilder withProtocol(
59             final NetconfClientConfiguration.NetconfClientProtocol clientProtocol) {
60         this.clientProtocol = clientProtocol;
61         return this;
62     }
63
64     @SuppressWarnings("checkstyle:hiddenField")
65     public NetconfClientConfigurationBuilder withAdditionalHeader(
66             final NetconfHelloMessageAdditionalHeader additionalHeader) {
67         this.additionalHeader = additionalHeader;
68         return this;
69     }
70
71     @SuppressWarnings("checkstyle:hiddenField")
72     public NetconfClientConfigurationBuilder withSessionListener(final NetconfClientSessionListener sessionListener) {
73         this.sessionListener = sessionListener;
74         return this;
75     }
76
77     @SuppressWarnings("checkstyle:hiddenField")
78     public NetconfClientConfigurationBuilder withReconnectStrategy(final ReconnectStrategy reconnectStrategy) {
79         this.reconnectStrategy = reconnectStrategy;
80         return this;
81     }
82
83     @SuppressWarnings("checkstyle:hiddenField")
84     public NetconfClientConfigurationBuilder withAuthHandler(final AuthenticationHandler authHandler) {
85         this.authHandler = authHandler;
86         return this;
87     }
88
89     @SuppressWarnings("checkstyle:hiddenField")
90     public NetconfClientConfigurationBuilder withSslHandlerFactory(final SslHandlerFactory sslHandlerFactory) {
91         this.sslHandlerFactory = sslHandlerFactory;
92         return this;
93     }
94
95     @SuppressWarnings("checkstyle:hiddenField")
96     public NetconfClientConfigurationBuilder withSshClient(final NetconfSshClient sshClient) {
97         this.sshClient = sshClient;
98         return this;
99     }
100
101     @SuppressWarnings("checkstyle:hiddenField")
102     public NetconfClientConfigurationBuilder withOdlHelloCapabilities(final List<Uri> odlHelloCapabilities) {
103         this.odlHelloCapabilities = odlHelloCapabilities;
104         return this;
105     }
106
107     final InetSocketAddress getAddress() {
108         return address;
109     }
110
111     final long getConnectionTimeoutMillis() {
112         return connectionTimeoutMillis;
113     }
114
115     final NetconfHelloMessageAdditionalHeader getAdditionalHeader() {
116         return additionalHeader;
117     }
118
119     final NetconfClientSessionListener getSessionListener() {
120         return sessionListener;
121     }
122
123     final ReconnectStrategy getReconnectStrategy() {
124         return reconnectStrategy;
125     }
126
127     final AuthenticationHandler getAuthHandler() {
128         return authHandler;
129     }
130
131     final NetconfClientConfiguration.NetconfClientProtocol getProtocol() {
132         return clientProtocol;
133     }
134
135     final SslHandlerFactory getSslHandlerFactory() {
136         return sslHandlerFactory;
137     }
138
139     public NetconfSshClient getSshClient() {
140         return sshClient;
141     }
142
143     final List<Uri> getOdlHelloCapabilities() {
144         return odlHelloCapabilities;
145     }
146
147     public NetconfClientConfiguration build() {
148         return new NetconfClientConfiguration(clientProtocol, address, connectionTimeoutMillis, additionalHeader,
149                 sessionListener, reconnectStrategy, authHandler, sslHandlerFactory, sshClient, odlHelloCapabilities);
150     }
151 }