public IModulePipeline GetPipelineByFrom(ISystemPipeline system, string from, string urlActor)
        {
            if (bStarted == false)
            {
                throw new Exception("must getpipeline after System.Start()");
            }

            if (urlActor.IndexOf("this/") != 0)
            {
                throw new Exception("remote pipeonly");
            }
            var refName = from + "_" + urlActor;


            var actorpath    = urlActor.Substring(5);
            var targetModule = this.localModules[actorpath];

            var _from = refName == null ? null : this.GetPipeline(targetModule, from);

            return(refSystemThis.GetPipeLineByFrom(_from, targetModule));
            //if (refPipelines.TryGetValue(refName, out IModulePipeline pipe))
            //{
            //    return pipe;
            //}

            //{

            //    refSystemThis.GetPipeline(from, actorpath);
            //    refPipelines[refName] = new PipelineRefLocal(refSystemThis, from, actorpath, targetModule);
            //    return refPipelines[refName];
            //}
        }
Exemple #2
0
        public PipelineRefRemote(ISystemPipeline usersystem, string userPath, RefSystemRemote remotesystem, string path)
        {
            this._usersystem = usersystem;
            this.userpath    = userPath;

            this._remotesystem = remotesystem;
            this.path          = path;
        }
 public PipelineSystemV1(AllPet.Common.ILogger logger)
 {
     this.logger     = logger;
     localModules    = new global::System.Collections.Concurrent.ConcurrentDictionary <string, IModuleInstance>();
     localModulePath = new global::System.Collections.Concurrent.ConcurrentDictionary <IModuleInstance, string>();
     //refPipelines = new global::System.Collections.Concurrent.ConcurrentDictionary<string, IModulePipeline>();
     refSystems    = new global::System.Collections.Concurrent.ConcurrentDictionary <string, ISystemPipeline>();
     linkedIP      = new global::System.Collections.Concurrent.ConcurrentDictionary <ulong, string>();
     refSystemThis = new PipelineSystemRefLocal(this);
 }
Exemple #4
0
        void _OnPeerLink(ISystemPipeline system)//现在能区分主叫 connect 和 被叫 accept了
        {
            var pipe = linkNodes[system.PeerID];

            //主叫被叫都尝试加入对方网络
            logger.Info("--------------------------》_OnPeerLink:id/" + system.PeerID + "         IPEndPoint/" + system.Remote + "              BeAccepted:" + system.IsHost);

            Tell_ReqJoinPeer(pipe.remoteNode);
            if (this.isProved)
            {
                //告诉我你是否是共识节点或者能否到达共识节点
                Tell_Post_TouchProvedPeer(pipe.remoteNode, string.Empty, this.guid.ToString());
            }
            logger.Info("_OnPeerLink" + system.PeerID);
        }
Exemple #5
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _bootstrap = null !;
            _cleanup   = null !;
            _init      = null !;

            _beforeUpdate = null !;
            _update       = null !;
            _afterUpdate  = null !;

            _disposed = true;
        }
Exemple #6
0
        public SystemService(
            ISystemPipeline <IBootstrapSystem> bootstrap,
            ISystemPipeline <ICleanupSystem> cleanup,
            ISystemPipeline <IInitSystem> init,
            ISystemPipeline <IBeforeUpdateSystem> beforeUpdate,
            ISystemPipeline <IUpdateSystem> update,
            ISystemPipeline <IAfterUpdateSystem> afterUpdate)
        {
            _bootstrap = bootstrap;
            _cleanup   = cleanup;

            _init = init;

            _beforeUpdate = beforeUpdate;
            _update       = update;
            _afterUpdate  = afterUpdate;
        }
Exemple #7
0
        void _OnPeerClose(ISystemPipeline system)
        {
            if (linkNodes.TryRemove(system.PeerID, out LinkObj node))
            {
                var remotestr = node.remoteNode.system.Remote.ToString();
                this.linkIDs.TryRemove(remotestr, out ulong v);
                provedNodes.TryRemove(system.PeerID, out LinkObj keepernode);
                var canlink = this.listCanlink.Getqueue(remotestr);
                if (canlink?.weight > 0)
                {
                    canlink.weight--;
                }
                logger.Info("_OnPeerClose" + system.PeerID);

                //断开连接处理plevel
                losePlevelFromLinkObj(node);
            }
        }
Exemple #8
0
        //peerid 是连接id,而每个节点,需要一个唯一不重复的节点ID,以方便进行识别


        void RegNetEvent(ISystemPipeline syspipe)
        {
            //    //syspipe.HaltLink();
            //    if (syspipe.linked)
            //    {
            //        //logger.Info("==reg net event direct");
            //        _OnPeerLink(syspipe.PeerID, syspipe.IsHost, syspipe.Remote);
            //    }
            //    else
            //    {
            //        //logger.Info("==reg net event delay");
            //        syspipe.OnPeerLink += _OnPeerLink;
            //    }
            //    syspipe.OnPeerClose += _OnPeerClose;
            //    //syspipe.ResumeLink();

            syspipe.SetLinkEvent(this._OnPeerLink);
            syspipe.SetLinkCloseEvent(this._OnPeerClose);
        }
        public void DisConnect(ISystemPipeline pipe)
        {
            var id = pipe.PeerID;

            this.peer.Disconnect(pipe.PeerID);
        }
        public IModulePipeline GetPipeline(IModuleInstance user, string urlActor)
        {
            if (bStarted == false)
            {
                throw new Exception("must getpipeline after System.Start()");
            }

            var userstr = "";

            if (user != null)
            {
                userstr = localModulePath[user];
            }
            var refName = userstr + "_" + urlActor;

            //if (refPipelines.TryGetValue(refName, out IModulePipeline pipe))
            //{
            //    return pipe;
            //}

            if (urlActor[0] == '@')//收到通讯
            {
                var             sppos  = urlActor.IndexOf('/');
                var             addrid = UInt64.Parse(urlActor.Substring(1, sppos - 1));
                var             path   = urlActor.Substring(sppos + 1);
                var             addr   = linkedIP[addrid];
                ISystemPipeline refsys = null;
                if (refSystems.TryGetValue(addr, out refsys))
                {
                    return(refsys.GetPipeline(user, path));
                }
                else
                {//没连接
                    return(null);
                }
                //refPipelines[refName] = new PipelineRefRemote(refSystemThis, userstr, refsys as RefSystemRemote, path);
                //return refPipelines[refName];
            }
            if (urlActor.IndexOf("this/") == 0)//本地模块
            {
                var actorpath = urlActor.Substring(5);
                //var actor = this.localModules[actorpath];
                return(refSystemThis.GetPipeline(user, actorpath));
                //refPipelines[refName] = new PipelineRefLocal(refSystemThis, userstr, actorpath, actor);
                //return refPipelines[refName];
            }
            else //有地址的模块
            {
                var             sppos  = urlActor.IndexOf('/');
                var             addr   = urlActor.Substring(0, sppos);
                var             path   = urlActor.Substring(sppos + 1);
                ISystemPipeline refsys = null;
                if (refSystems.TryGetValue(addr, out refsys))
                {
                    IModulePipeline node = refsys.GetPipeline(user, path);
                    //if(PreInit!=null)
                    //{
                    //    PreInit(node);
                    //}
                    return(node);
                }
                else
                {//没连接
                    IModulePipeline node = null;
                    refsys = this.Connect(addr.AsIPEndPoint(), (system) => {
                        node = system.GetPipeline(user, path);
                        //if (PreInit != null)
                        //{
                        //    PreInit(node);
                        //}
                    });
                    return(node);
                }

                //refPipelines[refName] = new PipelineRefRemote(refSystemThis, userstr, refsys as RefSystemRemote, path);
                //return refPipelines[refName];
            }
        }