public void RemoveWorkHandlerLostEventExample() { int eventSize = 8; var countdownEvent = new CountdownEvent(eventSize); var workSequence = new Sequence(); var disruptor = new Disruptor <StubEvent>(StubEvent.EventFactory, 4); var ringBuffer = disruptor.Start(); var handler1 = new DynamicHandler(1, countdownEvent); var processor1 = new WorkProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(), handler1, new FatalExceptionHandler(), workSequence); var handler2 = new DynamicHandler(2, countdownEvent); var processor2 = new WorkProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(), handler2, new FatalExceptionHandler(), workSequence); ringBuffer.AddGatingSequences(processor1.Sequence); Task.Run(() => processor1.Run()); ringBuffer.AddGatingSequences(processor2.Sequence); Task.Run(() => processor2.Run()); handler1.AwaitStart(); handler2.AwaitStart(); Thread.Sleep(10); // processor1 should own an unavailable work sequence // => this sequence will be dropped by Halt processor1.Halt(); var producer = new MessageProducer(disruptor, InitData(0, eventSize)); Task.Run(() => producer.Run()); producer.AwaitStart(); handler1.AwaitShutdown(); ringBuffer.RemoveGatingSequence(processor1.Sequence); // countdownEvent should not reach zero because of the dropped sequence var await = countdownEvent.Wait(TimeSpan.FromMilliseconds(500)); Assert.IsFalse(await); }
public void RemoveWorkHandlerLaterTest() { var eventSize = 8; var countdownEvent = new CountdownEvent(eventSize); var workSequence = new Sequence(); var disruptor = new Disruptor <StubEvent>(StubEvent.EventFactory, 4); var ringBuffer = disruptor.Start(); var handler1 = new DynamicHandler(1, countdownEvent); var processor1 = new WorkProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(), handler1, new FatalExceptionHandler(), workSequence); var handler2 = new DynamicHandler(2, countdownEvent); var processor2 = new WorkProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(), handler2, new FatalExceptionHandler(), workSequence); ringBuffer.AddGatingSequences(processor1.Sequence); Task.Run(() => processor1.Run()); ringBuffer.AddGatingSequences(processor2.Sequence); Task.Run(() => processor2.Run()); handler1.AwaitStart(); handler2.AwaitStart(); Thread.Sleep(10); // processor1 should own an unavailable work sequence // => this sequence should not be dropped by HaltLater processor1.HaltLater(); var producer = new MessageProducer(disruptor, InitData(0, eventSize)); Task.Run(() => producer.Run()); producer.AwaitStart(); handler1.AwaitShutdown(); ringBuffer.RemoveGatingSequence(processor1.Sequence); Assert.IsTrue(countdownEvent.Wait(TimeSpan.FromSeconds(3))); }
private void CreateProcessor(Socket client) { var processor = new WorkProcessor(this, client); processor.Run(ProcessCmdLine); }