Skip to content

Commit ed2663e

Browse files
author
Devendra
committed
removing v2 code
1 parent a3e87ad commit ed2663e

7 files changed

Lines changed: 21 additions & 598 deletions

File tree

‎java/srcPubnubApi/srcCore/com/pubnub/api/PubnubCore.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ protected Object _publish(Hashtable args, boolean sync) {
198198
if (storeInHistory != null && storeInHistory.length() > 0)
199199
parameters.put("store", storeInHistory);
200200

201-
JSONObject meta = (JSONObject) args.get("meta");
202-
if (meta != null && meta.length() > 0)
203-
parameters.put("meta", meta.toString());
204201

205202
final Callback callback = getWrappedCallback(cb);
206203

‎java/srcPubnubApi/srcCore/com/pubnub/api/PubnubCoreAsync.java‎

Lines changed: 9 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ abstract class PubnubCoreAsync extends PubnubCore implements PubnubAsyncInterfac
2121

2222
protected TimedTaskManager timedTaskManager;
2323
private volatile String _timetoken = "0";
24-
private volatile String _region = null;
2524
private volatile String _saved_timetoken = "0";
2625

2726
protected static String PRESENCE_SUFFIX = "-pnpres";
@@ -34,17 +33,6 @@ abstract class PubnubCoreAsync extends PubnubCore implements PubnubAsyncInterfac
3433
private int HEARTBEAT = 320;
3534
private volatile int PRESENCE_HB_INTERVAL = 0;
3635

37-
private String connectionid;
38-
39-
private boolean V2 = false;
40-
41-
public void setV2(boolean v2) {
42-
this.V2 = v2;
43-
}
44-
45-
public boolean isV2() {
46-
return this.V2;
47-
}
4836

4937
public void shutdown() {
5038
nonSubscribeManager.stop();
@@ -260,10 +248,6 @@ public PubnubCoreAsync(String publish_key, String subscribe_key, String secret_k
260248

261249
Random random = new Random();
262250

263-
private String getNewConnectionId() {
264-
return "conn" + random.nextInt();
265-
}
266-
267251
private void initAsync() {
268252

269253
if (channelSubscriptions == null)
@@ -291,8 +275,6 @@ private void initAsync() {
291275
nonSubscribeManager.setHeader("Accept-Encoding", "gzip");
292276
nonSubscribeManager.setHeader("User-Agent", getUserAgent());
293277

294-
this.connectionid = getNewConnectionId();
295-
296278
}
297279

298280
public void setSubscribeTimeout(int timeout) {
@@ -397,103 +379,6 @@ public void publish(String channel, Double message, Callback callback) {
397379
_publish(args, false);
398380
}
399381

400-
public void publish(String channel, JSONObject message, boolean storeInHistory, JSONObject metadata,
401-
Callback callback) {
402-
Hashtable args = new Hashtable();
403-
args.put("channel", channel);
404-
args.put("message", message);
405-
args.put("callback", callback);
406-
args.put("meta", metadata);
407-
args.put("storeInHistory", (storeInHistory) ? "" : "0");
408-
_publish(args, false);
409-
}
410-
411-
public void publish(String channel, JSONArray message, boolean storeInHistory, JSONObject metadata,
412-
Callback callback) {
413-
Hashtable args = new Hashtable();
414-
args.put("channel", channel);
415-
args.put("message", message);
416-
args.put("callback", callback);
417-
args.put("meta", metadata);
418-
args.put("storeInHistory", (storeInHistory) ? "" : "0");
419-
_publish(args, false);
420-
}
421-
422-
public void publish(String channel, String message, boolean storeInHistory, JSONObject metadata, Callback callback) {
423-
Hashtable args = new Hashtable();
424-
args.put("channel", channel);
425-
args.put("message", message);
426-
args.put("callback", callback);
427-
args.put("meta", metadata);
428-
args.put("storeInHistory", (storeInHistory) ? "" : "0");
429-
_publish(args, false);
430-
}
431-
432-
public void publish(String channel, Integer message, boolean storeInHistory, JSONObject metadata, Callback callback) {
433-
Hashtable args = new Hashtable();
434-
args.put("channel", channel);
435-
args.put("message", message);
436-
args.put("callback", callback);
437-
args.put("meta", metadata);
438-
args.put("storeInHistory", (storeInHistory) ? "" : "0");
439-
_publish(args, false);
440-
}
441-
442-
public void publish(String channel, Double message, boolean storeInHistory, JSONObject metadata, Callback callback) {
443-
Hashtable args = new Hashtable();
444-
args.put("channel", channel);
445-
args.put("message", message);
446-
args.put("callback", callback);
447-
args.put("meta", metadata);
448-
args.put("storeInHistory", (storeInHistory) ? "" : "0");
449-
_publish(args, false);
450-
}
451-
452-
public void publish(String channel, JSONObject message, JSONObject metadata, Callback callback) {
453-
Hashtable args = new Hashtable();
454-
args.put("channel", channel);
455-
args.put("message", message);
456-
args.put("meta", metadata);
457-
args.put("callback", callback);
458-
_publish(args, false);
459-
}
460-
461-
public void publish(String channel, JSONArray message, JSONObject metadata, Callback callback) {
462-
Hashtable args = new Hashtable();
463-
args.put("channel", channel);
464-
args.put("message", message);
465-
args.put("meta", metadata);
466-
args.put("callback", callback);
467-
_publish(args, false);
468-
}
469-
470-
public void publish(String channel, String message, JSONObject metadata, Callback callback) {
471-
Hashtable args = new Hashtable();
472-
args.put("channel", channel);
473-
args.put("message", message);
474-
args.put("meta", metadata);
475-
args.put("callback", callback);
476-
_publish(args, false);
477-
}
478-
479-
public void publish(String channel, Integer message, JSONObject metadata, Callback callback) {
480-
Hashtable args = new Hashtable();
481-
args.put("channel", channel);
482-
args.put("message", message);
483-
args.put("meta", metadata);
484-
args.put("callback", callback);
485-
_publish(args, false);
486-
}
487-
488-
public void publish(String channel, Double message, JSONObject metadata, Callback callback) {
489-
Hashtable args = new Hashtable();
490-
args.put("channel", channel);
491-
args.put("message", message);
492-
args.put("meta", metadata);
493-
args.put("callback", callback);
494-
_publish(args, false);
495-
}
496-
497382
protected void publish(Hashtable args, Callback callback) {
498383
args.put("callback", callback);
499384
_publish(args, false);
@@ -722,9 +607,6 @@ private void _leave(String channel, String channelGroup, Hashtable params, Callb
722607
if (!PubnubUtil.isEmptyString(channelGroup))
723608
params.put("channel-group", channelGroup);
724609

725-
params.put("connectionid", this.connectionid);
726-
this.connectionid = getNewConnectionId();
727-
728610
HttpRequest hreq = new HttpRequest(urlArgs, params, new ResponseHandler() {
729611
public void handleResponse(HttpRequest hreq, String response) {
730612
cb.successCallback(null, response);
@@ -1095,11 +977,7 @@ private void _subscribe(Hashtable args) {
1095977

1096978
String[] channelList = (String[]) args.get("channels");
1097979
String[] groupList = (String[]) args.get("groups");
1098-
String filter = (String) args.get("filter");
1099980

1100-
if (filter != null && filter.length() > 0) {
1101-
channelSubscriptions.setFilter(filter);
1102-
}
1103981

1104982
if (channelList == null) {
1105983
channelList = new String[0];
@@ -1209,20 +1087,12 @@ private void _subscribe_base(boolean fresh, boolean dar, Worker worker) {
12091087
channelString = PubnubUtil.urlEncode(channelString);
12101088
}
12111089

1212-
String[] urlComponents = { getPubnubUrl(), ((this.V2) ? "v2/" : "") + "subscribe", this.SUBSCRIBE_KEY,
1213-
channelString, "0" + ((this.V2) ? "" : "/" + _timetoken) };
1090+
String[] urlComponents = { getPubnubUrl(), "subscribe", this.SUBSCRIBE_KEY,
1091+
channelString, "0" + "/" + _timetoken};
12141092

12151093
Hashtable params = PubnubUtil.hashtableClone(this.params);
12161094
params.put("uuid", UUID);
12171095

1218-
if (this.V2) {
1219-
params.put("tt", _timetoken);
1220-
if (this._region != null)
1221-
params.put("tr", this._region);
1222-
} else {
1223-
1224-
}
1225-
12261096
if (groupsArray.length > 0) {
12271097
params.put("channel-group", groupString);
12281098
}
@@ -1235,87 +1105,11 @@ private void _subscribe_base(boolean fresh, boolean dar, Worker worker) {
12351105
params.put("heartbeat", String.valueOf(HEARTBEAT));
12361106
log.verbose("Subscribing with timetoken : " + _timetoken);
12371107

1238-
// add connection id
1239-
1240-
params.put("connectionid", this.connectionid);
1241-
1242-
if (channelSubscriptions.getFilter() != null && channelSubscriptions.getFilter().length() > 0) {
1243-
params.put("filter-expr", channelSubscriptions.getFilter());
1244-
}
12451108

12461109
HttpRequest hreq = new HttpRequest(urlComponents, params, new ResponseHandler() {
12471110

1248-
void changeKey(JSONObject o, String ok, String nk) throws JSONException {
1249-
if (!o.isNull(ok)) {
1250-
Object t = o.get(ok);
1251-
o.put(nk, t);
1252-
o.remove(ok);
1253-
}
1254-
}
1255-
1256-
JSONObject expandV2Keys(JSONObject m) throws JSONException {
1257-
if (!m.isNull("o")) {
1258-
changeKey(m.getJSONObject("o"), "t", "timetoken");
1259-
changeKey(m.getJSONObject("o"), "r", "region_code");
1260-
}
1261-
if (!m.isNull("p")) {
1262-
changeKey(m.getJSONObject("p"), "t", "timetoken");
1263-
changeKey(m.getJSONObject("p"), "r", "region_code");
1264-
}
1265-
changeKey(m, "a", "shard");
1266-
changeKey(m, "b", "subscription_match");
1267-
changeKey(m, "c", "channel");
1268-
changeKey(m, "d", "payload");
1269-
changeKey(m, "ear", "eat_after_reading");
1270-
changeKey(m, "f", "flags");
1271-
changeKey(m, "i", "issuing_client_id");
1272-
changeKey(m, "k", "subscribe_key");
1273-
changeKey(m, "s", "sequence_number");
1274-
changeKey(m, "o", "origination_timetoken");
1275-
changeKey(m, "p", "publish_timetoken");
1276-
changeKey(m, "r", "replication_map");
1277-
changeKey(m, "u", "user_metadata");
1278-
changeKey(m, "w", "waypoint_list");
1279-
return m;
1280-
}
1281-
1282-
void v2Handler(JSONObject jso, HttpRequest hreq) throws JSONException {
1283-
JSONArray messages = jso.getJSONArray("m");
1284-
for (int i = 0; i < messages.length(); i++) {
1285-
JSONObject messageObj = messages.getJSONObject(i);
1286-
String channel = messageObj.getString("c");
1287-
String sub_channel = (messageObj.isNull("b")) ? null : messageObj.getString("b");
1288-
1289-
String message = messageObj.getString("d");
1290-
1291-
SubscriptionItem chobj = null;
1292-
if (channelSubscriptions != null && sub_channel != null)
1293-
chobj = channelSubscriptions.getItem(sub_channel);
1294-
1295-
if (chobj == null && channelGroupSubscriptions != null && sub_channel != null)
1296-
chobj = channelGroupSubscriptions.getItem(sub_channel);
1297-
1298-
if (chobj == null && channelSubscriptions != null)
1299-
chobj = channelSubscriptions.getItem(channel);
1300-
1301-
if (channel.indexOf("-pnpres") > 0) {
1302-
chobj = channelSubscriptions.getItem(channel);
1303-
channel = PubnubUtil.splitString(channel, "-pnpres")[0];
1304-
1305-
}
1306-
1307-
if (chobj != null) {
1308-
Callback callback = chobj.callback;
1309-
invokeSubscribeCallbackV2(chobj.name, chobj.callback, message, expandV2Keys(messageObj),
1310-
_timetoken, hreq);
1311-
}
1312-
1313-
}
1314-
}
1315-
13161111
void v1Handler(JSONArray jsa, HttpRequest hreq) throws JSONException {
13171112

1318-
log.debug("v1handler");
13191113
JSONArray messages = new JSONArray(jsa.get(0).toString());
13201114

13211115
if (jsa.length() == 4) {
@@ -1367,29 +1161,20 @@ public void handleResponse(HttpRequest hreq, String response) {
13671161
JSONObject jso = null;
13681162

13691163
String _in_response_timetoken = "";
1370-
boolean handleV2 = false;
13711164

13721165
try {
13731166
jsa = new JSONArray(response);
13741167
_in_response_timetoken = jsa.get(1).toString();
13751168

13761169
} catch (JSONException e) {
1377-
try {
1378-
// handle V2 response
1379-
handleV2 = true;
1380-
jso = new JSONObject(response);
13811170

1382-
_in_response_timetoken = jso.getJSONObject("t").getString("t");
1383-
_region = jso.getJSONObject("t").getString("r");
1171+
if (hreq.isSubzero()) {
1172+
log.verbose("Response of subscribe 0 request. Need to do dAr process again");
1173+
_subscribe_base(false, hreq.isDar(), hreq.getWorker());
1174+
} else
1175+
_subscribe_base(false);
1176+
return;
13841177

1385-
} catch (JSONException e1) {
1386-
if (hreq.isSubzero()) {
1387-
log.verbose("Response of subscribe 0 request. Need to do dAr process again");
1388-
_subscribe_base(false, hreq.isDar(), hreq.getWorker());
1389-
} else
1390-
_subscribe_base(false);
1391-
return;
1392-
}
13931178
}
13941179

13951180
/*
@@ -1418,10 +1203,7 @@ public void handleResponse(HttpRequest hreq, String response) {
14181203
}
14191204
try {
14201205

1421-
if (handleV2)
1422-
v2Handler(jso, hreq);
1423-
else
1424-
v1Handler(jsa, hreq);
1206+
v1Handler(jsa, hreq);
14251207

14261208
} catch (JSONException e) {
14271209

@@ -1636,11 +1418,4 @@ public void unsetAuthKey() {
16361418
resubscribe();
16371419
}
16381420

1639-
public String getFilter() {
1640-
return channelSubscriptions.getFilter();
1641-
}
1642-
1643-
public void setFilter(String filter) {
1644-
channelSubscriptions.setFilter(filter);
1645-
}
16461421
}

0 commit comments

Comments
 (0)