Esempio n. 1
0
 public override bool Initialize()
 {
     Ice.Communicator com = null;
     try
     {
         Ice.Properties prop = Ice.Util.createProperties();
         prop.setProperty("Ice.Default.Locator", "IGServerControllerIceGrid/Locator:default -t 5000 -h " + m_endPoint.Address.ToString() + " -p " + m_endPoint.Port.ToString());
         Ice.InitializationData initData = new Ice.InitializationData();
         initData.properties = prop;
         com = Ice.Util.initialize(initData);
         m_serverControllerClient = IGServerControllerIcePrxHelper.checkedCast(com.stringToProxy("serverController"));
     }
     catch (Ice.Exception)
     {
         IGServerManager.Instance.AppendError(string.Format("couldn't find a `::IGServerController::IGServerControllerIce' object for {0}", m_endPoint.Address.ToString()));
         return false;
     }
     finally
     {
         if (m_serverControllerClient == null)
         {
             IGServerManager.Instance.AppendError(string.Format("An exception was thrown while attempting to connect to: {0}", m_endPoint.Address.ToString()));
         }
     }
     return true;
 }
Esempio n. 2
0
            public override int run(string[] args)
            {
                if (args.Length > 0)
                {
                    Console.Error.WriteLine(appName() + ": too many arguments");
                    return 1;
                }

                try
                {
                    serverController = IGServerControllerIcePrxHelper.checkedCast(communicator().stringToProxy("serverController"));
                }
                catch (Ice.NotRegisteredException)
                {
                    IceGrid.QueryPrx query =
                        IceGrid.QueryPrxHelper.checkedCast(communicator().stringToProxy("IGServerControllerIceGrid/Query"));
                    serverController = IGServerControllerIcePrxHelper.checkedCast(query.findObjectByType("::IGServerController::IGServerControllerIce"));
                }
                if (serverController == null)
                {
                    Console.WriteLine("couldn't find a `::IGServerController::IGServerControllerIce' object");
                    return 1;
                }

                menu();

                string line = null;
                do
                {
                    try
                    {
                        Console.Write("==> ");
                        Console.Out.Flush();
                        line = Console.In.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        if (line.Equals("p"))
                        {
                            Console.WriteLine(string.Format("{0} Ping", DateTime.Now.TimeOfDay));
                            Console.WriteLine(string.Format("{0} Answer: {1}", DateTime.Now.TimeOfDay, serverController.ping()));
                        }
                        else if (line.Equals("s"))
                        {
                            Console.WriteLine(string.Format("{0} Status:\n{1}", DateTime.Now.TimeOfDay, serverController.getStatus()));
                        }
                        else if (line.Equals("shut"))
                        {
                            serverController.shutdown();
                        }
                        else if (line.Equals("x"))
                        {
                            // Nothing to do
                        }
                        else if (line.Equals("?"))
                        {
                            menu();
                        }
                        else if (line.StartsWith("r=\"") && line.EndsWith("\""))
                        {
                            var tmp_req_wait = nb_req_wait;
                            nb_req_wait = 0;
                            sendRequest(line.Substring(3, line.Length - 4));
                            nb_req_wait = tmp_req_wait;
                        }
                        else if (line.StartsWith("ar=\"") && line.EndsWith("\""))
                        {
                            requests.Add(line.Substring(4, line.Length - 5));
                            Console.WriteLine(string.Format("{0} Request added to buffer", DateTime.Now.TimeOfDay));
                        }
                        else if (line.Equals("as"))
                        {
                            nb_req_wait += requests.Count;
                            while (requests.Count > 0){
                                var req = requests[0];
                                requests.RemoveAt(0);
                                Thread newThread = new Thread(sendRequest);
                                newThread.Start(req);
                            }
                        }
                        else if (line.Equals("db"))
                        {
                            foreach (var req in requests)
                                Console.WriteLine(string.Format("{0}", req));
                        }
                        else if (line.Equals("rst"))
                        {
                            serverController.reset();
                        }
                        else
                        {
                            Console.WriteLine("unknown command `" + line + "'");
                            menu();
                        }
                    }
                    catch (Ice.LocalException ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
                while (!line.Equals("x"));

                return 0;
            }