-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
2,388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.slj.mqtt.tree; | ||
|
||
import java.util.Set; | ||
|
||
public class Example { | ||
public static void main(String[] args) throws MqttTreeException, MqttTreeLimitExceededException { | ||
MqttTree<String> tree = new MqttTree<String>(MqttTree.DEFAULT_SPLIT, true); | ||
|
||
tree.withMaxPathSegments(1024); | ||
tree.withMaxMembersAtLevel(1024); | ||
|
||
tree.subscribe("/this/is/a/topic", "ClientId1", "ClientId2"); | ||
|
||
tree.subscribe("/this/+/a/topic", "ClientId3"); | ||
|
||
tree.subscribe("/this/#", "ClientId4"); | ||
|
||
Set<String> m = tree.search("/this/is/a/topic"); | ||
|
||
System.out.println(String.format("matching search had [%s] members", m.size())); | ||
|
||
m = tree.search("/is/a/different/topic"); | ||
|
||
System.out.println(String.format("non-matching search had [%s] members", m.size())); | ||
|
||
tree.unsubscribe("/this/is/a/topic", "ClientId2"); | ||
|
||
m = tree.search("/this/is/a/topic"); | ||
|
||
System.out.println(String.format("matching search had [%s] members", m.size())); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
mqtt-sn-core/src/main/java/org/slj/mqtt/tree/IMqttTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.slj.mqtt.tree; | ||
|
||
import java.util.Set; | ||
|
||
public interface IMqttTree<T> { | ||
|
||
MqttTreeNode<T> subscribe(final String path, final T... members) | ||
throws MqttTreeException, MqttTreeLimitExceededException; | ||
|
||
boolean unsubscribe(final String path, T member) | ||
throws MqttTreeException; | ||
|
||
Set<T> search(final String path); | ||
|
||
boolean hasMembers(final String path); | ||
|
||
boolean hasPath(String path); | ||
|
||
MqttTreeNode<T> getRootNode(); | ||
|
||
void visit(MqttTreeNodeVisitor visitor); | ||
|
||
Set<String> getDistinctPaths(boolean considerMembership); | ||
|
||
int countDistinctPaths(boolean considerMembership); | ||
|
||
int getBranchCount(); | ||
} |
17 changes: 17 additions & 0 deletions
17
mqtt-sn-core/src/main/java/org/slj/mqtt/tree/ISearchableMqttTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.slj.mqtt.tree; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Provides index methods to search the Mqtt Tree character by character. | ||
*/ | ||
public interface ISearchableMqttTree<T> extends IMqttTree<T>{ | ||
|
||
/** | ||
* Use the radix index to perform quick lookup of your topic | ||
* @param path - any path prefix you would like to search | ||
* @param max - max results returned by the index | ||
* @return The nodes returned by the prefix search | ||
*/ | ||
List<MqttTreeNode<T>> prefixSearch(String path, int max); | ||
} |
Oops, something went wrong.