Class Topic
- Direct Known Subclasses:
BooleanArrayTopic
,BooleanTopic
,DoubleArrayTopic
,DoubleTopic
,FloatArrayTopic
,FloatTopic
,IntegerArrayTopic
,IntegerTopic
,ProtobufTopic
,RawTopic
,StringArrayTopic
,StringTopic
,StructArrayTopic
,StructTopic
public class Topic extends Object
-
Field Summary
Fields Modifier and Type Field Description protected int
m_handle
NetworkTables handle.protected NetworkTableInstance
m_inst
NetworkTables instance. -
Method Summary
Modifier and Type Method Description void
deleteProperty(String name)
Deletes a property.boolean
equals(Object other)
boolean
exists()
Determines if the topic is currently being published.GenericPublisher
genericPublish(String typeString, PubSubOption... options)
Create a new publisher to the topic.GenericPublisher
genericPublishEx(String typeString, String properties, PubSubOption... options)
Create a new publisher to the topic, with type string and initial properties.GenericSubscriber
genericSubscribe(PubSubOption... options)
Create a new subscriber to the topic.GenericSubscriber
genericSubscribe(String typeString, PubSubOption... options)
Create a new subscriber to the topic.GenericEntry
getGenericEntry(PubSubOption... options)
Create a new generic entry for the topic.GenericEntry
getGenericEntry(String typeString, PubSubOption... options)
Create a new generic entry for the topic.int
getHandle()
Gets the native handle for the topic.TopicInfo
getInfo()
Gets combined information about the topic.NetworkTableInstance
getInstance()
Gets the instance for the topic.String
getName()
Gets the name of the topic.String
getProperties()
Gets all topic properties as a JSON object string.String
getProperty(String name)
Gets the current value of a property (as a JSON string).NetworkTableType
getType()
Gets the type of the topic.String
getTypeString()
Gets the type string of the topic.int
hashCode()
boolean
isCached()
Returns whether the topic's last value is stored.boolean
isPersistent()
Returns whether the value is persistent through server restarts.boolean
isRetained()
Returns whether the topic is retained by server when there are no publishers.boolean
isValid()
Determines if the native handle is valid.void
setCached(boolean cached)
Allow storage of the topic's last value, allowing the value to be read (and not just accessed through event queues and listeners).void
setPersistent(boolean persistent)
Make value persistent through server restarts.void
setProperties(String properties)
Updates multiple topic properties.void
setProperty(String name, String value)
Sets a property value.void
setRetained(boolean retained)
Make the server retain the topic even when there are no publishers.
-
Field Details
-
Method Details
-
isValid
Determines if the native handle is valid.- Returns:
- True if the native handle is valid, false otherwise.
-
getHandle
Gets the native handle for the topic.- Returns:
- Native handle
-
getInstance
Gets the instance for the topic.- Returns:
- Instance
-
getName
Gets the name of the topic.- Returns:
- the topic's name
-
getType
Gets the type of the topic.- Returns:
- the topic's type
-
getTypeString
Gets the type string of the topic. This may have more information than the numeric type (especially for raw values).- Returns:
- the topic's type
-
getInfo
Gets combined information about the topic.- Returns:
- Topic information
-
setPersistent
Make value persistent through server restarts.- Parameters:
persistent
- True for persistent, false for not persistent.
-
isPersistent
Returns whether the value is persistent through server restarts.- Returns:
- True if the value is persistent.
-
setRetained
Make the server retain the topic even when there are no publishers.- Parameters:
retained
- True for retained, false for not retained.
-
isRetained
Returns whether the topic is retained by server when there are no publishers.- Returns:
- True if the topic is retained.
-
setCached
Allow storage of the topic's last value, allowing the value to be read (and not just accessed through event queues and listeners).- Parameters:
cached
- True for cached, false for not cached.
-
isCached
Returns whether the topic's last value is stored.- Returns:
- True if the topic is cached.
-
exists
Determines if the topic is currently being published.- Returns:
- True if the topic exists, false otherwise.
-
getProperty
Gets the current value of a property (as a JSON string).- Parameters:
name
- property name- Returns:
- JSON string; "null" if the property does not exist.
-
setProperty
Sets a property value.- Parameters:
name
- property namevalue
- property value (JSON string)- Throws:
IllegalArgumentException
- if properties is not parseable as JSON
-
deleteProperty
Deletes a property. Has no effect if the property does not exist.- Parameters:
name
- property name
-
getProperties
Gets all topic properties as a JSON object string. Each key in the object is the property name, and the corresponding value is the property value.- Returns:
- JSON string
-
setProperties
Updates multiple topic properties. Each key in the passed-in object is the name of the property to add/update, and the corresponding value is the property value to set for that property. Null values result in deletion of the corresponding property.- Parameters:
properties
- JSON object string with keys to add/update/delete- Throws:
IllegalArgumentException
- if properties is not a JSON object
-
genericSubscribe
Create a new subscriber to the topic.The subscriber is only active as long as the returned object is not closed.
- Parameters:
options
- subscribe options- Returns:
- subscriber
-
genericSubscribe
Create a new subscriber to the topic.The subscriber is only active as long as the returned object is not closed.
Subscribers that do not match the published data type do not return any values. To determine if the data type matches, use the appropriate Topic functions.
- Parameters:
typeString
- type stringoptions
- subscribe options- Returns:
- subscriber
-
genericPublish
Create a new publisher to the topic.The publisher is only active as long as the returned object is not closed.
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
- Parameters:
typeString
- type stringoptions
- publish options- Returns:
- publisher
-
genericPublishEx
public GenericPublisher genericPublishEx(String typeString, String properties, PubSubOption... options)Create a new publisher to the topic, with type string and initial properties.The publisher is only active as long as the returned object is not closed.
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
- Parameters:
typeString
- type stringproperties
- JSON propertiesoptions
- publish options- Returns:
- publisher
- Throws:
IllegalArgumentException
- if properties is not a JSON object
-
getGenericEntry
Create a new generic entry for the topic.Entries act as a combination of a subscriber and a weak publisher. The subscriber is active as long as the entry is not closed. The publisher is created when the entry is first written to, and remains active until either unpublish() is called or the entry is closed.
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
- Parameters:
options
- publish and/or subscribe options- Returns:
- entry
-
getGenericEntry
Create a new generic entry for the topic.Entries act as a combination of a subscriber and a weak publisher. The subscriber is active as long as the entry is not closed. The publisher is created when the entry is first written to, and remains active until either unpublish() is called or the entry is closed.
It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.
- Parameters:
typeString
- type stringoptions
- publish and/or subscribe options- Returns:
- entry
-
equals
-
hashCode
-