private StreamSegmentReadIndex getOrCreateIndex ( long streamSegmentId ) throws StreamSegmentNotExistsException { StreamSegmentReadIndex index ; synchronized ( this . lock ) { // Try to see if we have the index already in memory. index = getIndex ( streamSegmentId ) ; if ( index == null ) { // We don't have it, create one. SegmentMetadata segmentMetadata = this . metadata . getStreamSegmentMetadata ( streamSegmentId ) ; Exceptions . checkArgument ( segmentMetadata != null , "streamSegmentId" , "StreamSegmentId %s does not exist in the metadata." , streamSegmentId ) ; if ( segmentMetadata . isDeleted ( ) ) { throw new StreamSegmentNotExistsException ( segmentMetadata . getName ( ) ) ; } index = new StreamSegmentReadIndex ( this . config , segmentMetadata , this . cache , this . storage , this . executor , isRecoveryMode ( ) ) ; this . cacheManager . register ( index ) ; this . readIndices . put ( streamSegmentId , index ) ; } } return index ; }
Gets a reference to the existing StreamSegmentRead index for the given StreamSegment Id . Creates a new one if necessary .