Class Topic

java.lang.Object
edu.wpi.first.networktables.Topic
Direct Known Subclasses:
BooleanArrayTopic, BooleanTopic, DoubleArrayTopic, DoubleTopic, FloatArrayTopic, FloatTopic, IntegerArrayTopic, IntegerTopic, RawTopic, StringArrayTopic, StringTopic

public class Topic
extends Object
NetworkTables Topic.
  • Field Details

  • Method Details

    • isValid

      public boolean isValid()
      Determines if the native handle is valid.
      Returns:
      True if the native handle is valid, false otherwise.
    • getHandle

      public int getHandle()
      Gets the native handle for the topic.
      Returns:
      Native handle
    • getInstance

      Gets the instance for the topic.
      Returns:
      Instance
    • getName

      public String 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

      public TopicInfo getInfo()
      Gets combined information about the topic.
      Returns:
      Topic information
    • setPersistent

      public void setPersistent​(boolean persistent)
      Make value persistent through server restarts.
      Parameters:
      persistent - True for persistent, false for not persistent.
    • isPersistent

      public boolean isPersistent()
      Returns whether the value is persistent through server restarts.
      Returns:
      True if the value is persistent.
    • setRetained

      public void setRetained​(boolean retained)
      Make the server retain the topic even when there are no publishers.
      Parameters:
      retained - True for retained, false for not retained.
    • isRetained

      public boolean isRetained()
      Returns whether the topic is retained by server when there are no publishers.
      Returns:
      True if the topic is retained.
    • exists

      public boolean exists()
      Determines if the topic is currently being published.
      Returns:
      True if the topic exists, false otherwise.
    • getProperty

      public String getProperty​(String name)
      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

      public void setProperty​(String name, String value)
      Sets a property value.
      Parameters:
      name - property name
      value - property value (JSON string)
      Throws:
      IllegalArgumentException - if properties is not parseable as JSON
    • deleteProperty

      public void deleteProperty​(String name)
      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

      public void setProperties​(String properties)
      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

      public GenericSubscriber genericSubscribe​(String typeString, PubSubOption... options)
      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 string
      options - subscribe options
      Returns:
      subscriber
    • genericPublish

      public GenericPublisher genericPublish​(String typeString, PubSubOption... options)
      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 string
      options - 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 string
      properties - JSON properties
      options - publish options
      Returns:
      publisher
      Throws:
      IllegalArgumentException - if properties is not a JSON object
    • getGenericEntry

      public GenericEntry getGenericEntry​(PubSubOption... options)
      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

      public GenericEntry getGenericEntry​(String typeString, PubSubOption... options)
      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 string
      options - publish and/or subscribe options
      Returns:
      entry
    • equals

      public boolean equals​(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object