Exemple #1
0
        static int Main(string[] args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Debug.AutoFlush = true;

            KayakOptions options = null;

            try
            {
                options = new KayakOptionParser().Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("kayak: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Type `kayak --help` for more information.");
            }

            if (options.ShowHelp)
            {
                options.PrintHelp();
                return(0);
            }

            if (options == null)
            {
                return(1);
            }

            try
            {
                // all configuration strings search
                // AppDomain.CurrentDomain.SetupInformation.ApplicationBase for DLLs.
                // to change that path, we'd need to create a new app domain with a different
                // application base.

                //var domain = AppDomain.CreateDomain("KayakScheduler domain", null, new AppDomainSetup()
                //{
                //    ApplicationBase = Directory.GetCurrentDirectory(),
                //    ApplicationTrust = new ApplicationTrust(new PermissionSet(PermissionState.Unrestricted), Enumerable.Empty<StrongName>())
                //});

                //var launcher = (Launcher)domain.CreateInstanceFromAndUnwrap(
                //    Assembly.GetExecutingAssembly().CodeBase,
                //    typeof(Launcher).FullName);

                new Launcher().LaunchScheduler(options);

                //AppDomain.Unload(domain);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("kayak: failed to launch scheduler");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteStackTrace(e);
                return(-1);
            }

            return(0);
        }
Exemple #2
0
        public void LaunchScheduler(KayakOptions options)
        {
            // okay the default delegate kinds sucks because if the user's program doesn't
            // explicitly call stop the thread essentially hangs, becaues the event loop
            // frame never returns, it's just waiting on another task.
            //
            // something of a halting problem.
            // would be better if scheduler just stopped when no more callbacks were queued.
            //
            // for now, you should use gate if you don't provide a delegate. scheduler and process args
            // are passed in via env. call stop eventually, or be okay with your program never terminating

            var kayakDelegate =
                new KayakDelegateLoader().Load(options.KayakConfiguration)
                ?? new DefaultKayakDelegate();

            var scheduler = KayakScheduler.Factory.Create(kayakDelegate);

            scheduler.Post(() => kayakDelegate.OnStart(scheduler, options.RemainingArguments));

            var gateOptions = options.GateOptions;

            if (gateOptions != null)
            {
                var gateConfiguration = gateOptions.GateConfiguration;
                var listenEndPoint    = gateOptions.ListenEndPoint ?? new IPEndPoint(IPAddress.Any, 8000);

                var context = new Dictionary <string, object>()
                {
                    { "kayak.ListenEndPoint", listenEndPoint },
                    { "kayak.Arguments", options.RemainingArguments }
                };

                var config = DefaultConfigurationLoader.LoadConfiguration(gateConfiguration);

                if (config == null)
                {
                    throw new Exception("Could not load Gate configuration from configuration string '" + gateConfiguration + "'");
                }

                var app = AppBuilder.BuildConfiguration(config);

                var server = KayakServer.Factory.CreateGate(app, scheduler, context);

                scheduler.Post(() =>
                {
                    Console.WriteLine("kayak: binding gate app to '" + listenEndPoint + "'");
                    server.Listen(listenEndPoint);
                });
            }

            // blocks until Stop is called
            scheduler.Start();
        }
Exemple #3
0
        public void LaunchScheduler(KayakOptions options)
        {
            // okay the default delegate kinds sucks because if the user's program doesn't
            // explicitly call stop the thread essentially hangs, becaues the event loop
            // frame never returns, it's just waiting on another task.
            //
            // something of a halting problem.
            // would be better if scheduler just stopped when no more callbacks were queued.
            //
            // for now, you should use gate if you don't provide a delegate. scheduler and process args
            // are passed in via env. call stop eventually, or be okay with your program never terminating

            var kayakDelegate =
                new KayakDelegateLoader().Load(options.KayakConfiguration)
                ?? new DefaultKayakDelegate();

            var scheduler = KayakScheduler.Factory.Create(kayakDelegate);

            scheduler.Post(() => kayakDelegate.OnStart(scheduler, options.RemainingArguments));

            var gateOptions = options.GateOptions;

            if (gateOptions != null)
            {
                var gateConfiguration = gateOptions.GateConfiguration;
                var listenEndPoint = gateOptions.ListenEndPoint ?? new IPEndPoint(IPAddress.Any, 8000);

                var context = new Dictionary<string, object>()
                        {
                            { "kayak.ListenEndPoint", listenEndPoint },
                            { "kayak.Arguments", options.RemainingArguments }
                        };

                var config = DefaultConfigurationLoader.LoadConfiguration(gateConfiguration);

                if (config == null)
                    throw new Exception("Could not load Gate configuration from configuration string '" + gateConfiguration + "'");

                var app = AppBuilder.BuildConfiguration(config);

                var server = KayakServer.Factory.CreateGate(app, scheduler, context);

                scheduler.Post(() =>
                {
                    Console.WriteLine("kayak: binding gate app to '" + listenEndPoint + "'");
                    server.Listen(listenEndPoint);
                });
            }

            // blocks until Stop is called
            scheduler.Start();
        }
Exemple #4
0
        public KayakOptions Parse(string[] args)
        {
            bool          useGate           = false;
            string        gateConfiguration = null;
            string        listenEndPoint    = null;
            List <string> remaining         = null;

            KayakOptions options = new KayakOptions();

            options.optionSet = new OptionSet()
            {
                { "g|gate:", "A Gate configuration string",
                  v => { useGate = true; gateConfiguration = v; } },
                { "b|bind=", "The endpoint the server should bind to (use in combination with -g/--gate",
                  v => listenEndPoint = v },
                { "h|?|help", "Print help and exit", v => options.ShowHelp = true },
            };

            remaining = options.optionSet.Parse(args);

            if (remaining.Count > 0)
            {
                options.KayakConfiguration = remaining[0];
                remaining.RemoveAt(0);
            }

            options.RemainingArguments = remaining.ToArray();

            if (useGate)
            {
                options.GateOptions = new GateOptions();
                options.GateOptions.GateConfiguration = gateConfiguration;
                options.GateOptions.ListenEndPoint    = parseEP(listenEndPoint);
            }

            return(options);
        }
Exemple #5
0
        public KayakOptions Parse(string[] args)
        {
            bool useGate = false;
            string gateConfiguration = null;
            string listenEndPoint = null;
            List<string> remaining = null;

            KayakOptions options = new KayakOptions();

            options.optionSet = new OptionSet()
            {
                { "g|gate:", "A Gate configuration string",
                    v => { useGate = true; gateConfiguration = v; } },
                { "b|bind=", "The endpoint the server should bind to (use in combination with -g/--gate",
                    v => listenEndPoint = v },
                { "h|?|help", "Print help and exit", v => options.ShowHelp = true },
            };

            remaining = options.optionSet.Parse(args);

            if (remaining.Count > 0)
            {
                options.KayakConfiguration = remaining[0];
                remaining.RemoveAt(0);
            }

            options.RemainingArguments = remaining.ToArray();

            if (useGate)
            {
                options.GateOptions = new GateOptions();
                options.GateOptions.GateConfiguration = gateConfiguration;
                options.GateOptions.ListenEndPoint = parseEP(listenEndPoint);
            }

            return options;
        }