Sitelet https://github.com/snehamendiratta/java/commit/26ad167169468ba6e07ba56e371e5c1fd5ea7e39
Skip to content

Commit 26ad167

Browse files
committed
update wildcard channels behaviour
1 parent 38d096c commit 26ad167

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ abstract class PubnubCore {
4949

5050
protected static String PRESENCE_SUFFIX = "-pnpres";
5151
protected static String WILDCARD_SUFFIX = "*";
52+
protected static String WILDCARD_PRESENCE_SUFFIX = WILDCARD_SUFFIX + PRESENCE_SUFFIX;
5253
protected static String VERSION = "";
5354
private Random generator = new Random();
5455

@@ -2317,7 +2318,6 @@ private void _subscribe(Hashtable args) {
23172318
for (int i = 0; i < channelList.length; i++) {
23182319
String channel = channelList[i];
23192320

2320-
// HACK: wrap '*-pnpres' channels with cutted-off suffix
23212321
if (channel.endsWith(WILDCARD_SUFFIX + PRESENCE_SUFFIX)) {
23222322
String messagesChannel = channel.substring(0, channel.indexOf(PRESENCE_SUFFIX));
23232323

@@ -2379,9 +2379,9 @@ private boolean isWorkerDead(HttpRequest hreq) {
23792379
return (hreq == null || hreq.getWorker() == null)?false:hreq.getWorker()._die;
23802380
}
23812381
private void _subscribe_base(boolean fresh, boolean dar, Worker worker) {
2382-
String channelString = channelSubscriptions.getItemStringSorted();
2382+
String channelString = channelSubscriptions.getItemString(WILDCARD_PRESENCE_SUFFIX);
23832383
String groupString = channelGroupSubscriptions.getItemString();
2384-
String[] channelsArray = channelSubscriptions.getItemNames();
2384+
String[] channelsArray = channelSubscriptions.getItemNames(WILDCARD_PRESENCE_SUFFIX);
23852385
String[] groupsArray = channelGroupSubscriptions.getItemNames();
23862386

23872387
if (channelsArray.length <= 0 && groupsArray.length <= 0) {
@@ -2558,7 +2558,7 @@ public String getTimetoken() {
25582558
}
25592559

25602560
/**
2561-
* Logic of 4-elements success response is to complex, so it's excluded into separate method
2561+
* Handle 4-elements success response
25622562
*
25632563
* @param thirdString element of JSON response
25642564
* @param fourthString element of JSON response

‎java/srcPubnubApi/com/pubnub/api/PubnubUtilCore.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,22 @@ public static String joinString(String[] sourceArray, String delimiter) {
9494
* @return , string array with hash keys string
9595
*/
9696
public static synchronized String[] hashtableKeysToArray(Hashtable ht) {
97+
return hashtableKeysToArray(ht, null);
98+
}
99+
100+
public static synchronized String[] hashtableKeysToArray(Hashtable ht, String exclude) {
97101
Vector v = new Vector();
98102
String[] sa = null;
99103
int count = 0;
100104

101105
Enumeration e = ht.keys();
102106
while (e.hasMoreElements()) {
103107
String s = (String) e.nextElement();
108+
109+
if (exclude != null && s.indexOf(exclude) != -1) {
110+
continue;
111+
}
112+
104113
v.addElement(s);
105114
count++;
106115
}

‎java/srcPubnubApi/com/pubnub/api/Subscriptions.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,28 @@ public SubscriptionItem getItem(String name) {
4747
}
4848

4949
public String[] getItemNames() {
50+
return getItemNames(null);
51+
}
5052

51-
return PubnubUtil.hashtableKeysToArray(items);
53+
public String[] getItemNames(String filter) {
54+
return PubnubUtil.hashtableKeysToArray(items, filter);
5255
}
5356

5457
public String getItemStringNoPresence() {
55-
return PubnubUtil.hashTableKeysToDelimitedString(items, ",", "-pnpres");
58+
return PubnubUtil.hashTableKeysToDelimitedString(items, ",", Pubnub.PRESENCE_SUFFIX);
5659
}
5760

61+
// TODO: review & remove
5862
public String getItemStringSorted() {
59-
return PubnubUtil.hashTableKeysToSortedSuffixString(items, ",", "-pnpres");
63+
return PubnubUtil.hashTableKeysToSortedSuffixString(items, ",", Pubnub.PRESENCE_SUFFIX);
6064
}
6165

6266
public String getItemString() {
63-
return PubnubUtil.hashTableKeysToDelimitedString(items, ",");
67+
return getItemString(null);
68+
}
69+
70+
public String getItemString(String filter) {
71+
return PubnubUtil.hashTableKeysToDelimitedString(items, ",", filter);
6472
}
6573

6674
public void invokeConnectCallbackOnItems(Object message) {

‎java/srcTest/com/pubnub/api/WildcardSubscribeTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public void connectCallback(String channel, Object message) {
125125
// subscribe#connect event will not be triggered, because presence event already implicitly added it to the list
126126
TestHelper.SimpleCallback cb2 = new TestHelper.SimpleCallback(latch4) {};
127127

128+
Thread.sleep(1000);
129+
128130
pubnub.subscribe(channel + ".*", cb2);
129131
pubnub.presence(channel + ".*", cb);
130132

0 commit comments

Comments
 (0)