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
144 lines (118 loc) · 4.21 KB
/
Copy pathPNConfiguration.java
File metadata and controls
144 lines (118 loc) · 4.21 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
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 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;
/**
* 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;
/**
* 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;
}
/**
* 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(final int timeout, final 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(final int timeout) {
return setPresenceTimeoutWithCustomInterval(timeout, (timeout / 2) - 1);
}
}