Ejemplo n.º 1
0
        public static void UseExcess(this IAppBuilder app,
                                     Action <AppSettings> initializeSettings = null,
                                     Action <IDistributedApp> initializeApp  = null)
        {
            var settings = new AppSettings();

            if (initializeSettings != null)
            {
                initializeSettings(settings);
            }

            var server = new DistributedApp(new ThreadedConcurrentApp(
                                                types: null,
                                                threadCount: settings.Threads,
                                                blockUntilNextEvent: settings.BlockUntilNextEvent));

            if (initializeApp != null)
            {
                initializeApp(server);
            }

            app.Use <ExcessOwinMiddleware>(server);
            server.Start();
        }
Ejemplo n.º 2
0
        public static void Start(
            string localServer,
            string remoteServer,
            int threads = 2,
            IEnumerable <Type> classes = null,
            IDictionary <Guid, IConcurrentObject> managedInstances = null)
        {
            var concurrentApp = new ThreadedConcurrentApp(new Dictionary <string, Func <IConcurrentApp, object[], IConcurrentObject> >());
            var app           = new DistributedApp(concurrentApp, localServer);

            if (classes != null)
            {
                foreach (var @class in classes)
                {
                    Guid id;
                    IConcurrentObject @object;

                    app.RegisterClass(@class);
                    if (isConcurrentSingleton(@class, out id, out @object))
                    {
                        if (managedInstances != null)
                        {
                            managedInstances[id] = @object;
                        }

                        app.RegisterInstance(id, @object);
                    }
                }
            }

            app.Connect = _ =>
            {
                var waiter  = new ManualResetEvent(false);
                var errors  = new List <Exception>();
                int waitFor = 2;

                NetMQFunctions.StartServer(app, localServer,
                                           connected: ex =>
                {
                    if (ex != null)
                    {
                        errors.Add(ex);
                    }
                    if (--waitFor == 0)
                    {
                        waiter.Set();
                    }
                });

                NetMQFunctions.StartClient(app, localServer, remoteServer, ex =>
                {
                    if (ex != null)
                    {
                        errors.Add(ex);
                    }
                    if (--waitFor == 0)
                    {
                        waiter.Set();
                    }
                });

                waiter.WaitOne();
                return(errors.Any()
                    ? new AggregateException(errors)
                    : null);
            };

            app.Start();
        }