public abstract class TopicSelector extends Object
When a Client subscribes to Topics (either on connection or after) or unsubscribes from Topics then the Topics can be specified as Topic selector patterns enabling more than one Topic to be selected.
Selectors may also be used when selecting a set of Topic for other purposes.
Topics are potentially hierarchic in nature and a Topic name may therefore be
specified as a hierarchic name with each level of the hierarchy separated by
'/' (e.g. 'A/B/C'). This is represented by the simplest pattern of type
TopicSelector.Type.NAME
.
A Topic selector pattern of type TopicSelector.Type.PATTERNS
is similar to a Topic
name but each element may be specified as a regular expression pattern which
is to match with names at that level of the hierarchy. For example, 'A+/B'
would match with any topic called 'B' within any top level parent Topic that
starts with 'A' (e.g. A/B, AA/B, Accounts/B etc).
A Topic selector pattern of type TopicSelector.Type.PATTERN
is one which supplies a
regular expression without any embedded name separators ('/') and in this
case is applied to the whole of a hierarchic Topic name so a pattern of ".+3"
would match with any Topic that ends with "3" regardless of the number of
levels of Topic hierarchy. If the regex pattern itself needs to contain a '/'
then it needs to be escaped within the expression. For example
".*\x2FABC" instead of "/ABC".
The regular expression syntax that is supported is defined by the Java
Pattern
class.
If a Topic selector (name or regular expression pattern) ends with '/' then it means that all Topics in the Topic hierarchy below the selected topic(s). So 'A/B/C/' would mean all topics in the hierarchy below the topic A/B/C. If you want to indicate the selected Topic(s) AND all Topics below in the hierarchy then the specifier should end with '//'. So 'A/B/C+//' would select every Topic that starts with a 'C' within Topic A/B plus all Topics below them in the hierarchy.
Modifier and Type | Class and Description |
---|---|
static class |
TopicSelector.Type
The selector type
|
Modifier | Constructor and Description |
---|---|
protected |
TopicSelector(String selectorString,
boolean selectsAllBelow,
boolean selectsAllInclusive)
Create a Topic Selector
|
Modifier and Type | Method and Description |
---|---|
static void |
boostrap(com.pushtechnology.diffusion.threads.ServerThreadPools serverThreadPools) |
boolean |
equals(Object obj) |
String |
getTopicName()
Returns the Topic name if this is a Topic Name Selector (i.e.
|
abstract TopicSelector.Type |
getType()
Returns the selector type
|
int |
hashCode() |
boolean |
isSimpleTopicNameSelector()
Is the selector a simple topic name selector that selects only a named
topic and not it's children.
|
static boolean |
isTopicName(String name)
Checks if a supplied string is a valid topic name (as opposed to a topic
selector).
|
abstract boolean |
isTopicNameSelector()
Does this selector refer to a specific Topic.
|
static boolean |
isValidSelector(String selector)
Check if the supplied string is a valid topic selector.
|
static boolean |
isValidTopicNameCharacter(char character)
Checks if a supplied character is allowed in a full Topic name.
|
static boolean |
isValidTopicNodeName(String topicName)
Validates a topic node name to ensure that it does not contain invalid
characters.
|
static boolean |
isValidTopicNodeNameCharacter(char character)
Checks if a supplied character is allowed in a Topic node name.
|
abstract boolean |
matches(String topicName)
This does a match to check if a specified topic name (or name subset)
matches with the selector.
|
static TopicSelector |
parse(String selector)
Parses a topic selector string to create a TopicSelector object.
|
abstract Set<Topic> |
select(TopicTreeNode node)
Deprecated.
|
boolean |
selectsAllBelow()
Selects all below?
|
boolean |
selectsAllInclusive()
Selects all below inclusive?
|
boolean |
selectsChildren()
This indicates whether the selector selects the children of any selected
Topic also.
|
String |
toString()
Returns a String representation of the selector that is compatible with
the
parse(String) method. |
protected TopicSelector(String selectorString, boolean selectsAllBelow, boolean selectsAllInclusive)
selectsAllBelow
- true if selector selects all belowselectsAllInclusive
- true if selects all below and itselfpublic static void boostrap(com.pushtechnology.diffusion.threads.ServerThreadPools serverThreadPools)
public static TopicSelector parse(String selector) throws TopicInvalidException
selector
- the selector stringTopicInvalidException
- if the selector string is invalidpublic static boolean isTopicName(String name)
This validates a full hierarchic topic name (e.g. A/B/C) to ensure that it is correctly structured and each element is a valid topic node name.
name
- the hierarchic topic name to validate which can be a simple
topic name or a name representing a topic within a topic tree
where the individual topic names are separated by topic name
delimiters.public static boolean isValidTopicNodeName(String topicName)
A topic name may comprise any UTF-8 encodable character except ',' '!' or any of the regular expression metacharacters.
This validates a topic node name and not a full hierarchic topic name and thus would reject a name that contained topic name delimiters.
topicName
- the topic node namepublic static boolean isValidTopicNodeNameCharacter(char character)
character
- the character to checkpublic static boolean isValidTopicNameCharacter(char character)
This is the same as isValidTopicNodeNameCharacter(char)
except
that the name delimiter
is also
permitted.
character
- the character to checkpublic static boolean isValidSelector(String selector)
selector
- the selector stringpublic abstract TopicSelector.Type getType()
public final boolean isSimpleTopicNameSelector()
topic name selector
and
does not select children
.public abstract boolean isTopicNameSelector()
This will return true even if the selector selects a Topic and/or its children.
public String getTopicName()
isTopicNameSelector()
returns true).public final boolean selectsChildren()
selectsAllBelow()
or
selectsAllInclusive()
is true.public final boolean selectsAllBelow()
public final boolean selectsAllInclusive()
@Deprecated public abstract Set<Topic> select(TopicTreeNode node)
TopicTreeNode.getTopics(TopicSelector)
node
- the nodepublic abstract boolean matches(String topicName)
topicName
- the topic name which must be a valid hierarchic topic
name.public final String toString()
parse(String)
method.toString
in class Object
Object.toString()
Copyright © 2016 Push Technology Ltd. All Rights Reserved.