diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkReceiver.java b/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkReceiver.java index ff66844d9a..a48a1fd3c6 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkReceiver.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkReceiver.java @@ -3,6 +3,7 @@ import java.util.function.Consumer; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; /** * Manages the interface between the {@link PublishAnnotatedOperation} and the actual network @@ -18,7 +19,8 @@ public abstract class NetworkReceiver implements AutoCloseable { * @param path The path of the object to get */ public NetworkReceiver(String path) { - checkArgument(!path.isEmpty(), "Name cannot be an empty string"); + checkNotNull(path, "Path cannot be null"); + checkArgument(!path.isEmpty(), "Path cannot be an empty string"); this.path = path; } diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/networktables/NTManager.java b/core/src/main/java/edu/wpi/grip/core/operations/network/networktables/NTManager.java index f9485b5cff..4ffa01f351 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/networktables/NTManager.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/networktables/NTManager.java @@ -178,9 +178,9 @@ public void close() { NetworkTablesJNI.removeEntryListener(entryListenerFunctionUid); synchronized (NetworkTable.class) { - // This publisher is no longer used. + // This receiver is no longer used. if (NTManager.count.addAndGet(-1) == 0) { - // We are the last publisher so shut it down + // We are the last resource using NetworkTables so shut it down NetworkTable.shutdown(); } } @@ -247,7 +247,7 @@ public void close() { synchronized (NetworkTable.class) { // This publisher is no longer used. if (NTManager.count.addAndGet(-1) == 0) { - // We are the last publisher so shut it down + // We are the last resource using NetworkTables so shut it down NetworkTable.shutdown(); } } diff --git a/core/src/main/java/edu/wpi/grip/core/sources/NetworkTableEntrySource.java b/core/src/main/java/edu/wpi/grip/core/sources/NetworkTableEntrySource.java index 682cb1b534..a1d2d35b04 100644 --- a/core/src/main/java/edu/wpi/grip/core/sources/NetworkTableEntrySource.java +++ b/core/src/main/java/edu/wpi/grip/core/sources/NetworkTableEntrySource.java @@ -10,6 +10,7 @@ import edu.wpi.grip.core.sockets.SocketHints; import edu.wpi.grip.core.util.ExceptionWitness; +import com.google.common.base.CaseFormat; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -24,12 +25,13 @@ /** * Provides a way to get a {@link Types Type} from a NetworkTable that GRIP is connected to. */ -@XStreamAlias("grip:NetworkValue") +@XStreamAlias("grip:NetworkTableValue") public class NetworkTableEntrySource extends Source { private static final String PATH_PROPERTY = "networktable_path"; private static final String TYPE_PROPERTY = "BOOLEAN"; + private final EventBus eventBus; private final OutputSocket output; private final String path; private final Types type; @@ -46,7 +48,7 @@ public enum Types { @Override public String toString() { - return super.toString().charAt(0) + super.toString().substring(1).toLowerCase(); + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); } } @@ -75,12 +77,11 @@ public String toString() { @Assisted String path, @Assisted Types type) { super(exceptionWitnessFactory); + this.eventBus = eventBus; this.path = path; this.type = type; networkReceiver = networkReceiverFactory.create(path); output = osf.create(createOutputSocket(type)); - - networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this))); } @Override @@ -117,7 +118,7 @@ public Properties getProperties() { @Override public void initialize() { - updateOutputSockets(); + networkReceiver.addListener(o -> eventBus.post(new SourceHasPendingUpdateEvent(this))); } @Subscribe @@ -141,7 +142,7 @@ private static SocketHint createOutputSocket(Types type) { case STRING: return SocketHints.Outputs.createStringSocketHint(Types.STRING.toString(), ""); default: - throw new IllegalArgumentException("Invalid NetworkTable source type"); + throw new IllegalArgumentException(type + " is an invalid NetworkTable source type"); } } } \ No newline at end of file