Repository navigation
Expand file tree
/
Copy pathPubnub.java
More file actions
555 lines (516 loc) · 16.7 KB
/
Copy pathPubnub.java
File metadata and controls
555 lines (516 loc) · 16.7 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
package com.pubnub.api;
import java.util.Hashtable;
import java.util.Random;
/**
* Pubnub object facilitates querying channels for messages and listening on
* channels for presence/message events
*
* @author Pubnub
*
*/
public class Pubnub extends PubnubCore {
/**
* Pubnub Constructor
*
* @param publish_key
* Publish Key
* @param subscribe_key
* Subscribe Key
* @param secret_key
* Secret Key
* @param cipher_key
* Cipher Key
* @param ssl_on
* SSL on ?
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
String cipher_key, boolean ssl_on) {
super(publish_key, subscribe_key, secret_key, cipher_key, ssl_on);
}
/**
* Pubnub Constructor
*
* @param publish_key
* Publish key
* @param subscribe_key
* Subscribe Key
* @param secret_key
* Secret Key
* @param ssl_on
* SSL on ?
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key,
boolean ssl_on) {
super(publish_key, subscribe_key, secret_key, "", ssl_on);
}
/**
* Pubnub Constructor
*
* @param publish_key
* Publish Key
* @param subscribe_key
* Subscribe Key
*/
public Pubnub(String publish_key, String subscribe_key) {
super(publish_key, subscribe_key, "", "", false);
}
/**
* @param publish_key
* Publish Key
* @param subscribe_key
* Subscribe Key
* @param ssl
*/
public Pubnub(String publish_key, String subscribe_key, boolean ssl) {
super(publish_key, subscribe_key, "", "", ssl);
}
/**
* @param publish_key
* @param subscribe_key
* @param secret_key
*/
public Pubnub(String publish_key, String subscribe_key, String secret_key) {
super(publish_key, subscribe_key, secret_key, "", false);
}
/**
* Sets value for UUID
*
* @param uuid
* UUID value for Pubnub client
*/
public void setUUID(String uuid) {
this.UUID = uuid.toString();
}
protected String uuid() {
String valueBeforeMD5;
String valueAfterMD5;
Random mySecureRand = new Random();
String s_id = String.valueOf(PubnubCore.class.hashCode());
StringBuffer sbValueBeforeMD5 = new StringBuffer();
try {
long time = System.currentTimeMillis();
long rand = 0;
rand = mySecureRand.nextLong();
sbValueBeforeMD5.append(s_id);
sbValueBeforeMD5.append(":");
sbValueBeforeMD5.append(Long.toString(time));
sbValueBeforeMD5.append(":");
sbValueBeforeMD5.append(Long.toString(rand));
valueBeforeMD5 = sbValueBeforeMD5.toString();
byte[] array = PubnubCrypto.md5(valueBeforeMD5);
StringBuffer sb = new StringBuffer();
for (int j = 0; j < array.length; ++j) {
int b = array[j] & 0xFF;
if (b < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(b));
}
valueAfterMD5 = sb.toString();
String raw = valueAfterMD5.toUpperCase();
sb = new StringBuffer();
sb.append(raw.substring(0, 8));
sb.append("-");
sb.append(raw.substring(8, 12));
sb.append("-");
sb.append(raw.substring(12, 16));
sb.append("-");
sb.append(raw.substring(16, 20));
sb.append("-");
sb.append(raw.substring(20));
return sb.toString();
} catch (Exception e) {
return null;
}
}
/**
* This method sets timeout value for subscribe/presence. Default value is
* 310000 milliseconds i.e. 310 seconds
*
* @param timeout
* Timeout value in milliseconds for subscribe/presence
*/
public void setSubscribeTimeout(int timeout) {
super.setSubscribeTimeout(timeout);
}
/**
* This method returns timeout value for subscribe/presence.
*
* @return Timeout value in milliseconds for subscribe/presence
*/
public int getSubscribeTimeout() {
return super.getSubscribeTimeout();
}
/**
* This method set timeout value for non subscribe operations like publish,
* history, hereNow. Default value is 15000 milliseconds i.e. 15 seconds.
*
* @param timeout
* Timeout value in milliseconds for Non subscribe operations
* like publish, history, hereNow
*/
public void setNonSubscribeTimeout(int timeout) {
super.setNonSubscribeTimeout(timeout);
}
/**
* This method returns timeout value for non subscribe operations like publish, history, hereNow
*
* @return Timeout value in milliseconds for for Non subscribe operations like publish, history, hereNow
*/
public int getNonSubscribeTimeout() {
return super.getNonSubscribeTimeout();
}
protected String getUserAgent() {
return "Java/" + VERSION;
}
/**
* Send a message to a channel.
*
* @param args
* Hashtable containing channel name, message.
* @param callback
* object of sub class of Callback class
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Methods
* accepting Hashtable as arguments have been deprecated.
*/
@Deprecated
@Override
public void publish(Hashtable args, Callback callback) {
super.publish(args, callback);
}
/**
* Send a message to a channel.
*
* @param args
* Hashtable containing channel name, message, callback
* @deprecated As of version 3.5.2 . Will be removed in 3.6.0 . Methods
* accepting Hashtable as arguments have been deprecated.
*
*/
@Deprecated
@Override
public void publish(Hashtable args) {
super.publish(args);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param count
* Upper limit on number of messages to be returned
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, long start, long end, int count, boolean reverse, Callback callback)}
*/
@Deprecated
@Override
public void detailedHistory(final String channel, long start, long end,
int count, boolean reverse, final Callback callback) {
super.detailedHistory(channel, start, end, count, reverse, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param count
* Upper limit on number of messages to be returned
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
*/
public void history(final String channel, long start, long end, int count,
boolean reverse, final Callback callback) {
super.detailedHistory(channel, start, end, count, reverse, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, long start, boolean reverse, Callback callback)}
*/
@Deprecated
@Override
public void detailedHistory(String channel, long start, boolean reverse,
Callback callback) {
super.detailedHistory(channel, start, reverse, callback);
}
/**
*
* Read history for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
*/
public void history(String channel, long start, boolean reverse,
Callback callback) {
super.detailedHistory(channel, start, reverse, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, long start, long end, Callback callback)}
*/
@Deprecated
@Override
public void detailedHistory(String channel, long start, long end,
Callback callback) {
super.detailedHistory(channel, start, end, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param callback
* Callback
*/
public void history(String channel, long start, long end, Callback callback) {
super.detailedHistory(channel, start, end, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, long start, long end, boolean reverse, Callback callback)}
*/
@Deprecated
@Override
public void detailedHistory(String channel, long start, long end,
boolean reverse, Callback callback) {
super.detailedHistory(channel, start, end, reverse, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param start
* Start time
* @param end
* End time
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
*/
public void history(String channel, long start, long end, boolean reverse,
Callback callback) {
super.detailedHistory(channel, start, end, reverse, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param count
* Upper limit on number of messages to be returned
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, int count, boolean reverse, Callback callback)}
*/
@Deprecated
@Override
public void detailedHistory(String channel, int count, boolean reverse,
Callback callback) {
super.detailedHistory(channel, count, reverse, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param count
* Upper limit on number of messages to be returned
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
*/
public void history(String channel, int count, boolean reverse,
Callback callback) {
super.detailedHistory(channel, count, reverse, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, boolean reverse, Callback callback)}
*/
@Deprecated
public void detailedHistory(String channel, boolean reverse,
Callback callback) {
super.detailedHistory(channel, reverse, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param reverse
* True if messages need to be in reverse order
* @param callback
* Callback
*/
public void history(String channel, boolean reverse, Callback callback) {
super.detailedHistory(channel, reverse, callback);
}
/**
*
* Read DetailedHistory for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param count
* Maximum number of messages
* @param callback
* Callback object
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Replaced
* by
* {@link #history(String channel, int count, Callback callback)}
*/
@Deprecated
public void detailedHistory(String channel, int count, Callback callback) {
super.detailedHistory(channel, count, callback);
}
/**
*
* Read History for a channel.
*
* @param channel
* Channel name for which detailed history is required
* @param count
* Maximum number of messages
* @param callback
* Callback object
*/
@Override
public void history(String channel, int count, Callback callback) {
super.detailedHistory(channel, count, callback);
}
/**
* Unsubscribe/Disconnect from channel.
*
* @param args
* Hashtable containing channel name.
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Methods
* accepting Hashtable as arguments have been deprecated.
*/
@Deprecated
public void unsubscribe(Hashtable args) {
String[] channelList = (String[]) args.get("channels");
if (channelList == null) {
channelList = new String[] { (String) args.get("channel") };
}
unsubscribe(channelList);
}
/**
*
* Listen for a message on a channel.
*
* @param args
* Hashtable containing channel name
* @param callback
* Callback
* @exception PubnubException
* Throws PubnubException if Callback is null
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 .
*/
@Deprecated
public void subscribe(Hashtable args, Callback callback)
throws PubnubException {
args.put("callback", callback);
super.subscribe(args);
}
/**
*
* Listen for a message on a channel.
*
* @param args
* Hashtable containing channel name, callback
* @exception PubnubException
* Throws PubnubException if Callback is null
* @deprecated as of version 3.5.2 and will be removed with 3.6.0 . Methods
* accepting Hashtable as arguments have been deprecated.
*/
@Deprecated
public void subscribe(Hashtable args) throws PubnubException {
super.subscribe(args);
}
}