public void Start() { if (started.CompareAndSet(false, true)) { dispatcher = new SessionDispatcher(); foreach (NmsMessageConsumer consumer in consumers.Values.ToArray()) { consumer.Start(); } } }
public void TestCompareAndSetNotSetAtomicBoolWhenActualValueWasNotEqualToTheExpectedValue() { AtomicBool atomicBool = new AtomicBool(); Assert.False(atomicBool.Value); Assert.False(atomicBool.CompareAndSet(true, false)); }
public void Close() { CheckIsOnDeliveryThread(); if (closed.CompareAndSet(false, true)) { DoStop(false); foreach (NmsSession session in sessions.Values) { session.Shutdown(null); } try { provider.Close(); } catch (Exception) { Tracer.Debug("Ignoring provider exception during connection close"); } sessions.Clear(); started.Set(false); connected.Set(false); } }
/// <summary> /// Start the worker pool processing events in sequence. /// </summary> /// <returns>the <see cref="RingBuffer{T}"/> used for the work queue.</returns> /// <exception cref="InvalidOperationException">if the pool has already been started and not halted yet</exception> public RingBuffer <T> Start() { // TODO find a more flexible way to start threads (IScheduler or something like that) if (!_started.CompareAndSet(false, true)) { throw new InvalidOperationException("WorkerPool has already been started and cannot be restarted until halted."); } long cursor = _ringBuffer.Cursor; _workSequence.Value = cursor; for (int i = 0; i < _workProcessors.Length; i++) { var workProcessor = _workProcessors[i]; workProcessor.Sequence.Value = cursor; var thread = new Thread(workProcessor.Run) { IsBackground = true, }; thread.Start(); } return(_ringBuffer); }
public async Task CloseAsync() { CheckIsOnDeliveryExecutionFlow(); if (closed.CompareAndSet(false, true)) { DoStop(false); foreach (NmsSession session in sessions.Values) { await session.ShutdownAsync(null).Await(); } ; try { await provider.CloseAsync().Await();; } catch (Exception) { Tracer.Debug("Ignoring provider exception during connection close"); } sessions.Clear(); started.Set(false); connected.Set(false); } }
public void Start() { if (started.CompareAndSet(false, true)) { DrainMessageQueueToListener(); } }
private void CheckOnlyStartedOnce() { if (!_started.CompareAndSet(false, true)) { throw new InvalidOperationException("Disruptor.start() must only be called once."); } }
public void Dispose() { if (_disposed.CompareAndSet(false, true)) { _delegate(); } }
public void TestCompareAndSetAtomicBoolToFalse() { AtomicBool atomicBool = new AtomicBool(true); Assert.True(atomicBool.Value); Assert.True(atomicBool.CompareAndSet(true, false)); Assert.False(atomicBool.Value); }
private void DoStop(bool checkClosed) { if (checkClosed) { CheckClosedOrFailed(); } CheckIsOnDeliveryThread(); if (started.CompareAndSet(true, false)) { foreach (NmsSession session in sessions.Values) { session.Stop(); } } }
public void Shutdown(Exception error = null) { if (closed.CompareAndSet(false, true)) { failureCause = error; session.Remove(this); } }
public void Shutdown(Exception exception) { if (closed.CompareAndSet(false, true)) { messageQueue.Dispose(); failureCause = exception; Session.Remove(this); started.Set(false); } }
/// <summary> /// It is ok to have another thread re-run this method after a halt(). /// </summary> public void Run() { if (!_running.CompareAndSet(false, false)) { throw new InvalidOperationException("Thread is already running"); } _sequenceBarrier.ClearAlert(); NotifyStart(); var processedSequence = true; long nextSequence = _sequence.Value; T eventRef = null; while (true) { try { if (processedSequence) { processedSequence = false; nextSequence = _workSequence.IncrementAndGet(); _sequence.Value = nextSequence - 1L; } _sequenceBarrier.WaitFor(nextSequence); eventRef = _ringBuffer[nextSequence]; _workHandler.OnEvent(eventRef); processedSequence = true; } catch (AlertException) { if (!_running.Value) { break; } } catch (Exception ex) { _exceptionHandler.HandleEventException(ex, nextSequence, eventRef); processedSequence = true; } } NotifyShutdown(); _running.Value = false; }
/// <summary> /// It is ok to have another thread rerun this method after a halt(). /// </summary> public void Run() { if (!_running.CompareAndSet(false, true)) { throw new InvalidOperationException("Thread is already running"); } _sequenceBarrier.ClearAlert(); NotifyStart(); T evt = null; long nextSequence = _sequence.Value + 1L; while (true) { try { long availableSequence = _sequenceBarrier.WaitFor(nextSequence); while (nextSequence <= availableSequence) { evt = _ringBuffer[nextSequence]; _eventHandler.OnNext(evt, nextSequence, nextSequence == availableSequence); nextSequence++; } _sequence.LazySet(nextSequence - 1L); } catch (AlertException) { if (!_running.Value) { break; } } catch (Exception ex) { _exceptionHandler.HandleEventException(ex, nextSequence, evt); _sequence.LazySet(nextSequence); nextSequence++; } } NotifyShutdown(); _running.Value = false; }
public void Shutdown(NMSException exception = null) { if (closed.CompareAndSet(false, true)) { Stop(); try { foreach (NmsMessageConsumer consumer in consumers.Values.ToArray()) { consumer.Shutdown(exception); } foreach (NmsMessageProducer producer in producers.Values.ToArray()) { producer.Shutdown(exception); } } finally { Connection.RemoveSession(SessionInfo); } } }