Skip to content
Browse files

Add the unsubscribe method to the future and blocking apis

  • Loading branch information...
1 parent b07cfb6 commit aaad5c4c2ed421153a78028a2f9e4a458caf7d63 @chirino chirino committed Feb 5, 2012
View
6 .gitignore
@@ -27,3 +27,9 @@ target
# OS Stuff
*.swp
.DS_Store
+
+mqtt-client/dump.txt
+mqtt-client/in/
+mqtt-client/lib/
+mqtt-client/usage.txt
+
View
8 mqtt-client/src/main/java/org/fusesource/mqtt/client/BlockingConnection.java
@@ -57,6 +57,14 @@ public void disconnect() throws Exception {
return this.next.subscribe(topics).await();
}
+ public void unsubscribe(final String[] topics) throws Exception {
+ this.next.unsubscribe(topics).await();
+ }
+
+ public void unsubscribe(final UTF8Buffer[] topics) throws Exception {
+ this.next.unsubscribe(topics).await();
+ }
+
public void publish(final UTF8Buffer topic, final Buffer payload, final QoS qos, final boolean retain) throws Exception {
this.next.publish(topic, payload, qos, retain).await();
}
View
18 mqtt-client/src/main/java/org/fusesource/mqtt/client/FutureConnection.java
@@ -115,6 +115,24 @@ public void run() {
});
return future;
}
+
+ public Future<Void> unsubscribe(final String[] topics) {
+ UTF8Buffer[] buffers = new UTF8Buffer[topics.length];
+ for (int i = 0; i < buffers.length; i++) {
+ buffers[i] = new UTF8Buffer(topics[i]);
+ }
+ return unsubscribe(buffers);
+ }
+
+ public Future<Void> unsubscribe(final UTF8Buffer[] topics) {
+ final Promise<Void> future = new Promise<Void>();
+ next.getDispatchQueue().execute(new Runnable() {
+ public void run() {
+ next.unsubscribe(topics, future);
+ }
+ });
+ return future;
+ }
public Future<Void> publish(final String topic, final byte[] payload, final QoS qos, final boolean retain) {
return publish(utf8(topic), new Buffer(payload), qos, retain);
View
4 mqtt-client/src/main/java/org/fusesource/mqtt/codec/SUBACK.java
@@ -87,8 +87,8 @@ public SUBACK messageId(short messageId) {
@Override
public String toString() {
return "SUBACK{" +
- "grantedQos=" + grantedQos +
- ", messageId=" + Arrays.asList(messageId) +
+ "grantedQos=" + Arrays.toString(grantedQos) +
+ ", messageId=" +messageId +
'}';
}
}

0 comments on commit aaad5c4

Please sign in to comment.
Something went wrong with that request. Please try again.