view topology/manager/ConfigWaiter.cs @ 61:1a42115e51bb

fix
author KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
date Fri, 28 Jan 2022 23:15:05 +0900
parents 14222beab95b
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using Christie_net.annotation;
using Christie_net.codegear;


namespace Christie_net.topology.manager {

    public class ConfigWaiter : CodeGear {
        [Peek] public LinkedList<String> waiterNodeNames;
        [Take] public Message _DONEMESSAGE;
        [Take] public int nodeNum;
        
        public ConfigWaiter() {
        }

        public override void Run(CodeGearManager cgm) {
            nodeNum--;
            if (nodeNum == 0) {
                GetLocalDgm().Put("_STARTMESSAGE", new Message());
                foreach (String nodeName in waiterNodeNames) GetDgm(nodeName).Put("_STARTMESSAGE", new Message());
                GetLocalDgm().Put("startTime", CurrentTimeMillis());
                GetLocalDgm().Put("running", true);

                return;
            }

            cgm.Setup(new ConfigWaiter());
            GetLocalDgm().Put("nodeNum", nodeNum);
        }
        private static readonly DateTime Jan1st1970 = new DateTime
            (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        public static long CurrentTimeMillis()
        {
            return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
        }
    }
}