本文整理汇总了C#中RingBuffer.SetGatingSequences方法的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer.SetGatingSequences方法的具体用法?C# RingBuffer.SetGatingSequences怎么用?C# RingBuffer.SetGatingSequences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.SetGatingSequences方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
_ringBuffer = new RingBuffer<StubEvent>(()=>new StubEvent(-1), 16);
_sequenceBarrier = _ringBuffer.NewBarrier();
_batchHandlerMock = new Mock<IEventHandler<StubEvent>>();
_countDownEvent = new CountdownEvent(1);
_batchEventProcessor = new BatchEventProcessor<StubEvent>(_ringBuffer, _sequenceBarrier, _batchHandlerMock.Object);
_ringBuffer.SetGatingSequences(_batchEventProcessor.Sequence);
}
示例2: SetUp
public void SetUp()
{
_ringBuffer = new RingBuffer<StubEvent>(()=>new StubEvent(-1), 64);
_eventProcessorMock1 = new Mock<IEventProcessor>();
_eventProcessorMock2 = new Mock<IEventProcessor>();
_eventProcessorMock3 = new Mock<IEventProcessor>();
_ringBuffer.SetGatingSequences(new NoOpEventProcessor(_ringBuffer).Sequence);
}
示例3: ShouldPublishEvent
public void ShouldPublishEvent()
{
var ringBuffer = new RingBuffer<LongEvent>(()=>new LongEvent(0), BufferSize);
ringBuffer.SetGatingSequences(new NoOpEventProcessor(ringBuffer).Sequence);
var eventPublisher = new EventPublisher<LongEvent>(ringBuffer);
eventPublisher.PublishEvent(_translator);
eventPublisher.PublishEvent(_translator);
Assert.AreEqual(0L + ValueAdd, ringBuffer[0].Value);
Assert.AreEqual(1L + ValueAdd, ringBuffer[1].Value);
}
示例4: ShouldPublishEvent
public void ShouldPublishEvent()
{
const long valueAdd = 29L;
var ringBuffer = new RingBuffer<LongEvent>(()=>new LongEvent(0), 32);
ringBuffer.SetGatingSequences(new NoOpEventProcessor(ringBuffer).Sequence);
var eventPublisher = new EventPublisher<LongEvent>(ringBuffer);
Func<LongEvent, long, LongEvent> translator = (evt, seq) =>
{
evt.Value = seq + valueAdd;
return evt;
};
eventPublisher.PublishEvent(translator);
eventPublisher.PublishEvent(translator);
Assert.AreEqual(0L + valueAdd, ringBuffer[0].Value);
Assert.AreEqual(1L + valueAdd, ringBuffer[1].Value);
}
示例5: ShouldTryPublishEvent
public void ShouldTryPublishEvent()
{
RingBuffer<LongEvent> ringBuffer = new RingBuffer<LongEvent>(()=>new LongEvent(0), BufferSize);
ringBuffer.SetGatingSequences(new Sequence());
EventPublisher<LongEvent> eventPublisher = new EventPublisher<LongEvent>(ringBuffer);
for (int i = 0; i < BufferSize; i++)
{
Assert.IsTrue(eventPublisher.TryPublishEvent(_translator, 1));
}
for (int i = 0; i < BufferSize; i++)
{
Assert.AreEqual(i + ValueAdd, ringBuffer[i].Value);
}
Assert.IsFalse(eventPublisher.TryPublishEvent(_translator, 1));
}
示例6: Run
public void Run()
{
_ring = new RingBuffer<ValueEvent>(() => new ValueEvent(), new MultiThreadedClaimStrategy(2048), new YieldingWaitStrategy());
_sequenceBarrier = _ring.NewBarrier();
_sequence = new Sequence(Sequencer.InitialCursorValue);
_ring.SetGatingSequences(_sequence);
var manager = new EventStoreManager();
//manager.CompressionStrategy = new NoCompressionStrategy();
using (var stream = new FileStream("0.event", FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1))
{
var file = new StreamEventFileStorage(stream);
_writeStore = manager.AppendToStore(file);
var consumerTask = Task.Factory.StartNew(EventConsumer,
TaskCreationOptions.LongRunning |
TaskCreationOptions.HideScheduler);
_sw.Start();
var tasks = new Task[ParallelTasks];
Parallel.For(0, tasks.Length, i =>
{
tasks[i] = PublishSampleEvents(RepetitionCount);
});
Task.WaitAll(tasks);
_sequenceBarrier.Alert();
consumerTask.Wait();
_sw.Stop();
Console.WriteLine("Write {0}ms events per second:{1:f0} total len:{2}", _sw.ElapsedMilliseconds,
tasks.Length * RepetitionCount / _sw.Elapsed.TotalSeconds, stream.Length);
_sw.Restart();
var allObserverCounter = new AllObserverCounter();
manager.OpenReadOnlyStore(file).ReadFromStartToEnd(allObserverCounter);
_sw.Stop();
Console.WriteLine("Read {0}ms events per second:{1:f0} events:{2}", _sw.ElapsedMilliseconds,
allObserverCounter.Count / _sw.Elapsed.TotalSeconds, allObserverCounter.Count);
}
}
示例7: ShouldPreventProducersOvertakingEventProcessorsWrapPoint
public void ShouldPreventProducersOvertakingEventProcessorsWrapPoint()
{
const int ringBufferSize = 4;
var mre = new ManualResetEvent(false);
var producerComplete = false;
var ringBuffer = new RingBuffer<StubEvent>(() => new StubEvent(-1), ringBufferSize);
var processor = new TestEventProcessor(ringBuffer.NewBarrier());
ringBuffer.SetGatingSequences(processor.Sequence);
var thread = new Thread(
() =>
{
for (int i = 0; i <= ringBufferSize; i++) // produce 5 events
{
var sequence = ringBuffer.Next();
StubEvent evt = ringBuffer[sequence];
evt.Value = i;
ringBuffer.Publish(sequence);
if (i == 3) // unblock main thread after 4th event published
{
mre.Set();
}
}
producerComplete = true;
});
thread.Start();
mre.WaitOne();
Assert.AreEqual(ringBufferSize - 1, ringBuffer.Cursor);
Assert.IsFalse(producerComplete);
processor.Run();
thread.Join();
Assert.IsTrue(producerComplete);
}
示例8: SetUp
public void SetUp()
{
_ringBuffer = new RingBuffer<StubEvent>(() => new StubEvent(-1), 32);
_sequenceBarrier = _ringBuffer.NewBarrier();
_ringBuffer.SetGatingSequences(new NoOpEventProcessor(_ringBuffer).Sequence);
}