Skip to content

Commit 77031b9

Browse files
committed
remove redundant queries from ChannelGroup constructor
1 parent 8e7f321 commit 77031b9

3 files changed

Lines changed: 3 additions & 91 deletions

File tree

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package com.pubnub.api;
22

33
public class Channel extends SubscriptionItem{
4-
public ChannelGroup group;
5-
6-
public Channel(String channel, Callback callback, ChannelGroup group) {
7-
super(channel, callback);
8-
9-
this.group = group;
10-
}
11-
124
public Channel(String channel, Callback callback) {
135
super(channel, callback);
146
}
Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,7 @@
11
package com.pubnub.api;
22

3-
import org.json.JSONArray;
4-
import org.json.JSONException;
5-
import org.json.JSONObject;
6-
7-
import java.util.ArrayList;
8-
import java.util.concurrent.CountDownLatch;
9-
103
public class ChannelGroup extends SubscriptionItem{
11-
ArrayList channels = new ArrayList();
12-
13-
public static class RetrieveChannelsCallback extends Callback {
14-
private CountDownLatch latch;
15-
private JSONArray channels;
16-
17-
RetrieveChannelsCallback(CountDownLatch latch) {
18-
this.latch = latch;
19-
}
20-
21-
public void successCallback(String channel, Object channels) {
22-
try {
23-
this.channels = ((JSONObject) channels).getJSONArray("channels");
24-
} catch (JSONException e) {
25-
this.channels = new JSONArray();
26-
}
27-
this.latch.countDown();
28-
}
29-
30-
public void errorCallback(String channel, PubnubError error) {
31-
this.channels = new JSONArray();
32-
this.latch.countDown();
33-
}
34-
35-
public JSONArray getChannels() {
36-
return channels;
37-
}
4+
ChannelGroup(String name, Callback callback) {
5+
super(name, callback);
386
}
39-
40-
ChannelGroup(String name, Callback callback, PubnubCore pubnub) {
41-
CountDownLatch latch = new CountDownLatch(1);
42-
43-
this.name = name;
44-
this.callback = callback;
45-
this.connected = false;
46-
47-
RetrieveChannelsCallback cb = new RetrieveChannelsCallback(latch);
48-
pubnub.channelGroup(name, cb);
49-
50-
try {
51-
latch.await();
52-
} catch (InterruptedException e) {
53-
if (callback != null) {
54-
callback.errorCallback(
55-
name,
56-
PubnubError.getErrorObject(
57-
PubnubError.PNERROBJ_INTERNAL_ERROR,
58-
"Failed to retrieve " + name + "'s channel list"
59-
)
60-
);
61-
}
62-
}
63-
64-
JSONArray channelNames = cb.getChannels();
65-
66-
for (int i = 0; i < channelNames.length(); i++) {
67-
try {
68-
channels.add(channelNames.get(i).toString());
69-
} catch (JSONException e) {
70-
if (callback != null) {
71-
callback.errorCallback(
72-
name,
73-
PubnubError.getErrorObject(
74-
PubnubError.PNERROBJ_INTERNAL_ERROR,
75-
"Failed to retrieve " + name + "'s channel list"
76-
)
77-
);
78-
}
79-
}
80-
}
81-
}
82-
83-
public ArrayList getChannels() {
84-
return channels;
85-
}
86-
877
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ private void _subscribe(Hashtable args) {
23252325
ChannelGroup channelGroupObj = (ChannelGroup) channelGroupSubscriptions.getItem(group);
23262326

23272327
if (channelGroupObj == null) {
2328-
ChannelGroup chg = new ChannelGroup(group, callback, this);
2328+
ChannelGroup chg = new ChannelGroup(group, callback);
23292329

23302330
channelGroupSubscriptions.addItem(chg);
23312331
}

0 commit comments

Comments
 (0)