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
209 lines (169 loc) · 5.75 KB
/
PNConfiguration.java
File metadata and controls
209 lines (169 loc) · 5.75 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
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 okhttp3.Authenticator;
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)
public class PNConfiguration {
private static final int PRESENCE_TIMEOUT = 300;
private static final int NON_SUBSCRIBE_REQUEST_TIMEOUT = 10;
private static final int SUBSCRIBE_TIMEOUT = 310;
private static final int CONNECT_TIMEOUT = 5;
@Getter
private SSLSocketFactory sslSocketFactory;
@Getter
private X509ExtendedTrustManager x509ExtendedTrustManager;
@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.
*/
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;
/**
* verbosity of heartbeat configuration, by default only alerts on failed heartbeats
*/
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
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;
/**
* 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;
/**
* Initialize the PNConfiguration with default values
*/
public PNConfiguration() {
setPresenceTimeout(PRESENCE_TIMEOUT);
uuid = 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;
}
/**
* 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) {
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) {
return setPresenceTimeoutWithCustomInterval(timeout, (timeout / 2) - 1);
}
}