package com.tinkerpop.gremlin.server;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Timer;
import com.tinkerpop.gremlin.server.util.MetricManager;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Consumer;

import static com.codahale.metrics.MetricRegistry.name;

/**
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public interface OpProcessor {
    static final Logger opProcessorLogger = LoggerFactory.getLogger(OpProcessor.class);
    static final Counter errorCounter = MetricManager.INSTANCE.getCounter(name(GremlinServer.class, "errors"));

    public String getName();
    public Consumer<Context> select(final Context ctx);

    public static Consumer<Context> text(final String message) {
        return (context) -> context.getChannelHandlerContext().channel().write(
                new TextWebSocketFrame(String.format("%s>>%s", context.getRequestMessage().requestId, message)));
    }

    public static Consumer<Context> error(final String message) {
        opProcessorLogger.warn("Error handled with this response: {}", message);
        errorCounter.inc();
        return (context) -> context.getChannelHandlerContext().channel().write(new TextWebSocketFrame(message));
    }
}

@@ -382,16 +382,96 @@
 e;%0A%0A/**%0A
+ * Interface for providing commands that websocket requests will respond to.%0A *%0A
  * @auth
@@ -765,89 +765,567 @@
     
-public String getName();%0A    public Consumer%3CContext%3E select(final Context ctx);%0A
+/**%0A     * The name of the processor which requests must refer to %22processor%22 field on a request.%0A     */%0A    public String getName();%0A%0A    /**%0A     * Given the context (which contains the RequestMessage), return back a Consumer function that will be%0A     * executed with the context.  A typical implementation will simply check the %22op%22 field on the RequestMessage%0A     * and return the Consumer function for that particular operation.%0A     */%0A    public Consumer%3CContext%3E select(final Context ctx);%0A%0A    /**%0A     * Writes a response message as text.%0A     */
 %0A   
@@ -1587,16 +1587,203 @@
 %0A    %7D%0A%0A
+    /**%0A     * Writes an error response message.  All errors should be written to the client via this method as it increments%0A     * the error counter metrics for Gremlin Server.%0A     */%0A
     publ

Update javadoc on OpProcessor.