示例#1
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(100);

            var brokerAgent = new BrokerAgent(); env.Add(brokerAgent, "broker");

            ProviderAgent pa1 = new ProviderAgent(ServiceType.Add); env.Add(pa1, "provider1");
            ProviderAgent pa2 = new ProviderAgent(ServiceType.Add); env.Add(pa2, "provider2");
            ProviderAgent pa3 = new ProviderAgent(ServiceType.Sub); env.Add(pa3, "provider3");
            ProviderAgent pa4 = new ProviderAgent(ServiceType.Sub); env.Add(pa4, "provider4");

            ClientAgent ca1 = new ClientAgent(ServiceType.Add); env.Add(ca1, "client1");
            ClientAgent ca2 = new ClientAgent(ServiceType.Add); env.Add(ca2, "client2");
            ClientAgent ca3 = new ClientAgent(ServiceType.Sub); env.Add(ca3, "client3");
            ClientAgent ca4 = new ClientAgent(ServiceType.Sub); env.Add(ca4, "client4");

            env.Start();

            pa1.Send("provider1", "force-unregister");

            ProviderAgent pa5 = new ProviderAgent(ServiceType.Sub); env.Add(pa5, "provider5");

            env.Continue(100);

            ClientAgent ca5 = new ClientAgent(ServiceType.Add); env.Add(ca5, "client5");
            ClientAgent ca6 = new ClientAgent(ServiceType.Sub); env.Add(ca6, "client6");

            env.Continue(100);
        }
示例#2
0
        private static void Main(string[] args)
        {
            var env = new ConcurrentEnvironment();

            var brokerAgent = new BrokerAgent(); env.Add(brokerAgent, "broker"); brokerAgent.Start();

            Thread.Sleep(100);

            ProviderAgent pa1 = new ProviderAgent(ServiceType.Add); env.Add(pa1, "provider1"); pa1.Start();
            ProviderAgent pa2 = new ProviderAgent(ServiceType.Add); env.Add(pa2, "provider2"); pa2.Start();
            ProviderAgent pa3 = new ProviderAgent(ServiceType.Sub); env.Add(pa3, "provider3"); pa3.Start();
            ProviderAgent pa4 = new ProviderAgent(ServiceType.Sub); env.Add(pa4, "provider4"); pa4.Start();

            Thread.Sleep(100);

            ClientAgent ca1 = new ClientAgent(ServiceType.Add); env.Add(ca1, "client1"); ca1.Start();
            ClientAgent ca2 = new ClientAgent(ServiceType.Add); env.Add(ca2, "client2"); ca2.Start();
            ClientAgent ca3 = new ClientAgent(ServiceType.Sub); env.Add(ca3, "client3"); ca3.Start();
            ClientAgent ca4 = new ClientAgent(ServiceType.Sub); env.Add(ca4, "client4"); ca4.Start();

            Thread.Sleep(1000);

            pa1.Send("provider1", "force-unregister");

            ProviderAgent pa5 = new ProviderAgent(ServiceType.Sub); env.Add(pa5, "provider5"); pa5.Start();

            Thread.Sleep(1000);

            ClientAgent ca5 = new ClientAgent(ServiceType.Add); env.Add(ca5, "client5"); ca5.Start();
            ClientAgent ca6 = new ClientAgent(ServiceType.Sub); env.Add(ca6, "client6"); ca6.Start();

            env.WaitAll();
        }