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