コード例 #1
0
        public void send(RTAddress from, TMsg msg, Func <TSource, bool> fn)
        {
            var ctx = new msg.MsgContext <TSource, TMsg>(from, msg, fn, false);

            m_q.Enqueue(ctx);
            //m_wait.Set();
        }
コード例 #2
0
        public Task <msg.Answer <TSource, TMsg>[]> ask(RTAddress from, TMsg msg, Func <TSource, bool> fn)
        {
            var ctx = new msg.MsgContext <TSource, TMsg>(from, msg, fn, true);

            m_q.Enqueue(ctx);
            //m_wait.Set();

            // @@@@ PORT ASK
            return(null);
        }
コード例 #3
0
        internal void sendPing(RTAddress address)
        {
            var ping = new msg.Ping {
                address = address
            };

            var whichService = m_rand.Next(m_otherServices.Count);

            s_mgr.send(address, m_otherServices[whichService], ping);
        }
コード例 #4
0
        public void broadcast(RTAddress from, TMsg msg)
        {
            var ctx = new msg.MsgContext <TSource, TMsg>(from, msg, (svc) => true, false);

            foreach (var svc in m_services)
            {
                svc.Value.deliver(from, ctx);
            }

            //m_wait.Set();
        }
コード例 #5
0
        virtual internal void handle(msg.Startup startup)
        {
            log.debug($"{(uint)id & 0xffff:X4} got Startup from");

            var address = new RTAddress(s_mgr.Id, id);
            var ready   = new msg.Ready {
                address = address
            };

            s_mgr.broadcast(address, ready);
        }
コード例 #6
0
        override internal void handle(msg.Startup startup)
        {
            base.handle(startup);

            var address = new RTAddress(s_mgr.Id, id);

            log.info($"Starting up {cfg.res.services.Length} services");
            foreach (var svc in cfg.res.services)
            {
                send(svc, address);
            }
        }
コード例 #7
0
        public void send(RTAddress from, RTAddress to, TMsg msg)
        {
            var ctx = new msg.MsgContext <TSource, TMsg>(from, msg, (svc) => svc.id == to.Source, false);

            if (m_services.TryGetValue(to.Source, out var svc))
            {
                svc.deliver(from, ctx);
            }
            else
            {
                m_q.Enqueue(ctx);
            }

            //m_wait.Set();
        }
コード例 #8
0
        internal void handle(msg.Ready ready)
        {
            log.debug($"{(uint)id & 0xffff:X4}  got Ready from {ready.address}");

            var address = new RTAddress(s_mgr.Id, id);

            if (address != ready.address && !m_otherServices.Contains(ready.address))
            {
                log.debug($"{(uint)id & 0xffff:X4} READY adding service {ready.address}");
                m_otherServices = m_otherServices.Add(ready.address);

                var readyBack = new msg.Ready {
                    address = address
                };

                var whichService = ready.address;

                send(readyBack, whichService);

                //sendPing( address );
            }
        }
コード例 #9
0
        void handle(msg.Ping ping)
        {
            ++m_pingsRecvd;

            var ts = DateTime.Now - m_lastLoggedPing;

            if (ts.TotalSeconds > 1.0)
            {
                log.debug($"{(uint)id & 0xffff:X4} got {m_pingsRecvd} Pings in {ts.TotalSeconds} seconds");

                m_lastLoggedPing = DateTime.Now;
                m_pingsRecvd     = 0;
            }

            //log.debug( $"{(uint)id & 0xffff:X4}  got Ping from {ping.address}" );

            var address = new RTAddress(s_mgr.Id, id);

            /*
             * if( address != ping.address && !m_otherServices.Contains(ping.address) )
             * {
             *      log.debug( $"{(uint)id & 0xffff:X4}  PING adding service {ping.address}" );
             *      m_otherServices = m_otherServices.Add( ping.address );
             * }
             */

            var tsFullTest = DateTime.Now - m_startPingTest;

            if (tsFullTest.TotalSeconds < cfg.res.testPingSec)
            {
                sendPing(address);
            }
            else
            {
                log.info($"Finished doing Ping tests.");
            }
        }
コード例 #10
0
        public void handle(msg.StartService start)
        {
            Type[]   types = new Type[1];
            object[] parms = new object[1];

            //types[0] = typeof( lib.Token );

            Type svcType = Type.GetType(start.type);

            if (svcType != null)
            {
                // @@@ DEPENDENCY This implies that all services are a subclass of a class that has 1
                // generic argument that is its config type
                Type cfgType = svcType.BaseType.GenericTypeArguments[0];

                //res.Ref cfg = res.Mgr.lookup( start.configPath, cfgType );

                var refGenType = typeof(res.Ref <>);

                var refType = refGenType.MakeGenericType(cfgType);

                var cfg = Activator.CreateInstance(refType, start.configPath);

                if (cfg != null)
                {
                    types[0] = cfg.GetType();

                    ConstructorInfo cons = svcType.GetConstructor(types);

                    try
                    {
                        //parms[0] = new lib.Token( start.name );
                        parms[0] = cfg;

                        log.info($"Starting service {"unknown"} of type {refType.Name} using config {start.configPath}");

                        svc.Service <msg.Msg> newService = (svc.Service <msg.Msg>)cons.Invoke(parms);

                        s_mgr.start(newService);



                        var startupMsg = new msg.Startup {
                        };

                        var svcAddress = new RTAddress(s_mgr.Id, newService.id);

                        //var delayMsg = new msg.DelaySend { address = svcAddress, msg = startupMsg };


                        //s_mgr.send(  )

                        send(startupMsg, svcAddress);
                    }
                    catch (Exception ex)
                    {
                        log.error($"Exception while calling service constructor {ex}");
                    }
                }
                else
                {
                    log.warn($"Could not find service of type {start.type}");
                }
            }
            else
            {
                log.warn($"Could not find service of type {start.type}");
            }
        }
コード例 #11
0
 public Task <Answer <Service <TMsg>, TMsg> > deliverAsk(RTAddress from, msg.MsgContext <Service <TMsg>, TMsg> ctx)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public void deliver(RTAddress from, msg.MsgContext <Service <TMsg>, TMsg> ctx)
 {
     m_q.Enqueue(ctx);
     //m_event.Set();
 }
コード例 #13
0
 public void send(TMsg msg, RTAddress to, [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = 0)
 {
     //msg.setSender_fromService( this );
     //msg.setCaller_fromService( callerFilePath, callerMemberName, callerLineNumber );
     s_mgr.send(new RTAddress(s_mgr.Id, id), to, msg);
 }