private async Task Process(MyType e, StreamSequenceToken sequenceToken) { List <Guid> streams = await jobManager.GetPublish(this.GetPrimaryKey()); List <Task> t = new List <Task>(); Console.WriteLine($"AggregateGrain receives:{e.key}, {e.value}, {e.timestamp.GetTimestamp()}"); MyType ee; if (e.value == "watermark") { ee = e; } else { string Key = await jobManager.GetKey(this.GetPrimaryKey()); string Value = await jobManager.GetValue(this.GetPrimaryKey()); ee = NewEvent.CreateNewEvent(e, Key, Value); } var r = func.FeedData(ee); // r could be an empty dictionary if (r.Count > 0) { foreach (KeyValuePair <long, List <MyType> > records in r) { MyType watermark = new MyType("", "watermark", new Timestamp(records.Key)); List <MyType> result = Apply(records.Value); foreach (var item in streams) { var stream = streamProvider.GetStream <MyType>(item, null); foreach (var record in result) { t.Add(stream.OnNextAsync(record)); } } await Task.WhenAll(t); t = new List <Task>(); foreach (var item in streams) { var stream = streamProvider.GetStream <MyType>(item, null); t.Add(stream.OnNextAsync(watermark)); } await Task.WhenAll(t); } await Task.WhenAll(t); } else { await Task.CompletedTask; } }
public async Task Process1(MyType e, StreamSequenceToken sequenceToken) // Implement the Process method from IJoinGrain { MyType new_e; if (e.value == "watermark") { new_e = e; //Console.WriteLine($"Source data 1 receives watermark: {e.timestamp.GetTimestamp()}"); } else { //TODO: to many calls to jobManager var key = await jobManager.GetKey(this.GetPrimaryKey()); var value = await jobManager.GetValue(this.GetPrimaryKey()); string Key = key.Split(",")[0]; string Value = value.Split(",")[0]; new_e = NewEvent.CreateNewEvent(e, Key, Value); } var r = func1.FeedData(new_e); // r could be an empty list //Console.WriteLine("finish feeding data to func1"); if (r.Count > 0) { foreach (KeyValuePair <long, List <MyType> > ee in r) { if (!data1.ContainsKey(ee.Key)) { data1.Add(ee.Key, ee.Value); } else { throw new Exception($"Exception: data1 already has the key {ee.Key}"); } } var removed_key = await CheckIfCanJoin(); foreach (var item in removed_key) { data1.Remove(item); data2.Remove(item); } } else { await Task.CompletedTask; } }