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;
            }
        }
Exemple #2
0
        public async Task Process(MyType e, StreamSequenceToken sequenceToken) // Implements the Process method from IFilter
        {
            List <MyType> result = new List <MyType>();

            if (e.value == "watermark")
            {
                result.Add(e);
            }
            else
            {
                string Key = await jobManager.GetKey(this.GetPrimaryKey());

                string Value = await jobManager.GetValue(this.GetPrimaryKey());

                MyType new_e = NewEvent.CreateNewEvent(e, Key, Value);
                result = Apply(new_e);
            }
            List <Task> t       = new List <Task>();
            List <Guid> streams = await jobManager.GetPublish(this.GetPrimaryKey());

            foreach (var item1 in streams)
            {
                var stream = streamProvider.GetStream <MyType>(item1, null);
                foreach (var item2 in result)
                {
                    t.Add(stream.OnNextAsync(item2));
                }
            }
            await Task.WhenAll(t);
        }
Exemple #3
0
        private async Task Process(MyType e, StreamSequenceToken sequenceToken)
        {
            // Console.WriteLine($"Filter Grain receives: {e.key}, {e.value}, {e.timestamp.GetTimestamp()}");
            bool   emit_e;
            MyType ee;

            if (e.value == "watermark")
            {
                ee     = e;
                emit_e = true;
            }
            else
            {
                string Key = await jobManager.GetKey(this.GetPrimaryKey());

                string Value = await jobManager.GetValue(this.GetPrimaryKey());

                ee     = NewEvent.CreateNewEvent(e, Key, Value);
                emit_e = Apply(ee);
            }

            List <Task> t = new List <Task>();

            if (emit_e) // If the function returns true, send the element to SinkGrain
            {
                List <Guid> streams = await jobManager.GetPublish(this.GetPrimaryKey());

                foreach (var item in streams)
                {
                    var stream = streamProvider.GetStream <MyType>(item, null);
                    t.Add(stream.OnNextAsync(ee));
                }
            }
            await Task.WhenAll(t);
        }
Exemple #4
0
        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;
            }
        }