SimpleWebSocket 类型的 setBroadcaster(Broadcaster) 在 Grizzly 中不可见 java

setBroadcaster(Broadcaster) from the type SimpleWebSocket is not visible in Grizzly java

我使用 Grizzly 在 java 中设置 websocket 服务器。我的问题是我无法通过覆盖 WebSocketApplication 将 broadcaster 设置为 websocket 以使用优化的 websocket。我按照文档描述的方式进行操作。但是我得到了那个错误。

The method setBroadcaster(Broadcaster) from the type SimpleWebSocket is not visible.

这是我的代码

public class BroadcastApplication extends WebSocketApplication { 

    private final Broadcaster broadcaster;

    public BroadcastApplication(Broadcaster broadcaster) {
        this.broadcaster = broadcaster; 
    }

    @Override public WebSocket createSocket(ProtocolHandler handler, 
            HttpRequestPacket requestPacket, WebSocketListener... listeners) {
        final DefaultWebSocket ws = (DefaultWebSocket) super.createSocket(handler, requestPacket, listeners);
        ws.setBroadcaster(broadcaster); // Got error here
        return ws;
    }

    @Override public void onMessage(WebSocket socket, String data) {
        socket.broadcast(getWebSockets(), data);
    }
}

我的 grizzly-websockets 版本是 2.3.22。欢迎任何建议。

像这样的东西应该可以工作:

public class BroadcastApplication extends WebSocketApplication { 

    private final Broadcaster broadcaster;

    public BroadcastApplication(Broadcaster broadcaster) {
        this.broadcaster = broadcaster; 
    }

    @Override
    public WebSocket createSocket(ProtocolHandler handler, 
            HttpRequestPacket requestPacket, WebSocketListener... listeners) {
        return new BroadcastWebSocket(broadcaster, handler, requestPacket, listeners);
    }

    @Override
    public void onMessage(WebSocket socket, String data) {
        socket.broadcast(getWebSockets(), data);
    }

    private static class BroadcastWebSocket extends DefaultWebSocket {

        public BroadcastWebSocket(Broadcaster broadcaster,
                ProtocolHandler protocolHandler,
                HttpRequestPacket request,
                WebSocketListener... listeners) {

            super(protocolHandler, request, listeners);
            this.broadcaster = broadcaster;
        }
    }
}