private void ExecuteQuery(Cluster cluster, AdminPolicy policy)
        {
            WriteSize();
            Node       node    = cluster.GetRandomNode();
            int        timeout = (policy == null) ? 1000 : policy.timeout;
            int        status  = 0;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                conn.Write(dataBuffer, dataOffset);
                status = ReadBlocks(conn);
                node.PutConnection(conn);
            }
            catch (Exception e)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnectionOnError(conn);
                throw new AerospikeException(e);
            }

            if (status != QUERY_END && status > 0)
            {
                throw new AerospikeException(status, "Query failed.");
            }
        }
        private void ExecuteCommand(Cluster cluster, AdminPolicy policy)
        {
            WriteSize();
            Node       node    = cluster.GetRandomNode();
            int        timeout = (policy == null) ? 1000 : policy.timeout;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                conn.Write(dataBuffer, dataOffset);
                conn.ReadFully(dataBuffer, HEADER_SIZE);
                conn.UpdateLastUsed();
                node.PutConnection(conn);
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnectionOnError(conn);
                throw;
            }

            int result = dataBuffer[RESULT_CODE];

            if (result != 0)
            {
                throw new AerospikeException(result);
            }
        }
        //-------------------------------------------------------
        // Get Info via Node
        //-------------------------------------------------------

        /// <summary>
        /// Get one info value by name from the specified database server node.
        /// This method supports user authentication.
        /// </summary>
        /// <param name="node">server node</param>
        /// <param name="name">name of variable to retrieve</param>
        public static string Request(Node node, string name)
        {
            Connection conn = node.GetConnection(DEFAULT_TIMEOUT);

            try
            {
                string response = Info.Request(conn, name);
                node.PutConnection(conn);
                return(response);
            }
            catch (Exception)
            {
                node.CloseConnectionOnError(conn);
                throw;
            }
        }
        /// <summary>
        /// Get default info values from the specified database server node.
        /// This method supports user authentication.
        /// </summary>
        /// <param name="policy">info command configuration parameters, pass in null for defaults</param>
        /// <param name="node">server node</param>
        public static Dictionary <string, string> Request(InfoPolicy policy, Node node)
        {
            int        timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                Dictionary <string, string> result = Request(conn);
                node.PutConnection(conn);
                return(result);
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnectionOnError(conn);
                throw;
            }
        }
        public static RegisterTask Register(Cluster cluster, Policy policy, string content, string serverPath, Language language)
        {
            StringBuilder sb = new StringBuilder(serverPath.Length + content.Length + 100);

            sb.Append("udf-put:filename=");
            sb.Append(serverPath);
            sb.Append(";content=");
            sb.Append(content);
            sb.Append(";content-len=");
            sb.Append(content.Length);
            sb.Append(";udf-type=");
            sb.Append(language);
            sb.Append(";");

            // Send UDF to one node. That node will distribute the UDF to other nodes.
            string     command = sb.ToString();
            Node       node    = cluster.GetRandomNode();
            Connection conn    = node.GetConnection(policy.socketTimeout);

            try
            {
                Info info = new Info(conn, command);
                Info.NameValueParser parser = info.GetNameValueParser();
                string error   = null;
                string file    = null;
                string line    = null;
                string message = null;

                while (parser.Next())
                {
                    string name = parser.GetName();

                    if (name.Equals("error"))
                    {
                        error = parser.GetValue();
                    }
                    else if (name.Equals("file"))
                    {
                        file = parser.GetValue();
                    }
                    else if (name.Equals("line"))
                    {
                        line = parser.GetValue();
                    }
                    else if (name.Equals("message"))
                    {
                        message = parser.GetStringBase64();
                    }
                }

                if (error != null)
                {
                    throw new AerospikeException("Registration failed: " + error + Environment.NewLine +
                                                 "File: " + file + Environment.NewLine +
                                                 "Line: " + line + Environment.NewLine +
                                                 "Message: " + message
                                                 );
                }
                node.PutConnection(conn);
                return(new RegisterTask(cluster, policy, serverPath));
            }
            catch (Exception)
            {
                node.CloseConnectionOnError(conn);
                throw;
            }
        }