forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPNConfiguration.java
More file actions
279 lines (230 loc) · 7.97 KB
/
Copy pathPNConfiguration.java
File metadata and controls
279 lines (230 loc) · 7.97 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package com.pubnub.api;
import com.pubnub.api.enums.PNHeartbeatNotificationOptions;
import com.pubnub.api.enums.PNLogVerbosity;
import com.pubnub.api.enums.PNReconnectionPolicy;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.java.Log;
import okhttp3.Authenticator;
import okhttp3.CertificatePinner;
import okhttp3.ConnectionSpec;
import okhttp3.logging.HttpLoggingInterceptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509ExtendedTrustManager;
import java.net.Proxy;
import java.net.ProxySelector;
import java.util.UUID;
@Getter
@Setter
@Accessors(chain = true)
@Log
public class PNConfiguration {
private static final int DEFAULT_DEDUPE_SIZE = 100;
private static final int PRESENCE_TIMEOUT = 300;
private static final int MINIMUM_PRESENCE_TIMEOUT = 20;
private static final int NON_SUBSCRIBE_REQUEST_TIMEOUT = 10;
private static final int SUBSCRIBE_TIMEOUT = 310;
private static final int CONNECT_TIMEOUT = 5;
private static final int FILE_MESSAGE_PUBLISH_RETRY_LIMIT = 5;
@Getter
private SSLSocketFactory sslSocketFactory;
@Getter
private X509ExtendedTrustManager x509ExtendedTrustManager;
@Getter
private ConnectionSpec connectionSpec;
@Getter
private HostnameVerifier hostnameVerifier;
/**
* Set to true to send a UUID for PubNub instance
*/
@Getter
private boolean includeInstanceIdentifier;
/**
* Set to true to send a UUID on each request
*/
@Getter
private boolean includeRequestIdentifier;
/**
* By default, the origin is pointing directly to PubNub servers. If a proxy origin is needed, set a custom
* origin using this parameter.
*/
private String origin;
private int subscribeTimeout;
/**
* In seconds, how long the server will consider this client to be online before issuing a leave event.
*/
@Setter(AccessLevel.NONE)
private int presenceTimeout;
/**
* In seconds, How often the client should announce it's existence via heartbeating.
*/
@Setter(AccessLevel.NONE)
private int heartbeatInterval;
/**
* set to true to switch the client to HTTPS:// based communications.
*/
private boolean secure;
/**
* Subscribe Key provided by PubNub
*/
private String subscribeKey;
/**
* Publish Key provided by PubNub.
*/
private String publishKey;
private String secretKey;
private String cipherKey;
private String authKey;
private String uuid;
/**
* If proxies are forcefully caching requests, set to true to allow the client to randomize the subdomain.
* This configuration is not supported if custom origin is enabled.
*/
@Deprecated
private boolean cacheBusting;
/**
* toggle to enable verbose logging.
*/
@NotNull
private PNLogVerbosity logVerbosity;
/**
* Stores the maximum number of seconds which the client should wait for connection before timing out.
*/
private int connectTimeout;
/**
* Reference on number of seconds which is used by client during non-subscription operations to
* check whether response potentially failed with 'timeout' or not.
*/
private int nonSubscribeRequestTimeout;
/**
* Suppress leave events when a channel gets disconnected
*/
private boolean suppressLeaveEvents;
/**
* verbosity of heartbeat configuration, by default only alerts on failed heartbeats
*/
@Nullable
private PNHeartbeatNotificationOptions heartbeatNotificationOptions;
/**
* filterExpression used as part of PSV2 specification.
*/
@Setter
private String filterExpression;
/**
* Reconnection policy which will be used if/when networking goes down
*/
@Setter
@Nullable
private PNReconnectionPolicy reconnectionPolicy;
/**
* Set how many times the reconneciton manager will try to connect before giving app
*/
@Setter
private int maximumReconnectionRetries;
/**
* Proxy configuration which will be passed to the networking layer.
*/
@Setter
private Proxy proxy;
@Setter
private ProxySelector proxySelector;
@Setter
private Authenticator proxyAuthenticator;
@Setter
private CertificatePinner certificatePinner;
@Setter
private Integer maximumConnections;
@Setter
private HttpLoggingInterceptor httpLoggingInterceptor;
/**
* if set, the SDK will alert once the number of messages arrived in one call equal to the threshold
*/
private Integer requestMessageCountThreshold;
/**
* Use Google App Engine based networking configuration
*/
@Setter
private boolean googleAppEngineNetworking;
@Setter
private boolean startSubscriberThread;
@Setter
private boolean dedupOnSubscribe;
@Setter
private Integer maximumMessagesCacheSize;
@Setter
private boolean useRandomInitializationVector;
@Setter
private int fileMessagePublishRetryLimit;
/**
* Enables explicit presence control.
* When set to true heartbeat calls will contain only channels and groups added explicitly
* using {@link PubNub#presence()}. Should be used only with ACL set on the server side.
* For more information please contact PubNub support
*
* @see PubNub#presence()
* @see PNConfiguration#heartbeatInterval
*/
@Deprecated
@Setter
private boolean managePresenceListManually;
/**
* Initialize the PNConfiguration with default values
*/
public PNConfiguration() {
setPresenceTimeoutWithCustomInterval(PRESENCE_TIMEOUT, 0);
uuid = "pn-" + UUID.randomUUID().toString();
nonSubscribeRequestTimeout = NON_SUBSCRIBE_REQUEST_TIMEOUT;
subscribeTimeout = SUBSCRIBE_TIMEOUT;
connectTimeout = CONNECT_TIMEOUT;
logVerbosity = PNLogVerbosity.NONE;
heartbeatNotificationOptions = PNHeartbeatNotificationOptions.FAILURES;
reconnectionPolicy = PNReconnectionPolicy.NONE;
secure = true;
includeInstanceIdentifier = false;
includeRequestIdentifier = true;
startSubscriberThread = true;
maximumReconnectionRetries = -1;
dedupOnSubscribe = false;
suppressLeaveEvents = false;
maximumMessagesCacheSize = DEFAULT_DEDUPE_SIZE;
useRandomInitializationVector = true;
fileMessagePublishRetryLimit = FILE_MESSAGE_PUBLISH_RETRY_LIMIT;
managePresenceListManually = false;
}
/**
* set presence configurations for timeout and announce interval.
*
* @param timeout presence timeout; how long before the server considers this client to be gone.
* @param interval presence announce interval, how often the client should announce itself.
* @return returns itself.
*/
public PNConfiguration setPresenceTimeoutWithCustomInterval(int timeout, int interval) {
timeout = validatePresenceTimeout(timeout);
this.presenceTimeout = timeout;
this.heartbeatInterval = interval;
return this;
}
/**
* set presence configurations for timeout and allow the client to pick the best interval
*
* @param timeout presence timeout; how long before the server considers this client to be gone.
* @return returns itself.
*/
public PNConfiguration setPresenceTimeout(int timeout) {
timeout = validatePresenceTimeout(timeout);
return setPresenceTimeoutWithCustomInterval(timeout, (timeout / 2) - 1);
}
private int validatePresenceTimeout(int timeout) {
int validTimeout = timeout;
if (timeout < MINIMUM_PRESENCE_TIMEOUT) {
validTimeout = MINIMUM_PRESENCE_TIMEOUT;
log.warning("Presence timeout is too low. Defaulting to: " + MINIMUM_PRESENCE_TIMEOUT);
}
return validTimeout;
}
}