All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webbitserver.handler.logging.LoggingWebSocketHandler Maven / Gradle / Ivy

There is a newer version: 0.4.15
Show newest version
package org.webbitserver.handler.logging;

import org.webbitserver.WebSocketConnection;
import org.webbitserver.WebSocketHandler;

class LoggingWebSocketHandler implements WebSocketHandler {

    private final LogSink logSink;
    private final WebSocketConnection loggingConnection;
    private final WebSocketHandler handler;

    LoggingWebSocketHandler(LogSink logSink, WebSocketConnection loggingConnection, WebSocketHandler handler) {
        this.logSink = logSink;
        this.loggingConnection = loggingConnection;
        this.handler = handler;
    }

    @Override
    public void onOpen(WebSocketConnection connection) throws Exception {
        logSink.webSocketConnectionOpen(connection);
        handler.onOpen(loggingConnection);
    }

    @Override
    public void onClose(WebSocketConnection connection) throws Exception {
        logSink.webSocketConnectionClose(connection);
        logSink.httpEnd(connection.httpRequest());
        handler.onClose(loggingConnection);
    }

    @Override
    public void onMessage(WebSocketConnection connection, String message) throws Throwable {
        logSink.webSocketInboundData(connection, message);
        handler.onMessage(loggingConnection, message);
    }

    @Override
    public void onMessage(WebSocketConnection connection, byte[] message) throws Throwable {
        logSink.webSocketInboundData(connection, message);
        handler.onMessage(loggingConnection, message);
    }

    @Override
    public void onPong(WebSocketConnection connection, String message) throws Throwable {
        logSink.webSocketInboundPong(connection, message);
        handler.onPong(loggingConnection, message);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy