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
ASessionimplementation 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 firstSessionTaskto 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 newMultiTaskSessionobject providing the initial startingSessionTaskthat gets executed by the session when it starts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This method stops incoming requests from being added to the session queue.GremlinScriptEnginegetScriptEngine(SessionTask sessionTask, String language)Gets the script engine specific to this session which is dependent on theSettings.useCommonEngineForSessionsconfiguration.protected BindingsgetWorkerBindings()protected GremlinExecutorinitializeGremlinExecutor(SessionTask sessionTask)booleanisAcceptingTasks()Determines if this session can accept additional tasks or not.voidrun()voidsendTimeoutResponseForUncommencedTask()Respond to the client with the specific timeout response for this Session implementation.booleansubmitTask(SessionTask sessionTask)Adds a task for session to complete.StringtoString()-
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 newMultiTaskSessionobject providing the initial startingSessionTaskthat 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 toSessioninstances mapping
-
-
Method Detail
-
getScriptEngine
public GremlinScriptEngine getScriptEngine(SessionTask sessionTask, String language)
Gets the script engine specific to this session which is dependent on theSettings.useCommonEngineForSessionsconfiguration.- Overrides:
getScriptEnginein classAbstractSession
-
isAcceptingTasks
public boolean isAcceptingTasks()
Description copied from interface:SessionDetermines if this session can accept additional tasks or not.
-
sendTimeoutResponseForUncommencedTask
public void sendTimeoutResponseForUncommencedTask()
Description copied from class:AbstractSessionRespond 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:
sendTimeoutResponseForUncommencedTaskin classAbstractSession
-
submitTask
public boolean submitTask(SessionTask sessionTask) throws RejectedExecutionException
Description copied from interface:SessionAdds 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:
closein interfaceAutoCloseable- Overrides:
closein classAbstractSession
-
getWorkerBindings
protected Bindings getWorkerBindings() throws SessionException
- Overrides:
getWorkerBindingsin classAbstractSession- Throws:
SessionException
-
initializeGremlinExecutor
protected GremlinExecutor initializeGremlinExecutor(SessionTask sessionTask)
-
-