public final class NetworkTableInstance extends java.lang.Object
getDefault()
) is
always available, and is intended for the common case when there is only
a single NetworkTables instance being used in the program.
Additional instances can be created with the create()
function.
A reference must be kept to the NetworkTableInstance returned by this
function to keep it from being garbage collected.Modifier and Type | Field and Description |
---|---|
static int |
kDefaultPort
The default port that network tables operates on.
|
static int |
kNetModeClient |
static int |
kNetModeFailure |
static int |
kNetModeNone
Client/server mode flag values (as returned by
getNetworkMode() ). |
static int |
kNetModeServer |
static int |
kNetModeStarting |
Modifier and Type | Method and Description |
---|---|
int |
addConnectionListener(java.util.function.Consumer<ConnectionNotification> listener,
boolean immediateNotify)
Add a connection listener.
|
int |
addEntryListener(NetworkTableEntry entry,
java.util.function.Consumer<EntryNotification> listener,
int flags)
Add a listener for a particular entry.
|
int |
addEntryListener(java.lang.String prefix,
java.util.function.Consumer<EntryNotification> listener,
int flags)
Add a listener for all entries starting with a certain prefix.
|
int |
addLogger(java.util.function.Consumer<LogMessage> func,
int minLevel,
int maxLevel)
Add logger callback function.
|
static NetworkTableInstance |
create()
Create an instance.
|
void |
createRpc(NetworkTableEntry entry,
java.util.function.Consumer<RpcAnswer> callback)
Create a callback-based RPC entry point.
|
void |
deleteAllEntries()
Deletes ALL keys in ALL subtables (except persistent values).
|
boolean |
equals(java.lang.Object o) |
void |
flush()
Flushes all updated values immediately to the network.
|
void |
free()
Destroys the instance (if created by
create() ). |
ConnectionInfo[] |
getConnections()
Gets information on the currently established network connections.
|
static NetworkTableInstance |
getDefault()
Get global default instance.
|
NetworkTableEntry[] |
getEntries(java.lang.String prefix,
int types)
Get entries starting with the given prefix.
|
NetworkTableEntry |
getEntry(java.lang.String name)
Gets the entry for a key.
|
EntryInfo[] |
getEntryInfo(java.lang.String prefix,
int types)
Get information about entries starting with the given prefix.
|
int |
getHandle()
Gets the native handle for the entry.
|
int |
getNetworkMode()
Get the current network mode.
|
NetworkTable |
getTable(java.lang.String key)
Gets the table with the specified key.
|
int |
hashCode() |
boolean |
isConnected()
Return whether or not the instance is connected to another node.
|
boolean |
isValid()
Determines if the native handle is valid.
|
java.lang.String[] |
loadEntries(java.lang.String filename,
java.lang.String prefix)
Load table values from a file.
|
java.lang.String[] |
loadPersistent(java.lang.String filename)
Loads persistent keys from a file.
|
void |
removeConnectionListener(int listener)
Remove a connection listener.
|
void |
removeEntryListener(int listener)
Remove an entry listener.
|
void |
removeLogger(int logger)
Remove a logger.
|
void |
saveEntries(java.lang.String filename,
java.lang.String prefix)
Save table values to a file.
|
void |
savePersistent(java.lang.String filename)
Saves persistent keys to a file.
|
void |
setNetworkIdentity(java.lang.String name)
Set the network identity of this node.
|
void |
setServer(java.lang.String serverName)
Sets server address and port for client (without restarting client).
|
void |
setServer(java.lang.String[] serverNames)
Sets server addresses and port for client (without restarting client).
|
void |
setServer(java.lang.String[] serverNames,
int port)
Sets server addresses and port for client (without restarting client).
|
void |
setServer(java.lang.String[] serverNames,
int[] ports)
Sets server addresses and ports for client (without restarting client).
|
void |
setServer(java.lang.String serverName,
int port)
Sets server address and port for client (without restarting client).
|
void |
setServerTeam(int team)
Sets server addresses and port for client (without restarting client).
|
void |
setServerTeam(int team,
int port)
Sets server addresses and port for client (without restarting client).
|
void |
setUpdateRate(double interval)
Set the periodic update rate.
|
void |
startClient()
Starts a client.
|
void |
startClient(java.lang.String serverName)
Starts a client using the specified server and the default port
|
void |
startClient(java.lang.String[] serverNames)
Starts a client using the specified servers and default port.
|
void |
startClient(java.lang.String[] serverNames,
int port)
Starts a client using the specified servers and port number.
|
void |
startClient(java.lang.String[] serverNames,
int[] ports)
Starts a client using the specified (server, port) combinations.
|
void |
startClient(java.lang.String serverName,
int port)
Starts a client using the specified server and port
|
void |
startClientTeam(int team)
Starts a client using commonly known robot addresses for the specified
team using the default port number.
|
void |
startClientTeam(int team,
int port)
Starts a client using commonly known robot addresses for the specified
team.
|
void |
startDSClient()
Starts requesting server address from Driver Station.
|
void |
startDSClient(int port)
Starts requesting server address from Driver Station.
|
void |
startServer()
Starts a server using the networktables.ini as the persistent file,
using the default listening address and port.
|
void |
startServer(java.lang.String persistFilename)
Starts a server using the specified persistent filename, using the default
listening address and port.
|
void |
startServer(java.lang.String persistFilename,
java.lang.String listenAddress)
Starts a server using the specified filename and listening address,
using the default port.
|
void |
startServer(java.lang.String persistFilename,
java.lang.String listenAddress,
int port)
Starts a server using the specified filename, listening address, and port.
|
void |
stopClient()
Stops the client if it is running.
|
void |
stopDSClient()
Stops requesting server address from Driver Station.
|
void |
stopServer()
Stops the server if it is running.
|
boolean |
waitForConnectionListenerQueue(double timeout)
Wait for the connection listener queue to be empty.
|
boolean |
waitForEntryListenerQueue(double timeout)
Wait for the entry listener queue to be empty.
|
boolean |
waitForLoggerQueue(double timeout)
Wait for the incoming log event queue to be empty.
|
boolean |
waitForRpcCallQueue(double timeout)
Wait for the incoming RPC call queue to be empty.
|
public static final int kNetModeNone
getNetworkMode()
).
This is a bitmask.public static final int kNetModeServer
public static final int kNetModeClient
public static final int kNetModeStarting
public static final int kNetModeFailure
public static final int kDefaultPort
public boolean isValid()
public static NetworkTableInstance getDefault()
public static NetworkTableInstance create()
public int getHandle()
public NetworkTableEntry getEntry(java.lang.String name)
name
- Keypublic NetworkTableEntry[] getEntries(java.lang.String prefix, int types)
prefix
- entry name required prefix; only entries whose name
starts with this string are returnedtypes
- bitmask of types; 0 is treated as a "don't care"public EntryInfo[] getEntryInfo(java.lang.String prefix, int types)
prefix
- entry name required prefix; only entries whose name
starts with this string are returnedtypes
- bitmask of types; 0 is treated as a "don't care"public NetworkTable getTable(java.lang.String key)
key
- the key namepublic void deleteAllEntries()
public int addEntryListener(java.lang.String prefix, java.util.function.Consumer<EntryNotification> listener, int flags)
prefix
- UTF-8 string prefixlistener
- listener to addflags
- EntryListenerFlags
bitmaskpublic int addEntryListener(NetworkTableEntry entry, java.util.function.Consumer<EntryNotification> listener, int flags)
entry
- the entrylistener
- listener to addflags
- EntryListenerFlags
bitmaskpublic void removeEntryListener(int listener)
listener
- Listener handle to removepublic boolean waitForEntryListenerQueue(double timeout)
timeout
- timeout, in seconds. Set to 0 for non-blocking behavior,
or a negative value to block indefinitelypublic int addConnectionListener(java.util.function.Consumer<ConnectionNotification> listener, boolean immediateNotify)
listener
- Listener to addimmediateNotify
- Notify listener of all existing connectionspublic void removeConnectionListener(int listener)
listener
- Listener handle to removepublic boolean waitForConnectionListenerQueue(double timeout)
timeout
- timeout, in seconds. Set to 0 for non-blocking behavior,
or a negative value to block indefinitelypublic void createRpc(NetworkTableEntry entry, java.util.function.Consumer<RpcAnswer> callback)
entry
- the entrycallback
- callback functionpublic boolean waitForRpcCallQueue(double timeout)
timeout
- timeout, in seconds. Set to 0 for non-blocking behavior,
or a negative value to block indefinitelypublic void setNetworkIdentity(java.lang.String name)
name
- identity to advertisepublic int getNetworkMode()
public void startServer()
public void startServer(java.lang.String persistFilename)
persistFilename
- the name of the persist file to usepublic void startServer(java.lang.String persistFilename, java.lang.String listenAddress)
persistFilename
- the name of the persist file to uselistenAddress
- the address to listen on, or empty to listen on any
addresspublic void startServer(java.lang.String persistFilename, java.lang.String listenAddress, int port)
persistFilename
- the name of the persist file to uselistenAddress
- the address to listen on, or empty to listen on any
addressport
- port to communicate overpublic void stopServer()
public void startClient()
public void startClient(java.lang.String serverName)
serverName
- server namepublic void startClient(java.lang.String serverName, int port)
serverName
- server nameport
- port to communicate overpublic void startClient(java.lang.String[] serverNames)
serverNames
- array of server namespublic void startClient(java.lang.String[] serverNames, int port)
serverNames
- array of server namesport
- port to communicate overpublic void startClient(java.lang.String[] serverNames, int[] ports)
serverNames
- array of server namesports
- array of port numberspublic void startClientTeam(int team)
team
- team numberpublic void startClientTeam(int team, int port)
team
- team numberport
- port to communicate overpublic void stopClient()
public void setServer(java.lang.String serverName)
serverName
- server namepublic void setServer(java.lang.String serverName, int port)
serverName
- server nameport
- port to communicate overpublic void setServer(java.lang.String[] serverNames)
serverNames
- array of server namespublic void setServer(java.lang.String[] serverNames, int port)
serverNames
- array of server namesport
- port to communicate overpublic void setServer(java.lang.String[] serverNames, int[] ports)
serverNames
- array of server namesports
- array of port numberspublic void setServerTeam(int team)
team
- team numberpublic void setServerTeam(int team, int port)
team
- team numberport
- port to communicate overpublic void startDSClient()
public void startDSClient(int port)
port
- server port to use in combination with IP from DSpublic void stopDSClient()
public void setUpdateRate(double interval)
interval
- update interval in seconds (range 0.01 to 1.0)public void flush()
public ConnectionInfo[] getConnections()
public boolean isConnected()
public void savePersistent(java.lang.String filename) throws PersistentException
filename
- file namePersistentException
- if error saving filepublic java.lang.String[] loadPersistent(java.lang.String filename) throws PersistentException
filename
- file namePersistentException
- if error reading filepublic void saveEntries(java.lang.String filename, java.lang.String prefix) throws PersistentException
filename
- filenameprefix
- save only keys starting with this prefixPersistentException
- if error saving filepublic java.lang.String[] loadEntries(java.lang.String filename, java.lang.String prefix) throws PersistentException
filename
- filenameprefix
- load only keys starting with this prefixPersistentException
- if error saving filepublic int addLogger(java.util.function.Consumer<LogMessage> func, int minLevel, int maxLevel)
func
- log callback functionminLevel
- minimum log levelmaxLevel
- maximum log levelpublic void removeLogger(int logger)
logger
- Logger handle to removepublic boolean waitForLoggerQueue(double timeout)
timeout
- timeout, in seconds. Set to 0 for non-blocking behavior,
or a negative value to block indefinitelypublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object