Example #1
0
        public static NodeEntryPoint StartWithOptions(NodeOptions options, Action <int> termination)
        {
            var slim = new ManualResetEventSlim(false);
            var list = String.Join(Environment.NewLine,
                                   options.GetPairs().Select(p => String.Format("{0} : {1}", p.Key, p.Value)));

            Log.Info(list);

            var bus        = new InMemoryBus("OutputBus");
            var controller = new NodeController(bus);
            var mainQueue  = new QueuedHandler(controller, "Main Queue");

            controller.SetMainQueue(mainQueue);
            Application.Start(i =>
            {
                slim.Set();
                termination(i);
            });

            var http = new PlatformServerApiService(mainQueue, String.Format("http://{0}:{1}/", options.LocalHttpIp, options.HttpPort));

            bus.Subscribe <SystemMessage.Init>(http);
            bus.Subscribe <SystemMessage.StartShutdown>(http);


            var timer = new TimerService(new ThreadBasedScheduler(new RealTimeProvider()));

            bus.Subscribe <TimerMessage.Schedule>(timer);

            // switch, based on configuration
            AzureStoreConfiguration azureConfig;

            if (AzureStoreConfiguration.TryParse(options.StoreLocation, out azureConfig))
            {
                var storageService = new AzureStorageService(azureConfig, mainQueue);
                bus.Subscribe <ClientMessage.AppendEvents>(storageService);
                bus.Subscribe <SystemMessage.Init>(storageService);
                bus.Subscribe <ClientMessage.ImportEvents>(storageService);
                bus.Subscribe <ClientMessage.RequestStoreReset>(storageService);
            }
            else
            {
                var storageService = new FileStorageService(options.StoreLocation, mainQueue);
                bus.Subscribe <ClientMessage.AppendEvents>(storageService);
                bus.Subscribe <SystemMessage.Init>(storageService);
                bus.Subscribe <ClientMessage.ImportEvents>(storageService);
                bus.Subscribe <ClientMessage.RequestStoreReset>(storageService);
            }


            mainQueue.Start();

            mainQueue.Enqueue(new SystemMessage.Init());
            return(new NodeEntryPoint(mainQueue, slim));
        }
Example #2
0
        static void Main(string[] args)
        {
            var bus        = new InMemoryBus("OutputBus");
            var controller = new NodeController(bus);
            var mainQueue  = new QueuedHandler(controller, "Main Queue");

            controller.SetMainQueue(mainQueue);
            Application.Start(Environment.Exit);

            int?timeOut = args.Length > 0 ? int.Parse(args[0]) : (int?)null;
            int port    = args.Length > 1 ? int.Parse(args[1]) : 8080;

            var http = new PlatformServerApiService(mainQueue, string.Format("http://*:{0}/", port));

            bus.AddHandler <SystemMessage.Init>(http);
            bus.AddHandler <SystemMessage.Shutdown>(http);


            // switch, based on configuration

            var storageService = new StorageService(CreateFileStore, mainQueue);

            bus.AddHandler <ClientMessage.AppendEvents>(storageService);
            bus.AddHandler <SystemMessage.Init>(storageService);

            Console.WriteLine("Starting everything. Press enter to initiate shutdown");


            mainQueue.Start();

            mainQueue.Enqueue(new SystemMessage.Init());

            if (timeOut == null)
            {
                Console.ReadLine();
                mainQueue.Enqueue(new SystemMessage.Shutdown());
                Console.ReadLine();
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(timeOut.Value * 1000);
                    Application.Exit(ExitCode.Success, "");
                });
                _exitEvent.Wait();
            }
        }
Example #3
0
 public NodeEntryPoint(QueuedHandler handler, ManualResetEventSlim exitWait)
 {
     _handler  = handler;
     _exitWait = exitWait;
 }
Example #4
0
 public void SetMainQueue(QueuedHandler mainQueue)
 {
     _mainQueue = mainQueue;
 }