Ejemplo n.º 1
0
       public void CallMethod_Using_NProxyWrapper_ReadMessageWithRawActor()
       {
            waitHandle.Reset();
            using (var context = NetMQContext.Create())
            {
                using (var exchange = new Exchange(context))
                {
                    exchange.Start();
                    
                    var queueDevice = new QueueDevice(
                    context,
                    Pipe.PubSubControlBackAddressServer,
                    Pipe.PubSubControlFrontAddressServer,
                    DeviceMode.Threaded);
                    queueDevice.Start();

                    Thread.Sleep(200);

                    var task = Task.Run(() =>
                    {
                        return RunSubscriber(context);
                    });

                    using (var actor = new Actor(context, new BinarySerializer()))
                    {
                        using (var syncService = context.CreateResponseSocket())
                        {
                            syncService.Connect(Pipe.PubSubControlFrontAddressClient);
                            for (int i = 0; i < 1; i++)
                            {
                                syncService.Receive();
                                syncService.Send(string.Empty);
                            }

                            var order = actor.CreateInstance<IOrder>(typeof(Order));
                            Assert.IsInstanceOfType(order, typeof(IOrder));
                            order.UpdateDescription("XXX"); //called without exception    
                            waitHandle.WaitOne();

                            var netMqMessage = new NetMQMessage();
                            netMqMessage.Append(new NetMQFrame(string.Empty));
                            netMqMessage.Append(new NetMQFrame("shutdownallactors"));
                            actor.OutputChannel.SendMessage(netMqMessage);

                            //actor.SendKillSignal(actor.Serializer, actor.OutputChannel, string.Empty);
                        }
                    }

                    Thread.Sleep(200);

                    queueDevice.Stop(true);
                    exchange.Stop(true);
                }
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(ConsoleCancelHandler);
            using (var context = NetMQContext.Create())
            {
                var exchange = new Exchange(context);
                exchange.Start();
                using (var silo = new Silo(context, new BinarySerializer()))
                {
                    silo.RegisterEntity(typeof(TestHelpers.Counter));
                    silo.RegisterEntity(typeof(DiagnosticMessage));
                    silo.Start();

                    var diagnosticMessage = silo.ActorFactory.CreateInstance<IDiagnosticMessage>(typeof(DiagnosticMessage));

                    diagnosticMessage.WriteToConsole("Yeah this works");

                    Console.WriteLine("Press enter to start");
                    Console.ReadLine();

                    var counter = silo.ActorFactory.CreateInstance<ICounter>(typeof(Counter), Guid.NewGuid());

                    var exit = string.Empty;

                    for (int i = 0; i < 100; i++)
                    {
                        diagnosticMessage.WriteToConsole("Yeah this works");
                        Console.WriteLine(i);
                       counter.Add();
                        Thread.Sleep(10);
                    }

                    Console.WriteLine("Done: press enter to exit");
                    Console.ReadLine();
                    silo.Stop();
                }

                exchange.Stop(true);

                Console.WriteLine("Press Enter to Exit....again");
                Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
        public void CreatingAnActor()
        {

            Type generic = typeof(Actor<>);
            //Clown clown = null;
            //actor.Clowns.TryGetValue(addressAndNumber[0], out clown);

            //var type = Type.GetType(addressAndNumber[0]);
            Type[] typeArgs = { typeof(Order) };


            var obj = Activator.CreateInstance(typeof(Order));
            var constructed = generic.MakeGenericType(typeArgs);

            // Create a Type object representing the constructed generic 
            // type.
            using (var context = NetMQContext.Create())
            {
                using (var xchange = new Exchange(context))
                {
                    xchange.Start();
                    var serializer = new DefaultSerializer(Pipe.ControlChannelEncoding);

                    var target = (Actor)Activator.CreateInstance(constructed, context, new BinarySerializer());
                    
                    obj = target.ReadfromPersistence(@"TestHelpers.Order", typeof(Order));

                    target.Start();

                    xchange.Stop(true);
                }
            }
        }
Ejemplo n.º 4
0
        public void PersistSelfTest()
        {
            using (var context = NetMQContext.Create())
            {
                using (var exchange = new Exchange(context))
                {
                    exchange.Start();

                    using (var actor = new Actor<Customer>(context))
                    {
                        var customer = new Customer(1);
                        customer.Firstname = "John";
                        customer.Lastname = "off yer Rocker mate";

                        actor.PersistSelf(typeof(Customer), customer, new DefaultSerializer(Pipe.ControlChannelEncoding));
                    }
                    
                    exchange.Stop(true);
                }
            }
        }
Ejemplo n.º 5
0
        public void CallKillMe()
        {
            using (var context = NetMQContext.Create())
            {
                using (var exchange = new Exchange(context))
                {
                    exchange.Start();
                    using (var customer = new Actor<Customer>(context, new BinarySerializer()))
                    {
                        Thread.Sleep(300);
                        Task.Run(() => customer.Start());
                    }

                    exchange.Stop(true);
                }
            }
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(ConsoleCancelHandler);

            using (var context = NetMQContext.Create())
            {
                var exchange = new Exchange(context);
                exchange.Start();
                using (var silo = new Silo(context, new BinarySerializer()))
                {
                    silo.RegisterEntity(typeof(Customer));
                    silo.RegisterEntity(typeof(Order));
                    silo.RegisterEntity(typeof(DiagnosticMessage));
                    silo.Start();

                    var diagnosticMessage = silo.ActorFactory.CreateInstance<IDiagnosticMessage>(typeof(DiagnosticMessage));

                    diagnosticMessage.WriteToConsole("Yeah this works");
                    //Console.WriteLine("Run tests");
                    //Console.ReadLine();

                    var customer = silo.ActorFactory.CreateInstance<ICustomer>(typeof(Customer), 99);

                    //customer.CreateOrder();

                    var uniqueGuid = Guid.NewGuid();
                    var order = silo.ActorFactory.CreateInstance<IOrder>(typeof(Order), uniqueGuid);

                    var productId = Guid.NewGuid()
                        .ToString()
                        .Replace("-", "")
                        .Replace("{", "")
                        .Replace("}", "")
                        .Substring(0, 10);

                    order.CreateOrder("Another order", 23, productId, 12);

                    var exit = string.Empty;
                    var description = "XXXX";

                    for (int i = 0; i < 100; i++)
                    {
                        Console.WriteLine(
                               "({0}) Last order created was {1}, its description was {2}", i,
                               uniqueGuid,
                               description);

                       // uniqueGuid = Guid.NewGuid();
                        customer.CreateOrder();

                        if (exit != null && exit.ToLower() != "runtoend")
                        {
                            Console.WriteLine("Press Enter to send another message, or type exit to stop");
                            exit = Console.ReadLine();
                            if (exit != null && exit.ToLower() == "exit")
                            {
                                break;
                            }
                        }

                        description = "New Description " + 23 + (i * 2);
                        order.UpdateDescription(description);

                    //    customer.UpdateName(string.Format("new name, {0}", i.ToString(CultureInfo.InvariantCulture)));
                    //    var customer2 = silo.ActorFactory.CreateInstance<ICustomer>(typeof(Customer), i);
                    //    ////Thread.Sleep(500);
                    //    customer2.UpdateName("XXX - AAA" + i);
                    //    Console.WriteLine("Customer {0} was updated", i);
                    }

                    ////var netMqMessage = new NetMQMessage();
                    ////netMqMessage.Append(new NetMQFrame(actor.Serializer.GetBuffer("Aslongasitissomething")));
                    ////netMqMessage.Append(new NetMQFrame(actor.Serializer.GetBuffer("shutdownallactors")));
                    ////actor.OutputChannel.SendMessage(netMqMessage);

                    Console.WriteLine("Out of loop; Press Enter to stop silo");
                    Console.ReadLine();
                    silo.Stop();
                }

                exchange.Stop(true);

                Console.WriteLine("Press Enter to Exit");
                Console.ReadLine();
             }
        }