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
ASession
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 firstSessionTask
to execute is supplied on the constructor and additional ones may be added as they arrive withsubmitTask(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 Description protected BlockingQueue<SessionTask>
queue
-
Fields inherited from class org.apache.tinkerpop.gremlin.server.handler.AbstractSession
aliasesUsedBySession, closeReason, graphManager, maintainStateAfterException, sessions, sessionTaskStarted, sessionThread
-
Fields inherited from interface org.apache.tinkerpop.gremlin.server.handler.Session
evalOpTimer, traversalOpTimer
-
-
Constructor Summary
Constructors Constructor Description MultiTaskSession(SessionTask initialSessionTask, String sessionId, ConcurrentMap<String,Session> sessions)
Creates a newMultiTaskSession
object providing the initial startingSessionTask
that gets executed by the session when it starts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theSettings.useCommonEngineForSessions
configuration.protected Bindings
getWorkerBindings()
protected GremlinExecutor
initializeGremlinExecutor(SessionTask sessionTask)
boolean
isAcceptingTasks()
Determines if this session can accept additional tasks or not.void
run()
void
sendTimeoutResponseForUncommencedTask()
Respond to the client with the specific timeout response for this Session implementation.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, determineIfSpecialException, fromBytecode, fromScript, generateResponseMetaData, generateStatusAttributes, getActualTimeoutLengthWhenClosed, getCloseReason, getSessionId, handleException, handleGraphOperation, handleIterator, isBoundTo, isTransactionManaged, iterateComplete, makeFrame, mergeBindingsFromRequest, process, setSessionCancelFuture, setSessionFuture, startTransaction, triggerTimeout
-
-
-
-
Field Detail
-
queue
protected final BlockingQueue<SessionTask> queue
-
-
Constructor Detail
-
MultiTaskSession
public MultiTaskSession(SessionTask initialSessionTask, String sessionId, ConcurrentMap<String,Session> sessions)
Creates a newMultiTaskSession
object providing the initial startingSessionTask
that gets executed by the session when it starts.- Parameters:
initialSessionTask
- The tasks that starts the session.sessionId
- The id of the sessionsessions
- The session id toSession
instances mapping
-
-
Method Detail
-
getScriptEngine
public GremlinScriptEngine getScriptEngine(SessionTask sessionTask, String language)
Gets the script engine specific to this session which is dependent on theSettings.useCommonEngineForSessions
configuration.- Overrides:
getScriptEngine
in classAbstractSession
-
isAcceptingTasks
public boolean isAcceptingTasks()
Description copied from interface:Session
Determines if this session can accept additional tasks or not.
-
sendTimeoutResponseForUncommencedTask
public void sendTimeoutResponseForUncommencedTask()
Description copied from class:AbstractSession
Respond to the client with the specific timeout response for this Session implementation. This is for situations where the Session hasn't started running.- Specified by:
sendTimeoutResponseForUncommencedTask
in classAbstractSession
-
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 {@link super#close()} which will then interrupt thisrun()
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 interfaceAutoCloseable
- Overrides:
close
in classAbstractSession
-
getWorkerBindings
protected Bindings getWorkerBindings() throws SessionException
- Overrides:
getWorkerBindings
in classAbstractSession
- Throws:
SessionException
-
initializeGremlinExecutor
protected GremlinExecutor initializeGremlinExecutor(SessionTask sessionTask)
-
-