public void Waiting(IThreadState state) { if (ShouldNotifyDistributor()) { _bus.Send(new WorkerThreadAvailableCommand { Identifier = _identifier, InboxWorkQueueUri = _bus.Configuration.Inbox.WorkQueue.Uri.ToString(), ManagedThreadId = Thread.CurrentThread.ManagedThreadId, DateSent = DateTime.Now }, c => c.WithRecipient(_bus.Configuration.Worker.DistributorControlInboxWorkQueue)); if (_log.IsVerboseEnabled) { _log.Verbose(string.Format(ESBResources.DebugWorkerAvailable, _identifier, _bus.Configuration.Inbox.WorkQueue.Uri, _bus.Configuration.Worker.DistributorControlInboxWorkQueue.Uri)); } _nextNotificationDate = DateTime.Now.AddSeconds(_bus.Configuration.Worker.ThreadAvailableNotificationIntervalSeconds); } _threadActivity.Waiting(state); }
public void Execute(IThreadState state) { var pipeline = _pipelineFactory.GetPipeline <EventProcessingPipeline>(); while (state.Active) { var projection = _eventProcessor.GetProjection(); var waiting = true; if (projection != null) { pipeline.State.Clear(); pipeline.State.SetProjection(projection); pipeline.State.SetThreadState(state); pipeline.Execute(); if (pipeline.State.GetWorking()) { _threadActivity.Working(); waiting = false; } _eventProcessor.ReleaseProjection(projection.Name); } if (!waiting) { _threadActivity.Waiting(state); } } _pipelineFactory.ReleasePipeline(pipeline); }
public ActiveTimeRangeObserver(IThreadState state, ActiveTimeRange activeTimeRange) { Guard.AgainstNull(state, "state"); _state = state; _activeTimeRange = activeTimeRange; }
public virtual void Execute(IThreadState state) { var messagePipeline = Bus.Configuration.PipelineFactory.GetPipeline <TMessagePipeline>(Bus); try { messagePipeline.State.Replace(StateKeys.Working, false); messagePipeline.State.Replace(StateKeys.ActiveState, state); messagePipeline.Execute(); if (messagePipeline.State.Get <bool>(StateKeys.Working)) { Bus.Events.OnThreadWorking(this, new ThreadStateEventArgs(typeof(TMessagePipeline))); ThreadActivity.Working(); } else { Bus.Events.OnThreadWaiting(this, new ThreadStateEventArgs(typeof(TMessagePipeline))); ThreadActivity.Waiting(state); } } finally { Bus.Configuration.PipelineFactory.ReleasePipeline(messagePipeline); } }
public void Execute(IThreadState state) { while (state.Active) { var pipeline = _eventProcessor.Configuration.PipelineFactory.GetPipeline<EventProcessingPipeline>(_eventProcessor); pipeline.State.Add(_eventProjection); pipeline.State.Add(_eventProcessor.Configuration.ProjectionService); pipeline.State.Add(state); try { pipeline.Execute(); } finally { _pool.Release(pipeline); } if (pipeline.State.GetWorking()) { _threadActivity.Working(); } else { _threadActivity.Waiting(state); } } }
public virtual void Execute(IThreadState state) { var messagePipeline = _pipelineFactory.GetPipeline <TPipeline>(); try { messagePipeline.State.ResetWorking(); messagePipeline.State.Replace(StateKeys.ActiveState, state); messagePipeline.Execute(); if (messagePipeline.State.GetWorking()) { _events.OnThreadWorking(this, new ThreadStateEventArgs(typeof(TPipeline))); _threadActivity.Working(); } else { _events.OnThreadWaiting(this, new ThreadStateEventArgs(typeof(TPipeline))); _threadActivity.Waiting(state); } } finally { _pipelineFactory.ReleasePipeline(messagePipeline); } }
public static void While(int ms, IThreadState state, int step) { if (ms < 0) { return; } if (step < 0 || step > MaxStepSize) { step = MaxStepSize; } var end = DateTime.UtcNow.AddMilliseconds(ms); // sleep time should be: // - as large as possible to reduce burden on the os and improve accuracy // - less than the max step size to keep the thread responsive to thread state var remaining = (int)(end - DateTime.UtcNow).TotalMilliseconds; while (state.Active && remaining > 0) { var sleep = remaining < step ? remaining : step; Thread.Sleep(sleep); remaining = (int)(end - DateTime.UtcNow).TotalMilliseconds; } }
public ThreadContext() { Console.WriteLine("Thread yaratıldı ve henüz çalışmıyor"); ThreadId = Guid.NewGuid().ToString(); State = StoppedState.GetObject; observers = new List <IObserver>(); }
public void Execute(IThreadState state) { if (!ShouldProcessDeferred()) { ThreadSleep.While(1000, state); return; } var pipeline = _pipelineFactory.GetPipeline<DeferredMessagePipeline>(); try { pipeline.State.ResetWorking(); pipeline.Execute(); if (pipeline.State.GetWorking()) { var transportMessage = pipeline.State.GetTransportMessage(); if (transportMessage.IgnoreTillDate < _ignoreTillDate) { _ignoreTillDate = transportMessage.IgnoreTillDate; } if (!_checkpointMessageId.Equals(transportMessage.MessageId)) { if (!Guid.Empty.Equals(_checkpointMessageId)) { return; } _checkpointMessageId = transportMessage.MessageId; _log.Trace(string.Format(Resources.TraceDeferredCheckpointMessageId, transportMessage.MessageId)); return; } } _nextDeferredProcessDate = _ignoreTillDate; _ignoreTillDate = DateTime.MaxValue; _checkpointMessageId = Guid.Empty; _log.Trace(_nextDeferredProcessDate.Equals(DateTime.MaxValue) ? Resources.TraceDeferredProcessingHalted : string.Format(Resources.TraceDeferredProcessingReset, _nextDeferredProcessDate.ToString("O"))); } finally { _pipelineFactory.ReleasePipeline(pipeline); } }
public static void While(int ms, IThreadState state, int step) { var elapsed = 0; while (state.Active && elapsed < ms) { Thread.Sleep(step); elapsed += step; } }
public EventHandlerContext(EventEnvelope eventEnvelope, T @event, PrimitiveEvent primitiveEvent, IThreadState activeState) { Guard.AgainstNull(eventEnvelope, nameof(eventEnvelope)); Guard.AgainstNull(@event, nameof(@event)); Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent)); Guard.AgainstNull(activeState, nameof(activeState)); ActiveState = activeState; Event = @event; PrimitiveEvent = primitiveEvent; EventEnvelope = eventEnvelope; }
public HandlerContext(IServiceBusConfiguration configuration, ITransportMessageFactory transportMessageFactory, IPipelineFactory pipelineFactory, ISubscriptionManager subscriptionManager, TransportMessage transportMessage, T message, IThreadState activeState) { Guard.AgainstNull(configuration, "configuration"); Guard.AgainstNull(transportMessage, "transportMessage"); Guard.AgainstNull(message, "message"); Guard.AgainstNull(activeState, "activeState"); _messageSender = new MessageSender(transportMessageFactory, pipelineFactory, subscriptionManager, transportMessage); TransportMessage = transportMessage; Message = message; ActiveState = activeState; Configuration = configuration; }
public HandlerContext(IServiceBus bus, TransportMessage transportMessage, T message, IThreadState activeState) { Guard.AgainstNull(bus, "bus"); Guard.AgainstNull(transportMessage, "transportMessage"); Guard.AgainstNull(message, "message"); Guard.AgainstNull(activeState, "activeState"); _messageSender = new MessageSender(bus, transportMessage); TransportMessage = transportMessage; Message = message; ActiveState = activeState; Configuration = bus.Configuration; }
public void Process(EventEnvelope eventEnvelope, object domainEvent, PrimitiveEvent primitiveEvent, IThreadState threadState) { Guard.AgainstNull(eventEnvelope, nameof(eventEnvelope)); Guard.AgainstNull(domainEvent, nameof(domainEvent)); Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent)); Guard.AgainstNull(threadState, nameof(threadState)); if (primitiveEvent.SequenceNumber <= SequenceNumber) { return; } var domainEventType = Type.GetType(eventEnvelope.AssemblyQualifiedName, true); try { if (!HandlesType(domainEventType)) { if (Log.IsTraceEnabled) { _log.Trace(string.Format(Resources.TraceTypeNotHandled, Name, eventEnvelope.AssemblyQualifiedName)); } return; } var contextType = typeof(EventHandlerContext <>).MakeGenericType(domainEventType); var method = _eventHandlers[domainEventType].GetType().GetMethod("ProcessEvent", new[] { contextType }); if (method == null) { throw new ProcessEventMethodMissingException(string.Format( Resources.ProcessEventMethodMissingException, _eventHandlers[domainEventType].GetType().FullName, domainEventType.FullName)); } var handlerContext = Activator.CreateInstance(contextType, eventEnvelope, domainEvent, primitiveEvent, threadState); method.Invoke(_eventHandlers[domainEventType], new[] { handlerContext }); } finally { SequenceNumber = primitiveEvent.SequenceNumber; } }
public virtual void Execute(IThreadState state) { var availableWorker = _workerAvailabilityManager.GetAvailableWorker(); if (_configuration.Inbox.Distribute && availableWorker == null) { _threadActivity.Waiting(state); return; } var messagePipeline = availableWorker == null ? _pipelineFactory.GetPipeline <InboxMessagePipeline>() : (IPipeline)_pipelineFactory.GetPipeline <DistributorPipeline>(); try { messagePipeline.State.SetAvailableWorker(availableWorker); messagePipeline.State.ResetWorking(); messagePipeline.State.SetActiveState(state); messagePipeline.State.SetTransportMessage(null); messagePipeline.State.SetReceivedMessage(null); if (!state.Active) { return; } messagePipeline.Execute(); if (messagePipeline.State.GetWorking()) { _events.OnThreadWorking(this, new ThreadStateEventArgs(typeof(InboxMessagePipeline))); _threadActivity.Working(); } else { _events.OnThreadWaiting(this, new ThreadStateEventArgs(typeof(InboxMessagePipeline))); _threadActivity.Waiting(state); } } finally { _pipelineFactory.ReleasePipeline(messagePipeline); } }
public virtual void Execute(IThreadState state) { var availableWorker = _bus.Configuration.WorkerAvailabilityManager.GetAvailableWorker(); if (_bus.Configuration.Inbox.Distribute && availableWorker == null) { _threadActivity.Waiting(state); return; } var messagePipeline = availableWorker == null ? _bus.Configuration.PipelineFactory.GetPipeline<InboxMessagePipeline>(_bus) : (MessagePipeline) _bus.Configuration.PipelineFactory.GetPipeline<DistributorPipeline>(_bus); try { messagePipeline.State.SetAvailableWorker(availableWorker); messagePipeline.State.ResetWorking(); messagePipeline.State.SetActiveState(state); if (!state.Active) { return; } messagePipeline.Execute(); if (messagePipeline.State.Get<bool>(StateKeys.Working)) { _bus.Events.OnThreadWorking(this, new ThreadStateEventArgs(typeof (InboxMessagePipeline))); _threadActivity.Working(); } else { _bus.Events.OnThreadWaiting(this, new ThreadStateEventArgs(typeof (InboxMessagePipeline))); _threadActivity.Waiting(state); } } finally { _bus.Configuration.PipelineFactory.ReleasePipeline(messagePipeline); } }
public virtual void Execute(IThreadState state) { var availableWorker = _bus.Configuration.WorkerAvailabilityManager.GetAvailableWorker(); if (_bus.Configuration.Inbox.Distribute && availableWorker == null) { _threadActivity.Waiting(state); return; } var messagePipeline = availableWorker == null ? _bus.Configuration.PipelineFactory.GetPipeline <InboxMessagePipeline>(_bus) : (MessagePipeline)_bus.Configuration.PipelineFactory.GetPipeline <DistributorPipeline>(_bus); try { messagePipeline.State.SetAvailableWorker(availableWorker); messagePipeline.State.ResetWorking(); messagePipeline.State.SetActiveState(state); if (!state.Active) { return; } messagePipeline.Execute(); if (messagePipeline.State.Get <bool>(StateKeys.Working)) { _bus.Events.OnThreadWorking(this, new ThreadStateEventArgs(typeof(InboxMessagePipeline))); _threadActivity.Working(); } else { _bus.Events.OnThreadWaiting(this, new ThreadStateEventArgs(typeof(InboxMessagePipeline))); _threadActivity.Waiting(state); } } finally { _bus.Configuration.PipelineFactory.ReleasePipeline(messagePipeline); } }
public void Execute(IThreadState state) { if (!ShouldProcessDeferred()) { ThreadSleep.While(1000, state); return; } lock (_messageDeferredLock) { _messageDeferred = false; } var pipeline = _bus.Configuration.PipelineFactory.GetPipeline<DeferredMessagePipeline>(_bus); pipeline.State.SetCheckpointMessageId(_checkpointMessageId); pipeline.State.SetNextDeferredProcessDate(_nextDeferredProcessDate); pipeline.State.SetDeferredMessageReturned(false); pipeline.Execute(); var nextDeferredProcessDate = pipeline.State.Get<DateTime>(StateKeys.NextDeferredProcessDate); if (_messageDeferred) { if (nextDeferredProcessDate < _nextDeferredProcessDate) { _nextDeferredProcessDate = nextDeferredProcessDate; } } else { _nextDeferredProcessDate = nextDeferredProcessDate; } if (_checkpointMessageId != pipeline.State.Get<Guid>(StateKeys.CheckpointMessageId)) { _checkpointMessageId = pipeline.State.Get<Guid>(StateKeys.CheckpointMessageId); return; } _checkpointMessageId = Guid.Empty; }
public void Execute(IThreadState state) { if (!ShouldProcessDeferred()) { ThreadSleep.While(1000, state); return; } lock (_messageDeferredLock) { _messageDeferred = false; } var pipeline = _bus.Configuration.PipelineFactory.GetPipeline <DeferredMessagePipeline>(_bus); pipeline.State.SetCheckpointMessageId(_checkpointMessageId); pipeline.State.SetNextDeferredProcessDate(_nextDeferredProcessDate); pipeline.State.SetDeferredMessageReturned(false); pipeline.Execute(); var nextDeferredProcessDate = pipeline.State.Get <DateTime>(StateKeys.NextDeferredProcessDate); if (_messageDeferred) { if (nextDeferredProcessDate < _nextDeferredProcessDate) { _nextDeferredProcessDate = nextDeferredProcessDate; } } else { _nextDeferredProcessDate = nextDeferredProcessDate; } if (_checkpointMessageId != pipeline.State.Get <Guid>(StateKeys.CheckpointMessageId)) { _checkpointMessageId = pipeline.State.Get <Guid>(StateKeys.CheckpointMessageId); return; } _checkpointMessageId = Guid.Empty; }
public void Waiting(IThreadState state) { var ms = (int) GetSleepTimeSpan().TotalMilliseconds; ThreadSleep.While(ms, state); }
void IProcessor.Execute(IThreadState state) { Execute(state); }
public static void While(int ms, IThreadState state) { // step size should be as large as possible, // max step size by default While(ms, state, MaxStepSize); }
public static void SetActiveState(this State<Pipeline> state, IThreadState activeState) { state.Add(StateKeys.ActiveState, activeState); }
public ThreadContext() { Console.WriteLine("Thread yaratıldı ve henüz çalışmıyor"); State = new StoppedState(); }
public static void SetActiveState(this IState state, IThreadState activeState) { state.Replace(StateKeys.ActiveState, activeState); }
public static void While(int ms, IThreadState state) { While(ms, state, 5); }
public void Waiting(IThreadState state) { var ms = (int)GetSleepTimeSpan().TotalMilliseconds; ThreadSleep.While(ms, state); }
public static void SetActiveState(this IState <IPipeline> state, IThreadState activeState) { state.Add(StateKeys.ActiveState, activeState); }