private void OnColumnsCountChanged() { eventStream.Publish(new MatrixSizeChanged { ColumnsCount = ColumnsCount }); }
void OnTick(object state) { var ready = new Collection <Tuple <Guid, DateTime?> >(); var notReady = new Collection <Tuple <Guid, DateTime?> >(); try { Tuple <Guid, DateTime?> item; _eventStream.Publish <FailedJobQueue>( EventType.TimerActivity, EventProperty.ActivityName("RescheduleFailedJobs"), EventProperty.Named("FailedItemsQueueLength", _jobFailures.Count)); while (_jobFailures.TryTake(out item)) { if (item.Item2 < _now()) { ready.Add(item); } else { notReady.Add(item); } } foreach (var job in ready.Select(i => _persistenceStore.Load(i.Item1))) { _router.Route(job); } ready.Clear(); } catch (Exception e) { if (e.IsFatal()) { throw; } _eventStream.Publish <FailedJobQueue>(e); } finally { foreach (var item in ready.Concat(notReady)) { _jobFailures.Add(item); } _timer.Change(_configuration.RetryTimerInterval, Timeout.InfiniteTimeSpan); } }
public void Should_receive_all_events_published_as_a_stream() { ManualResetEvent signal = new ManualResetEvent(false); ReaderHandler handler = new ReaderHandler(signal); _streamingBus.SubscribeToReader(handler); IList <TestStreamEvent> streamEvents = new List <TestStreamEvent>(); streamEvents.Add(new TestStreamEvent(1)); streamEvents.Add(new TestStreamEvent(2)); streamEvents.Add(new TestStreamEvent(3)); using (IEventStream stream = _streamingBus.CreateStream(typeof(TestStreamEvent).FullName)) { stream.BatchLimit = 2; foreach (TestStreamEvent @event in streamEvents) { stream.Publish(@event); } } signal.WaitOne(TimeSpan.FromSeconds(10)); Assert.That(handler.ReceivedEvents, Is.Not.Null, "The collection of events was not receieved before the timeout expired."); Assert.That(handler.ReceivedEvents.Length, Is.EqualTo(3)); Assert.That(handler.ReceivedEvents.Select(e => e.Event), Is.Ordered.By("Sequence")); }
public Job Mutate <TSource>(Job job, JobStatus?status = null, int?dispatchCount = null, DateTime?retryOn = null, Continuation continuation = null, bool?suspended = null) { var newJob = new Job(job.Id, job.Type, job.Method, job.Arguments, job.CreatedOn, job.RootId, job.ParentId, job.CorrelationId, status ?? job.Status, dispatchCount ?? job.DispatchCount, retryOn ?? job.RetryOn, job.ExceptionFilters, continuation ?? job.Continuation, suspended ?? job.Suspended); _repository.Store(newJob); if (job.Status != newJob.Status) { _eventStream.Publish <TSource>( EventType.JobStatusChanged, EventProperty.JobSnapshot(job), EventProperty.FromStatus(job.Status), EventProperty.ToStatus(newJob.Status)); } return(newJob); }
/// <summary> /// Raises on each change of the selected cell /// </summary> public void OnSelectedCellChanged(SelectedCellsChangedEventArgs e) { var cell = e.AddedCells.FirstOrDefault(); if (cell.IsValid) { var row = (cell.Item as DataRowView).Row; var rowIndex = matrixRepresentation.GetRowIndex(row); var columnIndex = cell.Column.DisplayIndex; matrixRepresentation.ChangeSelectedCell(rowIndex, columnIndex); matrixRepresentation.ChangeSelectedCellValue(); eventStream.Publish(new MatrixChanged()); } }
void PublishQueueInitializedEvent(int activityCount, int suspendedCount, Type activityType = null) { _eventStream.Publish <JobQueueFactory>( EventType.Activity, EventProperty.ActivityName("JobQueueInitialized"), EventProperty.Named("ActivityType", activityType == null ? "All" : activityType.FullName), EventProperty.Named("ActivityCount", activityCount), EventProperty.Named("SuspendedCount", suspendedCount)); }
async Task <Job[]> LoadSuspended() { var list = new List <Job>(); while (list.Count == 0) { try { var max = Configuration.MaxQueueLength; var items = (Configuration.Type != null ? _persistenceStore.LoadSuspended(Configuration.Type, max) : _persistenceStore.LoadSuspended(_allActivityConfiguration.Select(c => c.Type), max)) .ToArray(); _eventStream.Publish <JobQueue>(EventType.Activity, EventProperty.ActivityName("LoadSuspendedItemsStarted"), EventProperty.Named("NumberOfItems", items.Length)); list.AddRange(items.Select(item => _jobMutator.Mutate <JobQueue>(item, suspended: false))); } catch (Exception e) { if (e.IsFatal()) { throw; } _eventStream.Publish <JobQueue>(e); } if (!list.Any()) { await Task.Delay(Configuration.RetryDelay); } } _eventStream.Publish <JobQueue>(EventType.Activity, EventProperty.ActivityName("LoadSuspendedItemsFinished"), EventProperty.Named("NumberOfItems", list.Count)); return(list.ToArray()); }
async Task Dispatch(Job job, ActivityConfiguration configuration) { await Task.Run(async() => { try { await _dispatcher.Dispatch(job, configuration); } catch (Exception e) { if (e.IsFatal()) { throw; } _eventStream.Publish <JobPump>(e); } }) .FailFastOnException(); }
public static void Main(string[] args) { IApplicationContext springContainer = ContextRegistry.GetContext(); IStandardStreamingEventBus streamingEventBus = springContainer.GetObject( typeof(IStandardStreamingEventBus).FullName) as IStandardStreamingEventBus; IList <ModernMajorGeneralMessage> streamMessages = new List <ModernMajorGeneralMessage>(); streamMessages.Add(new ModernMajorGeneralMessage("I am ")); streamMessages.Add(new ModernMajorGeneralMessage("the very ")); streamMessages.Add(new ModernMajorGeneralMessage("model of ")); streamMessages.Add(new ModernMajorGeneralMessage("a Modern ")); streamMessages.Add(new ModernMajorGeneralMessage("Major-General ")); streamMessages.Add(new ModernMajorGeneralMessage("I've information ")); streamMessages.Add(new ModernMajorGeneralMessage("vegetable, animal, ")); streamMessages.Add(new ModernMajorGeneralMessage("and mineral, ")); streamMessages.Add(new ModernMajorGeneralMessage("I know the kings of England, ")); streamMessages.Add(new ModernMajorGeneralMessage("and I quote the fights historical, ")); streamMessages.Add(new ModernMajorGeneralMessage("From Marathon to Waterloo, ")); streamMessages.Add(new ModernMajorGeneralMessage("in order categorical; ")); using (IEventStream stream = streamingEventBus.CreateStream(typeof(ModernMajorGeneralMessage).FullName)) { stream.BatchLimit = 2; foreach (ModernMajorGeneralMessage message in streamMessages) { stream.Publish(message); } } Environment.Exit(0); }
public void Dispatch(Job job, Exception exception, JobContext context, IDependencyScope scope) { if (job == null) { throw new ArgumentNullException("job"); } if (exception == null) { throw new ArgumentNullException("exception"); } if (context == null) { throw new ArgumentNullException("context"); } if (scope == null) { throw new ArgumentNullException("scope"); } foreach (var filter in job.ExceptionFilters) { try { DispatchCore(filter, exception, context, scope); } catch (Exception e) { if (e.IsFatal()) { throw; } _eventStream.Publish <ExceptionFilterDispatcher>(e); } } }
public void Publish(IEventStream eventStream) { eventStream.Publish(this, _unpublishedEvents); _unpublishedEvents.Clear(); }