Skip to content

Commit

Permalink
Merge pull request #32 from SarojMaharjan/master
Browse files Browse the repository at this point in the history
Solution for issue #19
  • Loading branch information
NaikSoftware authored Feb 1, 2017
2 parents 7fc11fa + 6e6c8ea commit 6c58850
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .idea/markdown-navigator/profiles_settings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

15 changes: 7 additions & 8 deletions lib/src/main/java/ua/naiksoftware/stomp/client/StompClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -157,7 +156,7 @@ public Observable<StompMessage> topic(String destinationPath, List<StompHeader>
if (subscribersSet == null) {
subscribersSet = new HashSet<>();
mSubscribers.put(destinationPath, subscribersSet);
subscribePath(destinationPath, headerList);
subscribePath(destinationPath, headerList).subscribe();
}
subscribersSet.add(subscriber);

Expand All @@ -169,16 +168,16 @@ public Observable<StompMessage> topic(String destinationPath, List<StompHeader>
set.remove(subscriber);
if (set.size() < 1) {
mSubscribers.remove(dest);
unsubscribePath(dest);
unsubscribePath(dest).subscribe();
}
}
}
}
});
}

private void subscribePath(String destinationPath, List<StompHeader> headerList) {
if (destinationPath == null) return;
private Observable<Void> subscribePath(String destinationPath, List<StompHeader> headerList) {
if (destinationPath == null) return Observable.empty();
String topicId = UUID.randomUUID().toString();

if (mTopics == null) mTopics = new HashMap<>();
Expand All @@ -188,16 +187,16 @@ private void subscribePath(String destinationPath, List<StompHeader> headerList)
headers.add(new StompHeader(StompHeader.DESTINATION, destinationPath));
headers.add(new StompHeader(StompHeader.ACK, DEFAULT_ACK));
if (headerList != null) headers.addAll(headerList);
send(new StompMessage(StompCommand.SUBSCRIBE,
return send(new StompMessage(StompCommand.SUBSCRIBE,
headers, null));
}


private void unsubscribePath(String dest) {
private Observable<Void> unsubscribePath(String dest) {
String topicId = mTopics.get(dest);
Log.d(TAG, "Unsubscribe path: " + dest + " id: " + topicId);

send(new StompMessage(StompCommand.UNSUBSCRIBE,
return send(new StompMessage(StompCommand.UNSUBSCRIBE,
Collections.singletonList(new StompHeader(StompHeader.ID, topicId)), null));
}

Expand Down

0 comments on commit 6c58850

Please sign in to comment.