private void executeQuery ( ServerCommit commit , ServerSessionContext session , CompletableFuture < Result > future , ThreadContext context ) { if ( ! log . isOpen ( ) ) { context . executor ( ) . execute ( ( ) -> future . completeExceptionally ( new IllegalStateException ( "log closed" ) ) ) ; return ; } // If the session is already in an inactive state, complete the future exceptionally. if ( ! session . state ( ) . active ( ) ) { context . executor ( ) . execute ( ( ) -> future . completeExceptionally ( new UnknownSessionException ( "inactive session: " + session . id ( ) ) ) ) ; return ; } long index = commit . index ( ) ; long eventIndex = session . getEventIndex ( ) ; // Update the state machine context with the query entry's index. We set a null consistency // level to indicate that events cannot be published in this context. Publishing events in // response to state machine queries is non-deterministic as queries are not replicated. executor . init ( index , commit . time ( ) , ServerStateMachineContext . Type . QUERY ) ; try { Object result = executor . executeOperation ( commit ) ; context . executor ( ) . execute ( ( ) -> future . complete ( new Result ( index , eventIndex , result ) ) ) ; } catch ( Exception e ) { context . executor ( ) . execute ( ( ) -> future . complete ( new Result ( index , eventIndex , e ) ) ) ; } }
Executes a state machine query .