private void updateStateStorage ( final SagaInstanceInfo description , final CurrentExecutionContext context ) { Saga saga = description . getSaga ( ) ; String sagaId = saga . state ( ) . getSagaId ( ) ; // if saga has finished delete existing state and possible timeouts // if saga has just been created state has never been save and there // is no need to delete it. if ( saga . isFinished ( ) && ! description . isStarting ( ) ) { cleanupSagaSate ( sagaId ) ; } else if ( saga . isFinished ( ) && description . isStarting ( ) ) { // check storage on whether saga has been saved via // a recursive child contexts. if ( context . hasBeenStored ( sagaId ) ) { cleanupSagaSate ( sagaId ) ; } } if ( ! saga . isFinished ( ) ) { context . recordSagaStateStored ( sagaId ) ; env . storage ( ) . save ( saga . state ( ) ) ; } }
Updates the state storage depending on whether the saga is completed or keeps on running .