Esempio n. 1
0
 protected void DoConnect(string order, string host)
 {
     // find in directory
     DirectoryActor.GetDirectory().Find(this, host);
     ReceiveAsync(ask => (ask is IMessageParam <DirectoryActor.DirectoryRequest, IActor>)).ContinueWith(
         r =>
     {
         IMessageParam <DirectoryActor.DirectoryRequest, IActor> ans = (IMessageParam <DirectoryActor.DirectoryRequest, IActor>)(r.Result);
         if (ans.Item2 != null)
         {
             SendByName.Send("Server found", "Console");
             ans.Item2.SendMessage(new ServerMessage <string>(this, ServerRequest.Connect, default));
             ReceiveAsync(m =>
             {
                 ServerMessage <string> sm = m as ServerMessage <string>;
                 return(m != null && (sm.Request.Equals(ServerRequest.Accept)));
             }).ContinueWith(
                 (c) =>
             {
                 SendByName.Send("Client connected", "Console");
                 aClient.Connect(ans.Item2);
                 Become(aClient);
             }, TaskScheduler.Default);
         }
         else
         {
             // Console.WriteLine("Retry");
             this.SendMessage(order, host);
             // Become(null);
         }
     }, TaskScheduler.Default);
     // repeat message
 }
Esempio n. 2
0
 protected override void ReceiveAnswer(ServerMessage <string> aMessage)
 {
     // echo to console
     if (aMessage != null)
     {
         SendByName <string> .Send(
             "client receive " + aMessage.Data, "Console");
     }
 }
Esempio n. 3
0
        private void DoInit(HostRelayActor hostRelayActor)
        {
            DirectoryActor.GetDirectory(); // Start directory
            ActorConsole.Register();       // Start console
            // should work now
            SendByName <string> .Send("Actor Server Start", "Console");

            Become(new NullBehavior());
            if (hostRelayActor != null)
            {
                ListenerService = fConfigManager.GetListenerService();
                new ShardDirectoryActor(this); // start shard directory
                fActHostRelay = hostRelayActor;
                fActHostRelay.SendMessage("Listen");
            }
            // new actTcpServer();
        }
Esempio n. 4
0
 protected override void DoRequest(ServerMessage <string> aMessage)
 {
     if (aMessage != null)
     {
         // echo to console
         SendByName.Send(
             "server receive " + aMessage.Data, "Console");
         // back to client but we need client
         if (aMessage.Client == null)
         {
             Debug.WriteLine("receive null client");
         }
         SendAnswer(aMessage, aMessage.Data);
     }
     else
     {
         throw new ActorException(MessageBhvEchoServer);
     }
 }
Esempio n. 5
0
        private void DoInit(HostRelayActor hostRelayActor)
        {
            DirectoryActor.GetDirectory(); // Start directory
            ActorConsole.Register();       // Start console
            // should work now
            SendByName.Send("Actor Server Start", "Console");
            if (ServerCommandService == null)
            {
                ServerCommandService = new ServerCommandService();
                ServerCommandService.RegisterCommand(new DiscoServerCommand());
                ServerCommandService.RegisterCommand(new StatServerCommand());
            }
            Become(ServerCommandService);
            if (hostRelayActor == null)
            {
                return;
            }

            ListenerService = _configManager.GetListenerService();
            ShardDirectoryActor.AttachShardDirectoryActor(this);
            _actHostRelay = hostRelayActor;
            _actHostRelay.SendMessage(HostRelayActor.ListenOrder);
        }
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;
            }
            }
        }