001package jmri.server.json.loconet;
002
003import com.fasterxml.jackson.databind.JsonNode;
004import java.io.IOException;
005import jmri.JmriException;
006import jmri.server.json.JsonConnection;
007import jmri.server.json.JsonException;
008import jmri.server.json.JsonRequest;
009import jmri.server.json.JsonSocketService;
010
011/**
012 * Minimal WebSocket handling for "loconetSlotUsage" -- a one-shot query,
013 * not something a client subscribes to, so every message (GET or LIST)
014 * is answered the same way as the HTTP GET, with no held subscription
015 * state to release on close.
016 *
017 * A real, minimal implementation is used here rather than a null socket
018 * service, since JsonClientHandler registers whatever getSocketService()
019 * returns into every type's dispatch set unconditionally -- a null entry
020 * there would NPE the first time a WebSocket client sent this type.
021 *
022 * @author Andrew Deak Copyright (C) 2026
023 */
024public class JsonLoconetSlotUsageSocketService extends JsonSocketService<JsonLoconetSlotUsageHttpService> {
025
026    public JsonLoconetSlotUsageSocketService(JsonConnection connection) {
027        super(connection, new JsonLoconetSlotUsageHttpService(connection.getObjectMapper()));
028    }
029
030    @Override
031    public void onMessage(String type, JsonNode data, JsonRequest request) throws IOException, JmriException, JsonException {
032        connection.sendMessage(service.doGet(type, "", data, request), request.id);
033    }
034
035    @Override
036    public void onList(String type, JsonNode data, JsonRequest request) throws IOException, JmriException, JsonException {
037        connection.sendMessage(service.doGet(type, "", data, request), request.id);
038    }
039
040    @Override
041    public void onClose() {
042        // no subscription state held
043    }
044}