void IAsyncLogProviderCommandHandler.ContinueAsynchronously(CommandContext ctx)
        {
            result = new DateBoundPositionResponseData();

            result.Position = PositionedMessagesUtils.LocateDateBound(ctx.Reader, date, bound, ctx.Cancellation);
            ctx.Tracer.Info("Position to return: {0}", result.Position);

            if (result.Position == ctx.Reader.EndPosition)
            {
                result.IsEndPosition = true;
                ctx.Tracer.Info("It is END position");
            }
            else if (result.Position == ctx.Reader.BeginPosition - 1)
            {
                result.IsBeforeBeginPosition = true;
                ctx.Tracer.Info("It is BEGIN-1 position");
            }
            else
            {
                ctx.Cancellation.ThrowIfCancellationRequested();
                if (userNeedsDate)
                {
                    result.Date = PositionedMessagesUtils.ReadNearestMessageTimestamp(ctx.Reader, result.Position);
                    ctx.Tracer.Info("Date to return: {0}", result.Date);
                }
            }
            dateBoundsCache.Set(date, result);
        }
示例#2
0
        async Task IAsyncLogProviderCommandHandler.ContinueAsynchronously(CommandContext ctx)
        {
            result = new DateBoundPositionResponseData();

            result.Position = await PositionedMessagesUtils.LocateDateBound(ctx.Reader, date, bound, ctx.Cancellation);

            ctx.Tracer.Info("Position to return: {0}", result.Position);

            if (result.Position == ctx.Reader.EndPosition)
            {
                result.IsEndPosition = true;
                ctx.Tracer.Info("It is END position");
            }
            else if (result.Position == ctx.Reader.BeginPosition - 1)
            {
                result.IsBeforeBeginPosition = true;
                ctx.Tracer.Info("It is BEGIN-1 position");
            }
            else
            {
                ctx.Cancellation.ThrowIfCancellationRequested();
                if (messageRequested)
                {
                    result.Message = await PositionedMessagesUtils.ReadNearestMessage(ctx.Reader, result.Position, MessagesParserFlag.HintMessageContentIsNotNeeed);

                    ctx.Tracer.Info("Details to return: {0} at {1}", result.Message?.Time, result.Message?.Position);
                }
            }
            dateBoundsCache.Set(date, result);
        }
示例#3
0
            public bool Update()
            {
                using (owner.trace.NewNamedFrame("Updating {0}", this.fileName))
                {
                    CheckDisposed();

                    try
                    {
                        if (simpleMedia == null)
                        {
                            owner.trace.Info("SimpleMedia object not created yet. Creating");
                            simpleMedia = new SimpleFileMedia(
                                owner.fileSystem,
                                SimpleFileMedia.CreateConnectionParamsFromFileName(Path.Combine(owner.baseDirectory, FileName))
                                );
                        }

                        owner.trace.Info("Updating simple media");
                        simpleMedia.Update();

                        if (!simpleMedia.IsAvailable)
                        {
                            owner.trace.Info("File is not avaliable (i.e. has been deleted)");
                            return(false);
                        }

                        if (firstMessageTime == null)
                        {
                            owner.trace.Info("First message time is unknown. Calcalating it");
                            using (IPositionedMessagesReader reader = (IPositionedMessagesReader)Activator.CreateInstance(
                                       owner.logReaderType, new MediaBasedReaderParams(owner.tempThreads, SimpleMedia, owner.tempFilesManager), owner.logFormatInfo))
                            {
                                owner.trace.Info("Reader created");

                                reader.UpdateAvailableBounds(false);
                                owner.trace.Info("Bounds found");

                                IMessage first = PositionedMessagesUtils.ReadNearestMessage(reader, reader.BeginPosition);
                                if (first == null)
                                {
                                    owner.trace.Warning("No messages found");
                                    return(false);
                                }

                                owner.trace.Info("First message: {0} '{1}'", first.Time, first.Text);
                                firstMessageTime = first.Time;
                            }
                        }

                        owner.trace.Info("Part updated OK");
                        return(true);
                    }
                    catch (Exception e)
                    {
                        owner.trace.Error(e, "Failure during part update");
                        return(false);
                    }
                }
            }
示例#4
0
        bool UpdateAvailableTime(bool incrementalMode)
        {
            bool itIsFirstUpdate = firstUpdateFlag;

            firstUpdateFlag = false;

            UpdateBoundsStatus status = reader.UpdateAvailableBounds(incrementalMode);

            if (status == UpdateBoundsStatus.NothingUpdated && incrementalMode)
            {
                return(false);
            }

            if (status == UpdateBoundsStatus.OldMessagesAreInvalid)
            {
                incrementalMode = false;
            }

            // Get new boundary values into temporary variables
            IMessage newFirst, newLast;

            PositionedMessagesUtils.GetBoundaryMessages(reader, null, out newFirst, out newLast);

            if (firstMessage != null)
            {
                if (newFirst == null || MessageTimestamp.Compare(newFirst.Time, firstMessage.Time) != 0)
                {
                    // The first message we've just read differs from the cached one.
                    // This means that the log was overwritten. Fall to non-incremental mode.
                    incrementalMode = false;
                }
            }

            if (!incrementalMode)
            {
                if (!itIsFirstUpdate)
                {
                    // Reset everything that has been loaded so far
                    InvalidateEverythingThatHasBeenLoaded();
                }
                firstMessage = null;
            }

            // Try to get the dates range for new bounday messages
            DateRange newAvailTime = GetAvailableDateRangeHelper(newFirst, newLast);

            firstMessage = newFirst;

            // Getting here means that the boundaries changed.
            // Fire the notfication.

            var positionsRange = new FileRange.Range(reader.BeginPosition, reader.EndPosition);

            if (!incrementalMode)
            {
                readerContentsEtag = reader.GetContentsEtag();
            }

            int contentsEtag =
                readerContentsEtag
                ^ positionsRange.Begin.GetHashCode()
                ^ positionsRange.End.GetHashCode();

            StatsTransaction(stats =>
            {
                stats.AvailableTime    = newAvailTime;
                LogProviderStatsFlag f = LogProviderStatsFlag.AvailableTime;
                if (incrementalMode)
                {
                    f |= LogProviderStatsFlag.AvailableTimeUpdatedIncrementallyFlag;
                }
                stats.TotalBytes = reader.SizeInBytes;
                f |= LogProviderStatsFlag.BytesCount;
                stats.PositionsRange = positionsRange;
                f |= LogProviderStatsFlag.PositionsRange;
                stats.PositionsRangeUpdatesCount++;
                if (stats.ContentsEtag == null || contentsEtag != stats.ContentsEtag.Value)
                {
                    stats.ContentsEtag = contentsEtag;
                    f |= LogProviderStatsFlag.ContentsEtag;
                }
                return(f);
            });

            return(true);
        }