class WsServer extends WebSocketServer {
    static final Logger log = LoggerFactory.getLogger(WsServer.class);
    static final WebSocketServerProps wsProps = WebSocketServerProps.getInstance();

    private final WebSocketRouter webSocketRouter = WebSocketRouter.getInstance();

    public WsServer(int port) {
        super(new InetSocketAddress(port));
    }

    public WsServer(InetAddress address, int port) {
        super(new InetSocketAddress(address, port));
    }

    @Override
    public void onStart() {
        LogUtil.global().info("Server:Websocket onStart...");
    }


    private WebSocketImpl getSession(WebSocket conn) {
        return getSession(conn, null);
    }

    private WebSocketImpl getSession(WebSocket conn, ClientHandshake shake) {
        WebSocketImpl session = conn.getAttachment();

        if (session == null) {
            //直接从附件拿，不一定可靠
            session = new WebSocketImpl(conn);
            conn.setAttachment(session);

            if (shake != null) {
                Iterator<String> httpFields = shake.iterateHttpFields();
                while (httpFields.hasNext()) {
                    String name = httpFields.next();
                    session.param(name, shake.getFieldValue(name));
                }
            }
        }

        return session;
    }

    @Override
    public void onOpen(WebSocket conn, ClientHandshake shake) {
        WebSocketImpl webSocket = getSession(conn, shake);
        webSocketRouter.getListener().onOpen(webSocket);

        //设置闲置超时
        if (wsProps.getIdleTimeout() > 0) {
            webSocket.setIdleTimeout(wsProps.getIdleTimeout());
        }
    }

    @Override
    public void onClose(WebSocket conn, int i, String s, boolean b) {
        WebSocketImpl webSocket = getSession(conn);
        if (webSocket.isClosed()) {
            return;
        } else {
            webSocket.close();
        }

        webSocketRouter.getListener().onClose(webSocket);
    }

    @Override
    public void onWebsocketPing(WebSocket conn, Framedata f) {
        super.onWebsocketPing(conn, f);

        WebSocketImpl webSocket = getSession(conn);
        if (webSocket != null) {
            webSocket.onReceive();
        }
    }

    @Override
    public void onWebsocketPong(WebSocket conn, Framedata f) {
        super.onWebsocketPong(conn, f);

        WebSocketImpl webSocket = getSession(conn);
        if (webSocket != null) {
            webSocket.onReceive();
        }
    }

    @Override
    public void onMessage(WebSocket conn, String data) {<FILL_FUNCTION_BODY>}

    @Override
    public void onMessage(WebSocket conn, ByteBuffer data) {
        try {
            WebSocketImpl webSocket = getSession(conn);
            webSocket.onReceive();

            webSocketRouter.getListener().onMessage(webSocket, data);
        } catch (Throwable e) {
            log.warn(e.getMessage(), e);
        }
    }

    @Override
    public void onError(WebSocket conn, Exception ex) {
        try {
            WebSocketImpl webSocket = getSession(conn);
            webSocketRouter.getListener().onError(webSocket, ex);
        } catch (Throwable e) {
            log.warn(e.getMessage(), e);
        }
    }
}

        try {
            WebSocketImpl webSocket = getSession(conn);
            webSocket.onReceive();

            webSocketRouter.getListener().onMessage(webSocket, data);
        } catch (Throwable e) {
            log.warn(e.getMessage(), e);
        }
    
<methods>public void <init>() ,public void <init>(java.net.InetSocketAddress) ,public void <init>(java.net.InetSocketAddress, int) ,public void <init>(java.net.InetSocketAddress, List<org.java_websocket.drafts.Draft>) ,public void <init>(java.net.InetSocketAddress, int, List<org.java_websocket.drafts.Draft>) ,public void <init>(java.net.InetSocketAddress, int, List<org.java_websocket.drafts.Draft>, Collection<org.java_websocket.WebSocket>) ,public void broadcast(java.lang.String) ,public void broadcast(byte[]) ,public void broadcast(java.nio.ByteBuffer) ,public void broadcast(byte[], Collection<org.java_websocket.WebSocket>) ,public void broadcast(java.nio.ByteBuffer, Collection<org.java_websocket.WebSocket>) ,public void broadcast(java.lang.String, Collection<org.java_websocket.WebSocket>) ,public java.nio.ByteBuffer createBuffer() ,public java.net.InetSocketAddress getAddress() ,public Collection<org.java_websocket.WebSocket> getConnections() ,public List<org.java_websocket.drafts.Draft> getDraft() ,public java.net.InetSocketAddress getLocalSocketAddress(org.java_websocket.WebSocket) ,public int getMaxPendingConnections() ,public int getPort() ,public java.net.InetSocketAddress getRemoteSocketAddress(org.java_websocket.WebSocket) ,public final org.java_websocket.WebSocketFactory getWebSocketFactory() ,public abstract void onClose(org.java_websocket.WebSocket, int, java.lang.String, boolean) ,public void onCloseInitiated(org.java_websocket.WebSocket, int, java.lang.String) ,public void onClosing(org.java_websocket.WebSocket, int, java.lang.String, boolean) ,public abstract void onError(org.java_websocket.WebSocket, java.lang.Exception) ,public abstract void onMessage(org.java_websocket.WebSocket, java.lang.String) ,public void onMessage(org.java_websocket.WebSocket, java.nio.ByteBuffer) ,public abstract void onOpen(org.java_websocket.WebSocket, org.java_websocket.handshake.ClientHandshake) ,public abstract void onStart() ,public final void onWebsocketClose(org.java_websocket.WebSocket, int, java.lang.String, boolean) ,public void onWebsocketCloseInitiated(org.java_websocket.WebSocket, int, java.lang.String) ,public void onWebsocketClosing(org.java_websocket.WebSocket, int, java.lang.String, boolean) ,public final void onWebsocketError(org.java_websocket.WebSocket, java.lang.Exception) ,public final void onWebsocketMessage(org.java_websocket.WebSocket, java.lang.String) ,public final void onWebsocketMessage(org.java_websocket.WebSocket, java.nio.ByteBuffer) ,public final void onWebsocketOpen(org.java_websocket.WebSocket, org.java_websocket.handshake.Handshakedata) ,public final void onWriteDemand(org.java_websocket.WebSocket) ,public void run() ,public void setMaxPendingConnections(int) ,public final void setWebSocketFactory(org.java_websocket.WebSocketServerFactory) ,public void start() ,public void stop() throws java.lang.InterruptedException,public void stop(int) throws java.lang.InterruptedException,public void stop(int, java.lang.String) throws java.lang.InterruptedException<variables>private static final int AVAILABLE_PROCESSORS,private final java.net.InetSocketAddress address,private BlockingQueue<java.nio.ByteBuffer> buffers,private final Collection<org.java_websocket.WebSocket> connections,protected List<org.java_websocket.server.WebSocketServer.WebSocketWorker> decoders,private List<org.java_websocket.drafts.Draft> drafts,private List<org.java_websocket.WebSocketImpl> iqueue,private final java.util.concurrent.atomic.AtomicBoolean isclosed,private final org.slf4j.Logger log,private int maxPendingConnections,private int queueinvokes,private final java.util.concurrent.atomic.AtomicInteger queuesize,private java.nio.channels.Selector selector,private java.lang.Thread selectorthread,private java.nio.channels.ServerSocketChannel server,private org.java_websocket.WebSocketServerFactory wsf