org.apache.tinkerpop.gremlin.server.op

## Class AbstractEvalOpProcessor

- java.lang.Object
- - org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor
  - - org.apache.tinkerpop.gremlin.server.op.AbstractEvalOpProcessor

- All Implemented Interfaces:
    AutoCloseable, OpProcessor
  Direct Known Subclasses:
    SessionOpProcessor, StandardOpProcessor

      public abstract class AbstractEvalOpProcessor
      extends AbstractOpProcessor

  A base `OpProcessor` implementation that helps with operations that deal with script evaluation functions.
  Author:
    Stephen Mallette (http://stephen.genoprime.com)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `AbstractEvalOpProcessor.BindingSupplier`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `CONFIG_MAX_PARAMETERS` The maximum number of parameters that can be passed on a script evaluation request.
    `static int` | `DEFAULT_MAX_PARAMETERS` Default number of parameters allowed on a script evaluation request.
    `static Timer` | `evalOpTimer`
    `protected static Set<String>` | `INVALID_BINDINGS_KEYS` This may or may not be the full set of invalid binding keys.
    `protected int` | `maxParameters`

    - ### Fields inherited from class org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor

      `manageTransactions`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractEvalOpProcessor(boolean manageTransactions)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `evalOpInternal(Context context, Supplier<GremlinExecutor> gremlinExecutorSupplier, AbstractEvalOpProcessor.BindingSupplier bindingsSupplier)` A generalized implementation of the "eval" operation.
    `protected void` | `evalOpInternal(ResponseHandlerContext rhc, Supplier<GremlinExecutor> gremlinExecutorSupplier, AbstractEvalOpProcessor.BindingSupplier bindingsSupplier)` A variant of `evalOpInternal(Context, Supplier, BindingSupplier)` that is suitable for use in situations when multiple threads may produce `final` response messages concurrently.
    `abstract ThrowingConsumer<Context>` | `getEvalOp()` Provides an operation for evaluating a Gremlin script.
    `ThrowingConsumer<Context>` | `select(Context ctx)` Given the context (which contains the RequestMessage), return back a Consumer function that will be executed with the context.
    `abstract Optional<ThrowingConsumer<Context>>` | `selectOther(RequestMessage requestMessage)` A sub-class may have additional "ops" that it will service.
    `protected Optional<ThrowingConsumer<Context>>` | `validateEvalMessage(RequestMessage message)`

    - ### Methods inherited from class org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor

      `attemptCommit, attemptRollback, generateMetaData, handleIterator, handleIterator, isForceFlushed, iterateComplete, makeFrame, makeFrame`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.tinkerpop.gremlin.server.OpProcessor

      `getName, init`

    - ### Methods inherited from interface java.lang.AutoCloseable

      `close`

- - ### Field Detail

    - #### evalOpTimer

          public static final Timer evalOpTimer

    - #### CONFIG_MAX_PARAMETERS

          public static final String CONFIG_MAX_PARAMETERS

      The maximum number of parameters that can be passed on a script evaluation request.
      See Also:
        Constant Field Values

    - #### DEFAULT_MAX_PARAMETERS

          public static final int DEFAULT_MAX_PARAMETERS

      Default number of parameters allowed on a script evaluation request.
      See Also:
        Constant Field Values

    - #### maxParameters

          protected int maxParameters

    - #### INVALID_BINDINGS_KEYS

          protected static final Set<String> INVALID_BINDINGS_KEYS

      This may or may not be the full set of invalid binding keys. It is dependent on the static imports made to Gremlin Server. This should get rid of the worst offenders though and provide a good message back to the calling client.

      Use of `toUpperCase()` on the accessor values of `T` solves an issue where the `ScriptEngine` ignores private scope on `T` and imports static fields.

  - ### Constructor Detail

    - #### AbstractEvalOpProcessor

          protected AbstractEvalOpProcessor(boolean manageTransactions)

  - ### Method Detail

    - #### getEvalOp

          public abstract ThrowingConsumer<Context> getEvalOp()

      Provides an operation for evaluating a Gremlin script.

    - #### selectOther

          public abstract Optional<ThrowingConsumer<Context>> selectOther(RequestMessage requestMessage)
                                                                   throws OpProcessorException

      A sub-class may have additional "ops" that it will service. Calls to `select(Context)` that are not handled will be passed to this method to see if the sub-class can service the requested op code.
      Throws:
        `OpProcessorException`

    - #### select

          public ThrowingConsumer<Context> select(Context ctx)
                                           throws OpProcessorException

      Description copied from interface: `OpProcessor`
      Given the context (which contains the RequestMessage), return back a Consumer function that will be executed with the context. A typical implementation will simply check the "op" field on the RequestMessage and return the Consumer function for that particular operation.
      Throws:
        `OpProcessorException`

    - #### validateEvalMessage

          protected Optional<ThrowingConsumer<Context>> validateEvalMessage(RequestMessage message)
                                                                     throws OpProcessorException

      Throws:
        `OpProcessorException`

    - #### evalOpInternal

          protected void evalOpInternal(Context context,
                                        Supplier<GremlinExecutor> gremlinExecutorSupplier,
                                        AbstractEvalOpProcessor.BindingSupplier bindingsSupplier)
                                 throws OpProcessorException

      A generalized implementation of the "eval" operation. It handles script evaluation and iteration of results so as to write `ResponseMessage` objects down the Netty pipeline. It also handles script timeouts, iteration timeouts, metrics and building bindings. Note that result iteration is delegated to the `AbstractOpProcessor.handleIterator(org.apache.tinkerpop.gremlin.server.Context, java.util.Iterator)` method, so those extending this class could override that method for better control over result iteration.
      Parameters:
        `context` - The current Gremlin Server `Context`
        `gremlinExecutorSupplier` - A function that returns the `GremlinExecutor` to use in executing the script evaluation.
        `bindingsSupplier` - A function that returns the `Bindings` to provide to the `GremlinExecutor.eval(java.lang.String)` method.
      Throws:
        `OpProcessorException`
      See Also:
        `evalOpInternal(ResponseHandlerContext, Supplier, BindingSupplier)`

    - #### evalOpInternal

          protected void evalOpInternal(ResponseHandlerContext rhc,
                                        Supplier<GremlinExecutor> gremlinExecutorSupplier,
                                        AbstractEvalOpProcessor.BindingSupplier bindingsSupplier)
                                 throws OpProcessorException

      A variant of `evalOpInternal(Context, Supplier, BindingSupplier)` that is suitable for use in situations when multiple threads may produce `final` response messages concurrently.
      Throws:
        `OpProcessorException`
      See Also:
        `evalOpInternal(Context, Supplier, BindingSupplier)`

Copyright © 2013–2018 Apache Software Foundation. All rights reserved.