org.apache.tinkerpop.gremlin.server.handler

## Class MultiTaskSession

- java.lang.Object
- - org.apache.tinkerpop.gremlin.server.handler.AbstractSession
  - - org.apache.tinkerpop.gremlin.server.handler.MultiTaskSession

- All Implemented Interfaces:
    AutoCloseable, Runnable, Session

      public class MultiTaskSession
      extends AbstractSession

  A `Session` implementation that queues tasks given to it and executes them in a serial fashion within the same thread which thus allows multiple tasks to be executed in the same transaction. The first `SessionTask` to execute is supplied on the constructor and additional ones may be added as they arrive with `submitTask(SessionTask)` where they will be added to a queue where they will await execution in the thread bound to this session.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.tinkerpop.gremlin.server.handler.AbstractSession

      `AbstractSession.CloseReason`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected BlockingQueue<SessionTask>` | `queue`

    - ### Fields inherited from class org.apache.tinkerpop.gremlin.server.handler.AbstractSession

      `aliasesUsedBySession, closeReason, graphManager, maintainStateAfterException, sessions, sessionThread`

    - ### Fields inherited from interface org.apache.tinkerpop.gremlin.server.handler.Session

      `evalOpTimer, traversalOpTimer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MultiTaskSession(SessionTask initialSessionTask, String sessionId, ConcurrentMap<String,Session> sessions)` Creates a new `MultiTaskSession` object providing the initial starting `SessionTask` that gets executed by the session when it starts.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` This method stops incoming requests from being added to the session queue.
    `GremlinScriptEngine` | `getScriptEngine(SessionTask sessionTask, String language)` Gets the script engine specific to this session which is dependent on the `Settings.useCommonEngineForSessions` configuration.
    `protected Bindings` | `getWorkerBindings()`
    `protected GremlinExecutor` | `initializeGremlinExecutor(SessionTask sessionTask)`
    `boolean` | `isAcceptingTasks()` Determines if this session can accept additional tasks or not.
    `void` | `run()`
    `boolean` | `submitTask(SessionTask sessionTask)` Adds a task for session to complete.
    `String` | `toString()`

    - ### Methods inherited from class org.apache.tinkerpop.gremlin.server.handler.AbstractSession

      `cancel, closeTransaction, closeTransaction, closeTransactionSafely, closeTransactionSafely, determineIfTemporaryException, fromBytecode, fromScript, generateResponseMetaData, generateStatusAttributes, getActualTimeoutLengthWhenClosed, getCloseReason, getSessionId, handleException, handleGraphOperation, handleIterator, isBoundTo, isTransactionManaged, iterateComplete, makeFrame, mergeBindingsFromRequest, process, setSessionCancelFuture, setSessionFuture, startTransaction, triggerTimeout`

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

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

- - ### Field Detail

    - #### queue

          protected final BlockingQueue<SessionTask> queue

  - ### Constructor Detail

    - #### MultiTaskSession

          public MultiTaskSession(SessionTask initialSessionTask,
                                  String sessionId,
                                  ConcurrentMap<String,Session> sessions)

      Creates a new `MultiTaskSession` object providing the initial starting `SessionTask` that gets executed by the session when it starts.
      Parameters:
        `initialSessionTask` - The tasks that starts the session.
        `sessionId` - The id of the session
        `sessions` - The session id to `Session` instances mapping

  - ### Method Detail

    - #### getScriptEngine

          public GremlinScriptEngine getScriptEngine(SessionTask sessionTask,
                                                     String language)

      Gets the script engine specific to this session which is dependent on the `Settings.useCommonEngineForSessions` configuration.
      Overrides:
        `getScriptEngine` in class `AbstractSession`

    - #### isAcceptingTasks

          public boolean isAcceptingTasks()

      Description copied from interface: `Session`
      Determines if this session can accept additional tasks or not.

    - #### submitTask

          public boolean submitTask(SessionTask sessionTask)
                             throws RejectedExecutionException

      Description copied from interface: `Session`
      Adds a task for session to complete.
      Throws:
        `RejectedExecutionException` - if the task cannot be queued

    - #### run

          public void run()

    - #### close

          public void close()

      This method stops incoming requests from being added to the session queue. It then cancels the session lifetime timeout and then calls `super#close()` which will then interrupt this `run()` which will clear out remaining requests in the queue. This latter part of the close, where the interruption is concerned, is an asynchronous operation and will not block as it finishes its processing in the "gremlinPool" thread that was originally handling the work.
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `AbstractSession`

    - #### getWorkerBindings

          protected Bindings getWorkerBindings()
                                        throws SessionException

      Overrides:
        `getWorkerBindings` in class `AbstractSession`
      Throws:
        `SessionException`

    - #### initializeGremlinExecutor

          protected GremlinExecutor initializeGremlinExecutor(SessionTask sessionTask)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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