mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Support client round robin to multiple server addresses.
Change-Id: If87dc64a485b1c8a340c5f6fa39ca09d40133e30
This commit is contained in:
@@ -23,7 +23,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
private static boolean client = false;
|
||||
private static boolean running = false;
|
||||
private static int port = DEFAULT_PORT;
|
||||
private static String ipAddress = "";
|
||||
private static String[] ipAddresses = new String[0];
|
||||
private static String persistentFilename = "networktables.ini";
|
||||
|
||||
private synchronized static void checkInit() {
|
||||
@@ -38,9 +38,12 @@ public class NetworkTable implements ITable, IRemote {
|
||||
public synchronized static void initialize() {
|
||||
if (running)
|
||||
shutdown();
|
||||
if (client)
|
||||
NetworkTablesJNI.startClient(ipAddress, port);
|
||||
else
|
||||
if (client) {
|
||||
int[] ports = new int[ipAddresses.length];
|
||||
for (int i=0; i<ipAddresses.length; i++)
|
||||
ports[i] = port;
|
||||
NetworkTablesJNI.startClient(ipAddresses, ports);
|
||||
} else
|
||||
NetworkTablesJNI.startServer(persistentFilename, "", port);
|
||||
running = true;
|
||||
}
|
||||
@@ -95,10 +98,31 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* mode
|
||||
*/
|
||||
public synchronized static void setIPAddress(final String address) {
|
||||
if (ipAddress.equals(address))
|
||||
if (ipAddresses.length == 1 && ipAddresses[0].equals(address))
|
||||
return;
|
||||
checkInit();
|
||||
ipAddress = address;
|
||||
ipAddresses = new String[1];
|
||||
ipAddresses[0] = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param addresses the adresses that network tables will connect to in
|
||||
* client mode (in round robin order)
|
||||
*/
|
||||
public synchronized static void setIPAddress(final String[] addresses) {
|
||||
if (ipAddresses.length == addresses.length) {
|
||||
boolean match = true;
|
||||
for (int i=0; i<addresses.length; i++) {
|
||||
if (!ipAddresses[i].equals(addresses[i])) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match)
|
||||
return;
|
||||
}
|
||||
checkInit();
|
||||
ipAddresses = addresses;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,7 @@ public class NetworkTablesJNI {
|
||||
public static native void startServer(String persistFilename, String listenAddress, int port);
|
||||
public static native void stopServer();
|
||||
public static native void startClient(String serverName, int port);
|
||||
public static native void startClient(String[] serverNames, int[] ports);
|
||||
public static native void stopClient();
|
||||
public static native void setUpdateRate(double interval);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user