// FindBehavior to find the alias in directory private void FindBehavior(string msg1, T msg2) { // find in directory origMessage = msg2; Become(new Behavior <DirectoryActor.DirectoryRequest, IActor>(SendBehavior)); DirectoryActor.GetDirectory().Find(this, msg1); }
public EchoServerActor() : base() { HostDirectoryActor.Register(this); DirectoryActor.GetDirectory().Register(this, "EchoServer"); Become(new EchoServerBehavior()); }
public static void Register() { var console = new ActorConsole(); DirectoryActor.GetDirectory().Register(console, "Console"); Console.WriteLine(WelcomeConsole); }
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 }
public static void Register() { var console = new ActorConsole(); DirectoryActor.GetDirectory().Register(console, "Console"); Console.WriteLine("Console starts and autoregisters"); }
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)); }
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 DoRun(IActor actor, string data) { if (string.IsNullOrEmpty(data)) { DirectoryActor.GetDirectory().Disco(actor); } else { new DiscoveryActor(data); } }
private void Behavior(IActor msg) { // get number of actor in directory StringBuilder sb = new StringBuilder(); sb.AppendLine(DirectoryActor.GetDirectory().Stat()); // get number of actor in queue list sb.AppendLine(ActorTask.Stat()); // get number of actor in hostdirectory sb.AppendLine(HostDirectoryActor.GetInstance().GetStat()); msg.SendMessage(sb.ToString()); Become(new NullBehaviors()); }
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)); }
private void ProcessMessage(SerialObject aSerial) { // disco ? if ((aSerial.Data != null) && (aSerial.Data.GetType().Equals(typeof(DiscoCommand)))) { // ask directory entries for server //actHostDirectory.Register(this); DirectoryActor.GetDirectory().Disco(((DiscoCommand)aSerial.Data).Sender); } else { // or send to host directory HostDirectoryActor.GetInstance().SendMessage(aSerial); } }
public void Run(params object[] data) { if (data.Length < 2) { throw new ActorException("2 params expected"); } if (String.IsNullOrEmpty(data[1].ToString())) { DirectoryActor.GetDirectory().Disco((IActor)data[0]); } else { new DiscoveryActor(data[0].ToString()); } }
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(); }
private void ProcessMessage(object tobeSerial) { SerialObject aSerial = tobeSerial as SerialObject; if (tobeSerial is DataContractObject) { aSerial = new SerialObject(((DataContractObject)tobeSerial).Data, ((DataContractObject)tobeSerial).Tag); } // disco ? if (aSerial.Data?.GetType().Equals(typeof(DiscoCommand)) == true) { // ask directory entries for server //actHostDirectory.Register(this); DirectoryActor.GetDirectory().Disco(((DiscoCommand)aSerial.Data).Sender); } else { // or send to host directory HostDirectoryActor.GetInstance().SendMessage(aSerial); } }
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); }
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": { ActorStatServer sa = new ActorStatServer(); sa.SendMessage(asker); break; } case "GC": { GC.Collect(); 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": { // local disco ? if (String.IsNullOrEmpty(lData)) { DirectoryActor.GetDirectory().Disco(asker); } else { new DiscoveryActor(lData); // remote disco //actRemoteSend rem = new actRemoteSend(Data.Item1,lData, ""); //rem.SendMessage(new DiscoCommand(rem)); } 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; } } }