Execute() public method

public Execute ( string method, XmlRpcValue parameters, XmlRpcValue result ) : bool
method string
parameters XmlRpcValue
result XmlRpcValue
return bool
Ejemplo n.º 1
0
        public static bool kill(string node)
        {
            CachedXmlRpcClient cl = clientForNode(node);

            if (cl == null)
            {
                return(false);
            }
            XmlRpcValue req = new XmlRpcValue(), resp = new XmlRpcValue(), payl = new XmlRpcValue();

            req.Set(0, this_node.Name);
            req.Set(1, "Out of respect for Mrs. " + this_node.Name);
            if (!cl.Execute("shutdown", req, resp) || !XmlRpcManager.Instance.validateXmlrpcResponse("lookupNode", resp, ref payl))
            {
                return(false);
            }
            payl.Dump();
            XmlRpcManager.Instance.releaseXMLRPCClient(cl);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="method"></param>
        /// <param name="request">Full request to send to the master </param>
        /// <param name="response">Full response including status code and status message. Initially empty.</param>
        /// <param name="payload">Location to store the actual data requested, if any.</param>
        /// <param name="wait_for_master">If you recieve an unseccessful status code, keep retrying.</param>
        /// <returns></returns>
        public static bool execute(string method, XmlRpcValue request, ref XmlRpcValue response, ref XmlRpcValue payload,
                                   bool wait_for_master)
        {
            try
            {
                DateTime startTime   = DateTime.Now;
                string   master_host = host;
                int      master_port = port;

                //EDB.WriteLine("Trying to connect to master @ " + master_host + ":" + master_port);
                CachedXmlRpcClient client = XmlRpcManager.Instance.getXMLRPCClient(master_host, master_port, "/");
                bool printed = false;
                bool success = false;

                while (!success)
                {
                    // Check if we are shutting down
                    if (XmlRpcManager.Instance.shutting_down)
                    {
                        return(false);
                    }

                    // if the client is connected, execute the RPC call
                    success = client.IsConnected && client.Execute(method, request, response);

                    // Set success to false when response validation fails
                    if (success && !XmlRpcManager.Instance.validateXmlrpcResponse(method, response, ref payload))
                    {
                        success = false;
                    }

                    if (success)
                    {
                        XmlRpcManager.Instance.releaseXMLRPCClient(client);
                        return(true);
                    }
                    else
                    {
                        if (!wait_for_master)
                        {
                            XmlRpcManager.Instance.releaseXMLRPCClient(client);
                            return(false);
                        }

                        if (!printed)
                        {
                            EDB.WriteLine("[{0}] FAILED TO CONTACT MASTER AT [{1}:{2}]. {3}", method, master_host,
                                          master_port, (wait_for_master ? "Retrying..." : ""));
                            printed = true;
                        }
                        if (retryTimeout.TotalSeconds > 0 && DateTime.Now.Subtract(startTime) > retryTimeout)
                        {
                            EDB.WriteLine("[{0}] Timed out trying to connect to the master after [{1}] seconds", method,
                                          retryTimeout.TotalSeconds);
                            XmlRpcManager.Instance.releaseXMLRPCClient(client);
                            return(false);
                        }

                        //recreate the client, thereby causing it to reinitiate its connection (gross, but effective -- should really be done in xmlrpcwin32)
                        XmlRpcManager.Instance.releaseXMLRPCClient(client);
                        client = null;
                        Thread.Sleep(50);
                        client = XmlRpcManager.Instance.getXMLRPCClient(master_host, master_port, "/");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="method"></param>
        /// <param name="request">Full request to send to the master </param>
        /// <param name="response">Full response including status code and status message. Initially empty.</param>
        /// <param name="payload">Location to store the actual data requested, if any.</param>
        /// <param name="wait_for_master">If you recieve an unseccessful status code, keep retrying.</param>
        /// <returns></returns>
        public static bool execute(string method, XmlRpcValue request, XmlRpcValue response, XmlRpcValue payload,
                                   bool wait_for_master)
        {
            try
            {
                DateTime startTime   = DateTime.Now;
                string   master_host = host;
                int      master_port = port;

                CachedXmlRpcClient client = XmlRpcManager.Instance.getXMLRPCClient(master_host, master_port, "/");
                bool printed = false;
                bool success = false;
//				UnityEngine.Debug.LogWarning ( "Current thread ID " + Thread.CurrentThread.ManagedThreadId );

                while (!success)
                {
                    // Check if we are shutting down
                    if (XmlRpcManager.Instance.shutting_down)
                    {
                        return(false);
                    }

                    // if the client is connected, execute the RPC call
                    success = client.IsConnected && client.Execute(method, request, response);

                    if (client.IsConnected && !success)
                    {
                        if (response != null && response.asArray != null && response.asArray.Length >= 2)
                        {
                            EDB.WriteLine("Execute failed: return={0}, desc={1}", response[0].asInt, response[1].asString);
                        }
                        else
                        {
                            EDB.WriteLine("response type == " + (response != null ? response.Type.ToString() : "null"));
                        }
                    }

                    // Set success to false when response validation fails
                    if (success && !XmlRpcManager.Instance.validateXmlrpcResponse(method, response, payload))
                    {
                        success = false;
                    }

                    if (success)
                    {
                        XmlRpcManager.Instance.releaseXMLRPCClient(client);
                        return(true);
                    }
                    if (!wait_for_master)
                    {
                        XmlRpcManager.Instance.releaseXMLRPCClient(client);
                        return(false);
                    }

                    if (!printed)
                    {
                        EDB.WriteLine("[{0}] FAILED TO CONTACT MASTER AT [{1}:{2}]. {3}", method, master_host,
                                      master_port, (wait_for_master ? "Retrying for the next " + retryTimeout.TotalSeconds + " seconds..." : ""));
                        printed = true;
                    }
                    if (retryTimeout.TotalSeconds > 0 && DateTime.Now.Subtract(startTime) > retryTimeout)
                    {
                        EDB.WriteLine("[{0}] Timed out trying to connect to the master after [{1}] seconds", method,
                                      retryTimeout.TotalSeconds);
                        XmlRpcManager.Instance.releaseXMLRPCClient(client);
                        return(false);
                    }

                    //recreate the client, thereby causing it to reinitiate its connection (gross, but effective -- should really be done in xmlrpcwin32)
                    XmlRpcManager.Instance.releaseXMLRPCClient(client);
                    client = null;
                    Thread.Sleep(250);
                    client = XmlRpcManager.Instance.getXMLRPCClient(master_host, master_port, "/");
                }
            }
            catch (Exception e)
            {
                EDB.WriteLine(e);
            }
            EDB.WriteLine("Master API call: {0} failed!\n\tRequest:\n{1}", method, request);
            return(false);
        }