Skip to content

Commit

Permalink
PMD fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Feb 17, 2024
1 parent 49cb64c commit 50245fa
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import javafx.collections.ObservableMap;

@UiHints(showConnectionIndicator = false) // same host as NetworkTables plugin, so no need to duplicate that information
public final class CameraServerSourceType extends SourceType {
public final class CameraServerSourceType extends SourceType implements AutoCloseable {

public static final CameraServerSourceType INSTANCE = new CameraServerSourceType();

Expand All @@ -35,12 +35,13 @@ public final class CameraServerSourceType extends SourceType {
private final ObservableMap<String, Object> availableSources = FXCollections.observableHashMap();

private final MultiSubscriber subscriber;
private final int listener;

private CameraServerSourceType() {
super("CameraServer", true, "camera_server://", CameraServerSourceType::forName);
NetworkTableInstance inst = NetworkTableInstance.getDefault();
subscriber = new MultiSubscriber(inst, new String[] {"/CameraPublisher"}, PubSubOption.hidden(true));
inst.addListener(
listener = inst.addListener(
subscriber,
EnumSet.of(
NetworkTableEvent.Kind.kUnpublish,
Expand All @@ -66,6 +67,12 @@ private CameraServerSourceType() {
}));
}

@Override
public void close() {
subscriber.close();
NetworkTableInstance.getDefault().removeListener(listener);
}

public static CameraServerSource forName(String name) {
return INSTANCE.sources.computeIfAbsent(name, CameraServerSource::new);
}
Expand Down

0 comments on commit 50245fa

Please sign in to comment.