Package io.deephaven.server.session
Class SessionState
java.lang.Object
io.deephaven.server.session.SessionState
SessionState manages all exports for a single session.
It manages exported LivenessReferent
. It cascades failures to child dependencies.
TODO: - cyclical dependency detection - out-of-order dependency timeout
Details Regarding Data Structure of ExportObjects:
- The exportMap map, exportListeners list, exportListenerVersion, and export object's exportListenerVersion work together to enable a listener to synchronize with outstanding exports in addition to sending the listener updates while they continue to subscribe.
- SessionState::exportMap's purpose is to map from the export id to the export object
- SessionState::exportListeners' purpose is to keep a list of active subscribers
- SessionState::exportListenerVersion's purpose is to know whether or not a subscriber has already seen a status
- A listener will receive an export notification for export id NON_EXPORT_ID (a zero) to indicate that the run has completed. A listener may see an update for an export before receiving the "run has completed" message. A listener should be prepared to receive duplicate/redundant updates.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
static interface
static interface
static final class
This class represents one unit of content exported in the session.static interface
-
Field Summary
-
Constructor Summary
ConstructorDescriptionSessionState
(Scheduler scheduler, SessionService.ErrorTransformer errorTransformer, javax.inject.Provider<ExecutionContext> executionContextProvider, AuthContext authContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExportListener
(io.grpc.stub.StreamObserver<ExportNotification> observer) void
addOnCloseCallback
(Closeable onClose) Attach an on-close callback bound to the life of the session.<T> SessionState.ExportObject<T>
getExport
(int exportId) Grab the ExportObject for the provided id.<T> SessionState.ExportObject<T>
Grab the ExportObject for the provided ticket.<T> SessionState.ExportObject<T>
Grab the ExportObject for the provided ticket.<T> SessionState.ExportObject<T>
getExportIfExists
(int exportId) Grab the ExportObject for the provided id if it already exists, otherwise return null.<T> SessionState.ExportObject<T>
getExportIfExists
(Ticket ticket, String logId) Grab the ExportObject for the provided id if it already exists, otherwise return null.protected void
initializeExpiration
(SessionService.TokenExpiration expiration) This method is controlled by SessionService to update the expiration whenever the session is refreshed.boolean
static boolean
static boolean
<T> SessionState.ExportBuilder<T>
newExport
(int exportId) Create an ExportBuilder to create the export after dependencies are satisfied.<T> SessionState.ExportBuilder<T>
Create an ExportBuilder to create the export after dependencies are satisfied.<T> SessionState.ExportBuilder<T>
Create an ExportBuilder to create the export after dependencies are satisfied.<T> SessionState.ExportObject<T>
newServerSideExport
(T export) Create and export a pre-computed element.<T> SessionState.ExportBuilder<T>
Create an ExportBuilder to perform work after dependencies are satisfied that itself does not create any exports.long
void
Notes that this session has expired and exports should be released.io.grpc.stub.StreamObserver<ExportNotification>
removeExportListener
(io.grpc.stub.StreamObserver<ExportNotification> observer) Remove an on-close callback bound to the life of the session.boolean
removeOnCloseCallback
(Closeable onClose) Remove an on-close callback bound to the life of the session.toErrorHandler
(SessionState.ExportErrorGrpcHandler errorHandler) Convert anSessionState.ExportErrorGrpcHandler
to anSessionState.ExportErrorHandler
.protected void
updateExpiration
(SessionService.TokenExpiration expiration) This method is controlled by SessionService to update the expiration whenever the session is refreshed.static <T> SessionState.ExportObject<T>
wrapAsExport
(T export) Wrap an object in an ExportObject to make it conform to the session export API.static <T> SessionState.ExportObject<T>
wrapAsFailedExport
(Exception caughtException) Wrap an exception in an ExportObject to make it conform to the session export API.
-
Field Details
-
NON_EXPORT_ID
public static final int NON_EXPORT_ID- See Also:
-
-
Constructor Details
-
SessionState
@AssistedInject public SessionState(Scheduler scheduler, SessionService.ErrorTransformer errorTransformer, javax.inject.Provider<ExecutionContext> executionContextProvider, @Assisted AuthContext authContext)
-
-
Method Details
-
wrapAsExport
Wrap an object in an ExportObject to make it conform to the session export API.- Type Parameters:
T
- the type of the object- Parameters:
export
- the object to wrap- Returns:
- a sessionless export object
-
wrapAsFailedExport
Wrap an exception in an ExportObject to make it conform to the session export API. The export behaves as if it has already failed.- Type Parameters:
T
- the type of the object- Parameters:
caughtException
- the exception to propagate- Returns:
- a sessionless export object
-
initializeExpiration
@VisibleForTesting protected void initializeExpiration(@NotNull SessionService.TokenExpiration expiration) This method is controlled by SessionService to update the expiration whenever the session is refreshed.- Parameters:
expiration
- the initial expiration time and session token
-
updateExpiration
@VisibleForTesting protected void updateExpiration(@NotNull SessionService.TokenExpiration expiration) This method is controlled by SessionService to update the expiration whenever the session is refreshed.- Parameters:
expiration
- the new expiration time and session token
-
getSessionId
- Returns:
- the session id
-
getExpiration
- Returns:
- the current expiration token for this session
-
isExpired
public boolean isExpired()- Returns:
- whether or not this session is expired
-
getAuthContext
- Returns:
- the auth context for this session
-
getExecutionContext
- Returns:
- the execution context for this session
-
getExport
Grab the ExportObject for the provided ticket.- Parameters:
ticket
- the export ticketlogId
- an end-user friendly identification of the ticket should an error occur- Returns:
- a future-like object that represents this export
-
getExport
public <T> SessionState.ExportObject<T> getExport(org.apache.arrow.flight.impl.Flight.Ticket ticket, String logId) Grab the ExportObject for the provided ticket.- Parameters:
ticket
- the export ticketlogId
- an end-user friendly identification of the ticket should an error occur- Returns:
- a future-like object that represents this export
-
getExport
Grab the ExportObject for the provided id.- Parameters:
exportId
- the export handle id- Returns:
- a future-like object that represents this export
-
getExportIfExists
Grab the ExportObject for the provided id if it already exists, otherwise return null.- Parameters:
exportId
- the export handle id- Returns:
- a future-like object that represents this export
-
getExportIfExists
Grab the ExportObject for the provided id if it already exists, otherwise return null.- Parameters:
ticket
- the export ticketlogId
- an end-user friendly identification of the ticket should an error occur- Returns:
- a future-like object that represents this export
-
newServerSideExport
Create and export a pre-computed element. This is typically used in scenarios where the number of exports is not known in advance by the requesting client.- Type Parameters:
T
- the export type- Parameters:
export
- the result of the export- Returns:
- the ExportObject for this item for ease of access to the export
-
newExport
public <T> SessionState.ExportBuilder<T> newExport(org.apache.arrow.flight.impl.Flight.Ticket ticket, String logId) Create an ExportBuilder to create the export after dependencies are satisfied.- Type Parameters:
T
- the export type that the callable will return- Parameters:
ticket
- the grpcFlight.Ticket
for this exportlogId
- an end-user friendly identification of the ticket should an error occur- Returns:
- an export builder
-
newExport
Create an ExportBuilder to create the export after dependencies are satisfied.- Type Parameters:
T
- the export type that the callable will return- Parameters:
ticket
- the grpcTicket
for this exportlogId
- an end-user friendly identification of the ticket should an error occur- Returns:
- an export builder
-
newExport
Create an ExportBuilder to create the export after dependencies are satisfied.- Type Parameters:
T
- the export type that the callable will return- Parameters:
exportId
- the export id- Returns:
- an export builder
-
nonExport
Create an ExportBuilder to perform work after dependencies are satisfied that itself does not create any exports.- Returns:
- an export builder
-
addOnCloseCallback
Attach an on-close callback bound to the life of the session. Note thatCloseable
does not require that the close() method be idempotent, but when combined withremoveOnCloseCallback(Closeable)
, close() will only be called once from this class.- Parameters:
onClose
- the callback to invoke at end-of-life
-
removeOnCloseCallback
Remove an on-close callback bound to the life of the session. A common pattern to use this will be for an object to try to remove itself, and if it succeeds, to call its ownCloseable.close()
. If it fails, it can expect to have close() be called automatically.- Parameters:
onClose
- the callback to no longer invoke at end-of-life- Returns:
- true iff the callback was removed
- ApiNote:
- If this SessionState has already begun expiration processing,
onClose
will not be removed by this method. This means that ifonClose
was previously added and not removed, it either has already been invoked or will be invoked by the SessionState.
-
onExpired
public void onExpired()Notes that this session has expired and exports should be released. -
isExportStateFailure
- Returns:
- true iff the provided export state is a failure state
-
isExportStateTerminal
- Returns:
- true iff the provided export state is a terminal state
-
addExportListener
-
removeExportListener
public io.grpc.stub.StreamObserver<ExportNotification> removeExportListener(io.grpc.stub.StreamObserver<ExportNotification> observer) Remove an on-close callback bound to the life of the session.- Parameters:
observer
- the observer to no longer be subscribed- Returns:
- The item if it was removed, else null
-
numExportListeners
-
toErrorHandler
public static SessionState.ExportErrorHandler toErrorHandler(SessionState.ExportErrorGrpcHandler errorHandler) Convert anSessionState.ExportErrorGrpcHandler
to anSessionState.ExportErrorHandler
.gRPC's error handlers are designed to consume
StatusRuntimeException
objects. Exports can fail for a variety of reasons, and theSessionState.ExportErrorHandler
is designed to richly communicate export failures. This method is the glue between the two error handling APIs; enabling export error propagation to gRPC clients.- Parameters:
errorHandler
- the gRPC specific error handler- Returns:
- the generalized error handler
-