Esempio n. 1
0
        public static ShardRequest CastRequest(IActor aSender, IActor aTarget)
        {
            var req = new ShardRequest();

            req.RequestType = "Ask";
            req.Sender      = aSender;
            req.Target      = aTarget;
            return(req);
        }
Esempio n. 2
0
        public ShardRequest CastAnswer(IEnumerable <string> someData)
        {
            var req = new ShardRequest();

            req.RequestType = "Answer";
            req.Sender      = this.Sender;
            req.Target      = this.Target;
            req.Data        = new List <string>(someData);
            return(req);
        }
        public static ShardRequest CastRequest(IActor aSender, IActor aTarget)
        {
            var req = new ShardRequest()
            {
                RequestType = "Ask",
                Sender      = aSender,
                Target      = aTarget
            };

            return(req);
        }
        public ShardRequest CastAnswer(IEnumerable <string> someData)
        {
            var req = new ShardRequest()
            {
                RequestType = "Answer",
                Sender      = this.Sender,
                Target      = this.Target,
                Data        = new List <string>(someData)
            };

            return(req);
        }
Esempio n. 5
0
        private void DoProcessShardRequest(ShardRequest msg)
        {
            switch (msg.RequestType)
            {
            case "Ask":
            {
                var ans = msg.CastAnswer(fShardList.Values.AsEnumerable <string>());
                msg.Target.SendMessage(ans);
                break;
            }

            case "Answer":
            {
                foreach (var item in msg.Data)
                {
                    fShardList.Add(item, item);
                }
                break;
            }

            default: break;
            }
        }
Esempio n. 6
0
        private void Behavior(IActor asker, string Data)
        {
            char[] separ    = { ' ' };
            var    lStrings = Data.Split(separ, StringSplitOptions.RemoveEmptyEntries);
            var    lOrder   = lStrings[0];
            var    lData    = Data.Replace(lOrder, "").TrimStart();

            switch (lOrder)
            {
            case "Shard":
            {
                if (string.IsNullOrEmpty(lData))
                {
                    ShardRequest req = ShardRequest.CastRequest(this, asker);
                    SendByName <ShardRequest> .Send(req, "KnownShards");
                }
                else
                {
                    ConnectActor.Connect(this, lData, "KnownShards");
                    Receive(ans => { return(ans is IMessageParam <string, ActorTag, IActor>); }).ContinueWith(
                        ans =>
                        {
                            var res          = ans.Result as IMessageParam <string, ActorTag, IActor>;
                            ShardRequest req = ShardRequest.CastRequest(this, asker);
                            res.Item3.SendMessage(req);
                        });
                }
                break;
            }

            case "Stat":
            {
                (new StatServerCommand()).Run(asker);
                break;
            }

            case "AddTask":
            {
                // add a task
                break;
            }

            case "RemoteEcho":
            {
                // have a disco
                // find EchoServer
                // send message
                char[] separ2   = { ' ' };
                string lHost    = lData.Split(separ2)[0];
                string lService = lData.Split(separ2)[1];
                ConnectActor.Connect(this, lHost, lService);
                var data = Receive(ans => { return(ans is IMessageParam <string, ActorTag, IActor>); });
                var res  = data.Result as IMessageParam <string, ActorTag, IActor>;
                // we got remote server adress
                EchoClientActor aClient = new EchoClientActor();
                aClient.Connect(res.Item1);
                aClient.SendMessage("KooKoo");
                // res.Item3.SendMessage("call from " + this.Tag.Id);
                break;
            }

            case "Disco":
            {
                (new DiscoServerCommand()).Run(asker, lData);
                break;
            }

            case "SendTo":
            {
                RemoteNetActor.SendString(lData);
                break;
            }

            case "RPrint":
            {
                char[] separ2 = { ' ' };
                string lHost  = lData.Split(separ2)[0];
                string lMsg   = lData.Split(separ2)[1];
                ConnectActor.Connect(this, lHost, "RPrint");
                var data = Receive(ans => { return(ans is IMessageParam <string, ActorTag, IActor>); });
                var res  = data.Result as IMessageParam <string, ActorTag, IActor>;
                res.Item3.SendMessage("call  from " + this.Tag.Key());
                // SendMessageTo("call from " + this.Tag.Id,res.Item3);
                break;
            }
            }
        }