public override void GetStreamValuesHandler(GetStreamValuesArgsReader request, StreamValueCollectionsDTOWriter response) { TimestampPointerDTO?exclusiveUpperBoundCell = GetTimestampCellAfterTime(request.StreamCellId, request.EndTime); TimestampPointerDTO?inclusiveUpperBoundCellNullable; if (exclusiveUpperBoundCell.HasValue) { inclusiveUpperBoundCellNullable = GetImmediatePredecessorTimestampCell(exclusiveUpperBoundCell.Value.Id); } else { inclusiveUpperBoundCellNullable = GetSnapshotTimestamp(request.StreamCellId); } if (!inclusiveUpperBoundCellNullable.HasValue) { return; } TimestampPointerDTO inclusiveUpperBoundCell = inclusiveUpperBoundCellNullable.Value; foreach (var valueCollection in GetValuesAfterTimestamp(request.StreamCellId, request.StartTime, inclusiveUpperBoundCell)) { response.ValueCollections.Add(valueCollection); } }
private TimestampPointerDTO GetTimestampCellAfterTimeRecursive(TimestampPointerDTO currentTimeCellDTO, long timestamp) { TimestampPointerDTO previousTimeCellDTO = GetPreviousTimestampCellId(currentTimeCellDTO, timestamp); if (previousTimeCellDTO.Id == currentTimeCellDTO.Id) { return(currentTimeCellDTO); } else { return(GetTimestampCellAfterTime(previousTimeCellDTO, timestamp)); // logN } }
private TimestampPointerDTO GetTimestampCellAfterTime(TimestampPointerDTO currentTimeCellDTO, long timestamp) { TimestampPointerDTO previousTimeCellDTO; while (true) { previousTimeCellDTO = GetPreviousTimestampCellId(currentTimeCellDTO, timestamp); if (previousTimeCellDTO.Id == currentTimeCellDTO.Id) { break; } currentTimeCellDTO = previousTimeCellDTO; } return(currentTimeCellDTO); }
private TimestampPointerDTO?GetTimestampCellAfterTime(long streamCellId, long timestamp) { TimestampPointerDTO?snapshotNullable = GetSnapshotTimestamp(streamCellId); //Empty stream, return empty if (!snapshotNullable.HasValue) { return(null); } //Requested time is after Snapshot time; return Snapshot value TimestampPointerDTO snapshot = snapshotNullable.Value; if (timestamp >= snapshot.Ticks) { return(snapshot); } //Request time is historical; search through history return(GetTimestampCellAfterTime(snapshot, timestamp)); }
public static void Apply(this StreamValueCollectionDTOWriter response, TimestampPointerDTO timestamp, long streamCellId) { response.Timestamp = timestamp.Ticks; response.StreamCellId = streamCellId; List <long> valueCellIds; using (var valuesCollection = Global.LocalStorage.UseStreamValueCollection(timestamp.Values)) { valueCellIds = valuesCollection.Values; } foreach (var valueCellId in valueCellIds) { using (var value = Global.LocalStorage.UseStreamValue(valueCellId)) { StreamValueDTO valueDTO = value.ToStreamValueDTO(); response.Values.Add(valueDTO); } } }
private TimestampPointerDTO GetPreviousTimestampCellId(TimestampPointerDTO currentCell, long referenceTicks) { List <long> previousTimeCellIds = currentCell.Previous; long previousTimeCellId = previousTimeCellIds[0]; for (int i = previousTimeCellIds.Count - 1; i >= 0; i--) { previousTimeCellId = previousTimeCellIds[i]; using (var previousTimeCell = Storage.UseTimestamp(previousTimeCellId, CellAccessOptions.ReturnNullOnCellNotFound)) { if (previousTimeCell == null) { continue; } if (previousTimeCell.Ticks > referenceTicks) { return(previousTimeCell.ToTimestampPointerDTO()); } } } return(currentCell); }
private IEnumerable <StreamValueCollectionDTO> GetValuesAfterTimestamp(long streamCellId, long inclusiveLowerBoundTimestamp, TimestampPointerDTO inclusiveUpperBoundCell) { TimestampPointerDTO?currentCell = inclusiveUpperBoundCell; while (currentCell.HasValue && currentCell.Value.Ticks >= inclusiveLowerBoundTimestamp) { List <StreamValueDTO> valuesDTO = DTOFactory.GetValues(currentCell.Value.Values); StreamValueCollectionDTO valuesCollectionDTO = new StreamValueCollectionDTO(valuesDTO, currentCell.Value.Ticks, streamCellId); yield return(valuesCollectionDTO); currentCell = GetImmediatePredecessorTimestampCell(currentCell.Value.Id); } }