public void dispatchMessage(final WebSocketHandler handler, final NettyWebSocketConnection connection, final Executor executor, final Thread.UncaughtExceptionHandler exceptionHandler) throws UTF8Exception {

        switch (opcode) {
            case Opcodes.OPCODE_TEXT: {
                final String messageValue = utf8Output.getStringAndRecycle();
                executor.execute(new CatchingRunnable(exceptionHandler) {
                    @Override
                    protected void go() throws Throwable {
                        handler.onMessage(connection, messageValue);
                    }
                });
                return;
            }
            case Opcodes.OPCODE_BINARY: {
                final byte[] bytes = messageBytes();
                executor.execute(new CatchingRunnable(exceptionHandler) {
                    @Override
                    public void go() throws Throwable {
                        handler.onMessage(connection, bytes);
                    }
                });
                return;
            }
            case Opcodes.OPCODE_PING: {
                final byte[] bytes = messageBytes();
                executor.execute(new CatchingRunnable(exceptionHandler) {
                    @Override
                    protected void go() throws Throwable {
                        handler.onPing(connection, bytes);
                    }
                });
                return;
            }
            case Opcodes.OPCODE_PONG: {
                final byte[] bytes = messageBytes();
                executor.execute(new CatchingRunnable(exceptionHandler) {
                    @Override
                    protected void go() throws Throwable {
                        handler.onPong(connection, bytes);
                    }
                });
                return;
            }
            default:
                throw new IllegalStateException("Unexpected opcode:" + opcode);
        }
    }