Beispiel #1
0
        public RecordWriteResult TryWrite(IBuffer buffer, Action <IHerculesEventBuilder> build, out int recordSize)
        {
            recordSize = 0;

            var startingPosition = buffer.Position;

            RecordWriteResult RollbackWithError(RecordWriteResult error)
            {
                buffer.Position = startingPosition;
                return(error);
            }

            try
            {
                buffer.IsOverflowed = false;

                using (var builder = new BinaryEventBuilder(buffer, timeProvider, protocolVersion))
                    build(builder);

                if (buffer.IsOverflowed)
                {
                    return(RollbackWithError(RecordWriteResult.OutOfMemory));
                }
            }
            catch (Exception error)
            {
                LogBuilderException(error);

                return(RollbackWithError(RecordWriteResult.Exception));
            }

            recordSize = (int)(buffer.Position - startingPosition);

            if (recordSize <= maxRecordSize)
            {
                buffer.CommitRecord(recordSize);
                return(RecordWriteResult.Success);
            }

            LogRecordWasTooLarge(recordSize);

            return(RollbackWithError(RecordWriteResult.RecordTooLarge));
        }