Skip to content

Commit

Permalink
some optimization around topic evictions processing
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Oct 11, 2019
1 parent cda1359 commit da31054
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
30 changes: 14 additions & 16 deletions tinodesdk/src/main/java/co/tinode/tinodesdk/Tinode.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,24 +558,22 @@ private void dispatchPacket(String message) throws Exception {
}
}
}
if (pkt.ctrl.code == 205 && "evicted".equals(pkt.ctrl.text)) {
Topic topic = getTopic(pkt.ctrl.topic);
if (topic != null) {
Topic topic = getTopic(pkt.ctrl.topic);
if (topic != null) {
if (pkt.ctrl.code == 205 && "evicted".equals(pkt.ctrl.text)) {
boolean unsub = pkt.ctrl.getBoolParam("unsub", false);
topic.topicLeft(unsub, pkt.ctrl.code, pkt.ctrl.text);
}
} else if ("data".equals(pkt.ctrl.getStringParam("what", null))) {
// All data has been delivered.
Topic topic = getTopic(pkt.ctrl.topic);
if (topic != null) {
topic.allMessagesReceived(pkt.ctrl.getIntParam("count", 0));
}
} else if ("sub".equals(pkt.ctrl.getStringParam("what", null))) {
// The topic has no subscriptions.
Topic topic = getTopic(pkt.ctrl.topic);
if (topic != null) {
// Trigger Listener.onSubsUpdated.
topic.routeMetaSub(null);
} else {
String what = pkt.ctrl.getStringParam("what", null);
if (what != null) {
if ("data".equals(what)) {
// All data has been delivered.
topic.allMessagesReceived(pkt.ctrl.getIntParam("count", 0));
} else if ("sub".equals(what)) {
// The topic has no subscriptions. Trigger Listener.onSubsUpdated.
topic.allSubsReceived();
}
}
}
}
} else if (pkt.meta != null) {
Expand Down
12 changes: 8 additions & 4 deletions tinodesdk/src/main/java/co/tinode/tinodesdk/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -1581,11 +1581,10 @@ protected void processSub(Subscription<SP, SR> newsub) {
}

protected void routeMetaSub(MsgServerMeta<DP, DR, SP, SR> meta) {
if (meta != null) {
for (Subscription<SP, SR> newsub : meta.sub) {
processSub(newsub);
}
for (Subscription<SP, SR> newsub : meta.sub) {
processSub(newsub);
}

if (mListener != null) {
mListener.onSubsUpdated();
}
Expand Down Expand Up @@ -1642,6 +1641,11 @@ protected void allMessagesReceived(Integer count) {
}
}

protected void allSubsReceived() {
if (mListener != null) {
mListener.onSubsUpdated();
}
}
protected void routePres(MsgServerPres pres) {
MsgServerPres.What what = MsgServerPres.parseWhat(pres.what);
Subscription<SP, SR> sub;
Expand Down

0 comments on commit da31054

Please sign in to comment.