Esempio n. 1
0
        private static async Task DemoAsync(Type demo, string[] args)
        {
            Console.WriteLine($"{demo.Name}");
            Console.WriteLine(new string('=', 79));
            Console.WriteLine();

            var methods = demo.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                          .Where(m => m.Name.StartsWith("Demo") && m.GetParameters().Length == 0);

            foreach (var method in methods)
            {
                var orgColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("* " + method.Name);
                Console.ForegroundColor = orgColor;

                var system = ActorSystem.Create("Demo", "akka.suppress-json-serializer-warning=on");
                DeadRequestProcessingActor.Install(system);

                var demoInstance = Activator.CreateInstance(demo, system, args);
                var result       = method.Invoke(demoInstance, new object[0]);
                if (result is Task)
                {
                    await(Task) result;
                }

                Console.WriteLine();
                await system.Terminate();
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            var system = ActorSystem.Create("MySystem", "akka.suppress-json-serializer-warning=on");

            DeadRequestProcessingActor.Install(system);
            TestAsync(system).Wait();
        }
Esempio n. 3
0
        private static ActorSystem CreateClient(Config commonConfig)
        {
            var config = commonConfig.WithFallback("akka.remote.helios.tcp.port = 9002");
            var system = ActorSystem.Create("Client", config);

            DeadRequestProcessingActor.Install(system);
            return(system);
        }
        bool ServiceControl.Start(HostControl hostControl)
        {
            // initialize actor system
            _system = ActorSystem.Create("GameServer");
            DeadRequestProcessingActor.Install(_system);

            // start gateway to accept clients
            _gateway = StartListen(_system, ChannelType.Tcp, 5000).Result;
            return(true);
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            if (typeof(IServer) == null)
            {
                throw new Exception("Force interface module to be loaded");
            }

            var system = ActorSystem.Create("MySystem");

            DeadRequestProcessingActor.Install(system);

            StartListen(system, 8081);

            Console.WriteLine("Please enter key to quit.");
            Console.ReadLine();
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            System = ActorSystem.Create("MySystem");

            DeadRequestProcessingActor.Install(System);

            var greeter    = System.ActorOf <GreetingActor>("greeter");
            var counter    = System.ActorOf <CounterActor>("counter");
            var calculator = System.ActorOf <CalculatorActor>("calculator");
            var pedantic   = System.ActorOf <PedanticActor>("pedantic");

            StartAsync().Wait();

            Console.WriteLine("Enter to quit");
            Console.ReadLine();

            StopAsync().Wait();
        }
Esempio n. 7
0
        public void Initialize(ActorSystem system)
        {
            DeadRequestProcessingActor.Install(system);

            var context = new ClusterNodeContext {
                System = system
            };

            context.ClusterActorDiscovery = system.ActorOf(Props.Create(
                                                               () => new ClusterActorDiscovery(null)));

            context.UserTable = new DistributedActorTableRef <string>(system.ActorOf(
                                                                          Props.Create(() => new DistributedActorTable <string>(
                                                                                           "User", context.ClusterActorDiscovery, null, null)),
                                                                          "UserTable"));

            context.UserTableContainer = new DistributedActorTableContainerRef <string>(system.ActorOf(
                                                                                            Props.Create(() => new DistributedActorTableContainer <string>(
                                                                                                             "User", context.ClusterActorDiscovery, typeof(UserActorFactory), new object[] { context }, InterfacedPoisonPill.Instance)),
                                                                                            "UserTableContainer"));

            context.RoomTable = new DistributedActorTableRef <string>(system.ActorOf(
                                                                          Props.Create(() => new DistributedActorTable <string>(
                                                                                           "Room", context.ClusterActorDiscovery, null, null)),
                                                                          "RoomTable"));

            var roomTableContainer = system.ActorOf(
                Props.Create(() => new DistributedActorTableContainer <string>(
                                 "Room", context.ClusterActorDiscovery, typeof(RoomActorFactory), new object[] { context }, InterfacedPoisonPill.Instance)),
                "RoomTableContainer");

            context.BotTable = new DistributedActorTableRef <long>(system.ActorOf(
                                                                       Props.Create(() => new DistributedActorTable <long>(
                                                                                        "Bot", context.ClusterActorDiscovery, typeof(IncrementalIntegerIdGenerator), null)),
                                                                       "BotTable"));

            var botTableContainer = system.ActorOf(
                Props.Create(() => new DistributedActorTableContainer <long>(
                                 "Bot", context.ClusterActorDiscovery, typeof(BotActorFactory), new object[] { context }, InterfacedPoisonPill.Instance)),
                "BotTableContainer");

            Context = context;
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            if (typeof(IUser) == null)
            {
                throw new Exception("Force interface module to be loaded");
            }

            var system = ActorSystem.Create("MySystem");

            DeadRequestProcessingActor.Install(system);

            var gateway = StartListen(system, ChannelType.Tcp, new IPEndPoint(IPAddress.Any, 5000)).Result;

            Console.WriteLine("Please enter key to quit.");
            Console.ReadLine();

            gateway.Stop().Wait();
            system.Terminate().Wait();
        }
        private static void Main(string[] args)
        {
            if (typeof(IGreeter) == null)
            {
                throw new Exception("Force interface module to be loaded");
            }

            using (var system = ActorSystem.Create("MySystem", "akka.loglevel = DEBUG \n akka.actor.debug.lifecycle = on"))
            {
                DeadRequestProcessingActor.Install(system);

                var tcpGateway = StartGateway(system, ChannelType.Tcp, 5001);
                var udpGateway = StartGateway(system, ChannelType.Udp, 5001);

                Console.WriteLine("Please enter key to quit.");
                Console.ReadLine();

                tcpGateway.Stop().Wait();
                udpGateway.Stop().Wait();
            }
        }
        private static void Main(string[] args)
        {
            if (typeof(ICalculator) == null)
            {
                throw new Exception("Force interface module to be loaded");
            }

            using (var system = ActorSystem.Create("MySystem", "akka.loglevel = DEBUG \n akka.actor.debug.lifecycle = on"))
            {
                DeadRequestProcessingActor.Install(system);

                var gateways = new List <GatewayRef>();
                gateways.AddRange(StartGateway(system, ChannelType.Tcp, 5001, 5002));
                gateways.AddRange(StartGateway(system, ChannelType.Udp, 5001, 5002));

                Console.WriteLine("Please enter key to quit.");
                Console.ReadLine();

                Task.WaitAll(gateways.Select(g => g.Stop()).ToArray());
            }
        }
Esempio n. 11
0
        private static ClientRef[] CreateRemoteClients(int count)
        {
            var config = ConfigurationFactory.ParseString(@"
                akka {
                    actor {
                        provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
                        serializers {
                          proto = ""Akka.Interfaced.ProtobufSerializer.ProtobufSerializer, Akka.Interfaced.ProtobufSerializer""
                        }
                        serialization-bindings {
                          ""Akka.Interfaced.NotificationMessage, Akka.Interfaced"" = proto
                          ""Akka.Interfaced.RequestMessage, Akka.Interfaced"" = proto
                          ""Akka.Interfaced.ResponseMessage, Akka.Interfaced"" = proto
                        }
                    }
                    remote {
                        helios.tcp {
                            transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
                            transport-protocol = tcp
                            hostname = 127.0.0.1
                        }
                    }
                }");

            var system = ActorSystem.Create("ClientSystem", config);

            DeadRequestProcessingActor.Install(system);

            var clients = new ClientRef[count];

            for (int i = 0; i < count; i++)
            {
                var serverPath = $"akka.tcp://[email protected]:8081/user/Server_{i}";
                var server     = system.ActorSelection(serverPath).ResolveOne(TimeSpan.Zero).Result;
                var client     = system.ActorOf(Props.Create <ClientActor>(server), "Client_" + i);
                clients[i] = new ClientRef(client);
            }
            return(clients);
        }
Esempio n. 12
0
        private static IActorRef[] CreateRemoteServers(int count)
        {
            var config = ConfigurationFactory.ParseString(@"
                akka {
                    actor {
                        provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
                        serializers {
                          proto = ""Akka.Interfaced.ProtobufSerializer.ProtobufSerializer, Akka.Interfaced.ProtobufSerializer""
                        }
                        serialization-bindings {
                          ""Akka.Interfaced.NotificationMessage, Akka.Interfaced"" = proto
                          ""Akka.Interfaced.RequestMessage, Akka.Interfaced"" = proto
                          ""Akka.Interfaced.ResponseMessage, Akka.Interfaced"" = proto
                        }
                    }
                    remote {
                        helios.tcp {
                            transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
                            transport-protocol = tcp
                            port = 8081
                            hostname = 127.0.0.1
                        }
                    }
                }");

            var system = ActorSystem.Create("ServerSystem", config);

            DeadRequestProcessingActor.Install(system);

            var servers = new IActorRef[count];

            for (int i = 0; i < count; i++)
            {
                var server = system.ActorOf(Props.Create <ServerActor>(), "Server_" + i);
                servers[i] = server;
            }
            return(servers);
        }
Esempio n. 13
0
        private static void DoLocalTest(int actorCount, int pingCount)
        {
            using (var system = ActorSystem.Create("System"))
            {
                DeadRequestProcessingActor.Install(system);

                // make clients and servers

                var t1 = new Stopwatch();
                t1.Start();

                var clients = new List <ClientRef>();
                for (int i = 0; i < actorCount; i++)
                {
                    var server = system.ActorOf(Props.Create <ServerActor>(), "Server_" + i);
                    var client = system.ActorOf(Props.Create <ClientActor>(server), "Client_" + i);
                    clients.Add(new ClientRef(client));
                }

                var warmUpTasks = clients.Select(x => x.Start(1)).ToArray();
                Task.WaitAll(warmUpTasks);

                t1.Stop();
                Console.WriteLine($"Ready: {t1.Elapsed}");

                // test

                var t2 = new Stopwatch();
                t2.Start();

                var pingTasks = clients.Select(x => x.Start(pingCount)).ToArray();
                Task.WaitAll(pingTasks);

                t2.Stop();
                Console.WriteLine($"Test: {t2.Elapsed}");
            }
        }
Esempio n. 14
0
        async void Start()
        {
            _log.Info("-------LOG STARTED----");

            MainUI.Instance.ShowLoginWindow("", "");

            //load behaviours

            if (Directory.Exists(Path.Combine(Application.dataPath, behavioursPath)))
            {
                BehaviourManager.LoadBehaviours(Path.Combine(Application.dataPath, behavioursPath));
            }
            else
            {
                _log.Info($"Path {Path.Combine(Application.dataPath, behavioursPath)} not exists, skipping assembly loading");
            }



            string sconfig = @"
         akka{
                  actor{
                 
              serializers
                           {
                            hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion""
                           }
                         serialization-bindings {
                           ""System.Object"" = hyperion
                           }

    provider=""Akka.Remote.RemoteActorRefProvider,Akka.Remote""
                                                 
                        }
                
                 remote{
                    helios.tcp{
                            transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
                        port =18098

                        hostname=localhost
                        }
                    }
                }
      ";

            var config = ConfigurationFactory.ParseString(sconfig);

            _clientId = Guid.NewGuid();

            try
            {
                AkkaSystem = ActorSystem.Create("JediumClient" + _clientId, config);
            }
            catch (Exception e)
            {
                Debug.Log(e);
                // throw;
            }

            DeadRequestProcessingActor.Install(AkkaSystem);
        }
Esempio n. 15
0
        public bool Start()
        {
            _logger = LogManager.GetLogger("[MainHost]");

            _logger.Info("------------------------------JEDIUM SERVER---------------------------");
            _logger.Info("Starting at: " + DateTime.Now);

            //settings
            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadFile("config\\ServerConfig.ini");

            MainSettings.BehavioursPluginPath = data["Server"]["BehavioursPluginPath"];
            MainSettings.WebApiHost           = data["Server"]["WebApiHost"];
            MainSettings.DBUrl                   = data["Server"]["DBUrl"];
            MainSettings.DatabaseName            = data["Server"]["DatabaseName"];
            MainSettings.CollectMessageStats     = bool.Parse(data["Statistics"]["CollectMessageStats"]);
            MainSettings.StatsCollectionInterval = int.Parse(data["Statistics"]["StatsCollectionInterval"]);
            MainSettings.mainURL                 = data["Server"]["MainURL"];
            MainSettings.TickDelay               = int.Parse(data["Server"]["TickDelay"]);

            _logger.Warn("___TICK DELAY:" + MainSettings.TickDelay);
            MD5 mcalc = MD5.Create();

            byte[] dbytes = File.ReadAllBytes("Domain.dll");
            MainSettings.ServerHash = mcalc.ComputeHash(dbytes).ToHex(false);
            _logger.Info($"Server domain hash: {MainSettings.ServerHash}");


            //preload domain
            var type = typeof(ISceneActor);

            if (type == null)
            {
                throw new InvalidProgramException("!");
            }

            //load plugins
            // BehaviourManager.LoadBehaviours(MainSettings.BehavioursPluginPath);


            //get config (app.config)
            AkkaConfigurationSection section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");

            //_logger.Info();
            Config aconfig = section.AkkaConfig;

            Config localConfig = ConfigurationFactory.ParseString("akka.remote.helios.tcp.hostname = " + MainSettings.mainURL)
                                 .WithFallback(aconfig);

            //попытаться запустить актер сервера
            try
            {
                _system = ActorSystem.Create("VirtualFramework", localConfig);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                throw;
            }

            // на случай разрыва соединения
            DeadRequestProcessingActor.Install(_system);


            _databaseAgent = _system.ActorOf(Props.Create(() => new MongoDbActor()), "DataBase")
                             .Cast <DatabaseAgentRef>(); //TODO: Add test for connection

            _terminal = _system.ActorOf(Props.Create(() => new TerminalConnection(_databaseAgent)), "Terminal")
                        .Cast <TerminalConnectionRef>();


            _serverConnection = _system
                                .ActorOf(Props.Create(() => new ServerConnection(_databaseAgent)), "ServerEndpoint")
                                .Cast <ConnectionRef>();

            //_databaseAgent.SetDummyObjectTest().Wait();


            _manager = _system
                       .ActorOf(Props.Create(() => new ObjectsManager(_databaseAgent, _serverConnection)), "ObjectManager")
                       .Cast <ObjectsManagerRef>();


            //Editor

            _editorConnection = _system.ActorOf(Props.Create(() => new EditorConnection(_manager, _databaseAgent)), "EditorConnection")
                                .Cast <EditorConnectionRef>();

            //assets host
            _webApiHost = _system
                          .ActorOf(Props.Create(() => new WebApiHost(MainSettings.WebApiHost, _databaseAgent, _manager)),
                                   "AssetsHost")
                          .Cast <WebApiHostRef>();


            _pluginsHost = _system.ActorOf(Props.Create(() => new PluginsHost(_databaseAgent, _manager)), "PluginsHost")
                           .Cast <PluginsHostRef>();

            // _pluginsHost.LoadPlugins().Wait();


            _manager.LoadAllScenes().Wait();


            return(true);
        }