forked from socketio/socket.io-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocketOptionBuilder.java
208 lines (157 loc) · 5.6 KB
/
SocketOptionBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package io.socket.client;
import javax.net.ssl.HostnameVerifier;
/**
* Convenient builder class that helps creating
* {@link io.socket.client.IO.Options Client Option} object as builder pattern.
* Finally, you can get option object with call {@link #build()} method.
*
* @author junbong
*/
public class SocketOptionBuilder {
/**
* Construct new builder with default preferences.
*
* @return new builder object
* @see SocketOptionBuilder#builder(IO.Options)
*/
public static SocketOptionBuilder builder() {
return new SocketOptionBuilder();
}
/**
* Construct this builder from specified option object.
* The option that returned from {@link #build()} method
* is not equals with given option.
* In other words, builder creates new option object
* and copy all preferences from given option.
*
* @param options option object which to copy preferences
* @return new builder object
*/
public static SocketOptionBuilder builder(IO.Options options) {
return new SocketOptionBuilder(options);
}
private final IO.Options options = new IO.Options();
/**
* Construct new builder with default preferences.
*/
protected SocketOptionBuilder() {
this(null);
}
/**
* Construct this builder from specified option object.
* The option that returned from {@link #build()} method
* is not equals with given option.
* In other words, builder creates new option object
* and copy all preferences from given option.
*
* @param options option object which to copy preferences. Null-ok.
*/
protected SocketOptionBuilder(IO.Options options) {
if (options != null) {
this.setForceNew(options.forceNew)
.setMultiplex(options.multiplex)
.setReconnection(options.reconnection)
.setReconnectionAttempts(options.reconnectionAttempts)
.setReconnectionDelay(options.reconnectionDelay)
.setReconnectionDelayMax(options.reconnectionDelayMax)
.setRandomizationFactor(options.randomizationFactor)
.setTimeout(options.timeout)
.setTransports(options.transports)
.setUpgrade(options.upgrade)
.setRememberUpgrade(options.rememberUpgrade)
.setHost(options.host)
.setHostname(options.hostname)
.setHostnameVerifier(options.hostnameVerifier)
.setPort(options.port)
.setPolicyPort(options.policyPort)
.setSecure(options.secure)
.setPath(options.path)
.setQuery(options.query);
}
}
public SocketOptionBuilder setForceNew(boolean forceNew) {
this.options.forceNew = forceNew;
return this;
}
public SocketOptionBuilder setMultiplex(boolean multiplex) {
this.options.multiplex = multiplex;
return this;
}
public SocketOptionBuilder setReconnection(boolean reconnection) {
this.options.reconnection = reconnection;
return this;
}
public SocketOptionBuilder setReconnectionAttempts(int reconnectionAttempts) {
this.options.reconnectionAttempts = reconnectionAttempts;
return this;
}
public SocketOptionBuilder setReconnectionDelay(long reconnectionDelay) {
this.options.reconnectionDelay = reconnectionDelay;
return this;
}
public SocketOptionBuilder setReconnectionDelayMax(long reconnectionDelayMax) {
this.options.reconnectionDelayMax = reconnectionDelayMax;
return this;
}
public SocketOptionBuilder setRandomizationFactor(double randomizationFactor) {
this.options.randomizationFactor = randomizationFactor;
return this;
}
public SocketOptionBuilder setTimeout(long timeout) {
this.options.timeout = timeout;
return this;
}
public SocketOptionBuilder setTransports(String[] transports) {
this.options.transports = transports;
return this;
}
public SocketOptionBuilder setUpgrade(boolean upgrade) {
this.options.upgrade = upgrade;
return this;
}
public SocketOptionBuilder setRememberUpgrade(boolean rememberUpgrade) {
this.options.rememberUpgrade = rememberUpgrade;
return this;
}
public SocketOptionBuilder setHost(String host) {
this.options.host = host;
return this;
}
public SocketOptionBuilder setHostname(String hostname) {
this.options.hostname = hostname;
return this;
}
public SocketOptionBuilder setHostnameVerifier(HostnameVerifier hostnameVerifier) {
this.options.hostnameVerifier = hostnameVerifier;
return this;
}
public SocketOptionBuilder setPort(int port) {
this.options.port = port;
return this;
}
public SocketOptionBuilder setPolicyPort(int policyPort) {
this.options.policyPort = policyPort;
return this;
}
public SocketOptionBuilder setQuery(String query) {
this.options.query = query;
return this;
}
public SocketOptionBuilder setSecure(boolean secure) {
this.options.secure = secure;
return this;
}
public SocketOptionBuilder setPath(String path) {
this.options.path = path;
return this;
}
/**
* Finally retrieve {@link io.socket.client.IO.Options} object
* from this builder.
*
* @return option that built from this builder
*/
public IO.Options build() {
return this.options;
}
}