private void SendRemoteMessage(object aMsg)
        {
            // send message with http
            SerialObject so = new SerialObject(aMsg, fRemoteTag);

            MemoryStream ms = null;

            try
            {
                ms = new MemoryStream();

                fSerializeService.Serialize(so, ms);

                ms.Seek(0, SeekOrigin.Begin);

                IContextComm contextComm = ActorServer.GetInstance().ListenerService.GetCommunicationContext();
                contextComm.SendStream(so.Tag.Host, ms);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Dispose();
                    ms = null;
                }
            }
        }
 public RemoteSenderActor(ActorTag aTag)
     : base()
 {
     fRemoteTag        = aTag;
     fSerializeService = ActorServer.GetInstance().SerializeService;
     Become(new Behavior <object>(DoRouting));
 }
Beispiel #3
0
        public static ShardDirectoryActor AttachShardDirectoryActor(ActorServer actorServer)
        {
            CheckArg.Actor(actorServer);
            IActor shardFound = DirectoryActor.GetDirectory().GetActorByName("KnownShards");

            if (shardFound != null)
            {
                return((ShardDirectoryActor)shardFound);
            }
            return(new ShardDirectoryActor(actorServer));
        }
Beispiel #4
0
 public ShardDirectoryActor()
     : base()
 {
     fShardList = new Dictionary <string, string>();
     fShardList.Add("LocalHost", ActorServer.GetInstance().FullHost);
     DirectoryActor.GetDirectory().Register(this, "KnownShards");
     HostDirectoryActor.Register(this);
     Become(new Behavior <ShardRequest>(
                t => t is ShardRequest,
                DoProcessShardRequest));
 }
        private void DoDisco(IActor anActor)
        {
            Dictionary <string, string> directory = new Dictionary <string, string>();
            string fullhost = ActorServer.GetInstance().FullHost;

            foreach (string key in _dictionary.Keys)
            {
                IActor value = _dictionary[key];
                directory.Add(key, fullhost + value.Tag.Key());
            }
            anActor.SendMessage(directory);
        }
 public ShardDirectoryActor(ActorServer actorServer)
     : base()
 {
     fShardList = new Dictionary <string, string>
     {
         { "LocalHost", actorServer.FullHost }
     };
     DirectoryActor.GetDirectory().Register(this, "KnownShards");
     HostDirectoryActor.Register(this);
     Become(new Behavior <ShardRequest>(
                t => t is ShardRequest,
                DoProcessShardRequest));
 }
Beispiel #7
0
        private void DoDisco(IActor anActor)
        {
            Dictionary <string, string> directory = new Dictionary <string, string>();
            // TODO replace with Host Service
            var fullhost = ActorServer.GetInstance().FullHost;

            // var fullhost = new ConfigManager().Host().Host;
            foreach (string key in fDictionary.Keys)
            {
                var value = fDictionary[key];
                directory.Add(key, fullhost + value.Tag.Key());
            }
            anActor.SendMessage(directory);
        }
Beispiel #8
0
 public static void Start(ConfigManager configManager)
 {
     fServerInstance = new ActorServer
     {
         fConfigManager = configManager ?? throw new ActorException("ConfigManager can't be null"),
                                Name             = configManager.Host().Host,
                                Port             = configManager.Host().Port,
                                ListenerService  = configManager.GetListenerService(),
                                SerializeService = configManager.GetSerializeService(),
                                HostService      = configManager.GetHostService()
     };
     ActorTagHelper.FullHost = configManager.Host().Host;
     fServerInstance.DoInit(new HostRelayActor(fServerInstance.ListenerService));
 }
Beispiel #9
0
 private void DoListen(Object aMsg)
 {
     try
     {
         if (fListener == null)
         {
             fListener = ActorServer.GetInstance().ListenerService;
         }
         IContextComm context = fListener.GetCommunicationContext();
         RemoteReceiverActor.Cast(context);
         SendMessage("Listen");
     }
     catch (Exception e)
     {
         Debug.WriteLine("Can't listen " + e);
         Become(new NullBehavior());
     }
 }
Beispiel #10
0
        public static void Start(ActorConfigManager configManager)
        {
            CheckArg.ActorConfigManager(configManager);
            ActorTagHelper.FullHost = configManager.Host().Host;

            _serverInstance = new ActorServer
            {
                _configManager = configManager ?? throw new ActorException(MessageNullConfigManager),
                                       Name = configManager.Host().Host,
                                       Port = configManager.Host().Port
            };

            _serverInstance.ListenerService      = configManager.GetListenerService();
            _serverInstance.SerializeService     = configManager.GetSerializeService();
            _serverInstance.HostService          = configManager.GetHostService();
            _serverInstance.ServerCommandService = ActorConfigManager.GetServerCommandService();
            _serverInstance.DoInit(new HostRelayActor(_serverInstance.ListenerService));
        }
Beispiel #11
0
        private void StartServer()
        {
            var          localhost  = Dns.GetHostName();
            var          servername = ActorServer.GetInstance().Name;
            const string prefix     = "http://";
            var          suffix     = ":" + ActorServer.GetInstance().Port.ToString(CultureInfo.InvariantCulture);

            fListener.Prefixes.Add(prefix + "localhost" + suffix + "/" + servername + "/");
            fListener.Prefixes.Add(prefix + localhost + suffix + "/" + servername + "/");
            fListener.Prefixes.Add(prefix + "127.0.0.1" + suffix + "/" + servername + "/");
            try
            {
                fListener.Start();
            }
            catch (HttpListenerException e)
            {
                Debug.WriteLine("Can't start http " + e);
            }
        }
Beispiel #12
0
 public RemoteReceiverActor()
 {
     fSerializeService = ActorServer.GetInstance().SerializeService;
     Become(new Behavior <IContextComm, Stream>((i, t) => { return(true); }, DoContext));
 }
 public static void CompleteInitialize(RemoteSenderActor anActor)
 {
     CheckArg.Actor(anActor);
     anActor.fSerializeService = ActorServer.GetInstance().SerializeService;
     anActor.Become(new Behavior <object>(anActor.DoRouting));
 }
Beispiel #14
0
 public static void Start(string lName, int lPort, HostRelayActor hostRelayActor)
 {
     fServerInstance = new ActorServer(lName, lPort);
     fServerInstance.DoInit(hostRelayActor);
 }
        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.Send(req, "KnownShards");
                }
                else
                {
                    ConnectActor.Connect(this, lData, "KnownShards");
                    ReceiveAsync(ans => 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);
                        }, TaskScheduler.Default);
                }
                break;
            }

            case "Stat":
            {
                ActorServer.GetInstance().SendMessage(StatServerCommand.Name, asker);
                // (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 = ReceiveAsync(ans => 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":
            {
                ActorServer.GetInstance().SendMessage(DiscoServerCommand.Name, (IActor)asker, lData);
                // 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 = ReceiveAsync(ans => 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;
            }
            }
        }