Skip to content

Commit

Permalink
Tree into core
Browse files Browse the repository at this point in the history
  • Loading branch information
simon622 committed Sep 18, 2023
1 parent 5a172a8 commit 4c3034b
Show file tree
Hide file tree
Showing 23 changed files with 2,388 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mqtt-sn-core/src/main/java/org/slj/mqtt/tree/Example.java
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 mqtt-sn-core/src/main/java/org/slj/mqtt/tree/IMqttTree.java
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();
}
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);
}
Loading

0 comments on commit 4c3034b

Please sign in to comment.