Example #1
0
        /// <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.CloseConnection(conn);
                throw;
            }
        }
 /// <summary>
 /// Initialize task that has already completed.
 /// </summary>
 public BaseTask()
 {
     this.cluster = null;
     this.policy = null;
     this.done = true;
 }
 public void Close()
 {
     if (this.client != null)
     {
         this.client.Close();
     }
     if (this.indexCache != null)
     {
         indexCache.Clear();
         indexCache = null;
     }
     updatePolicy = null;
     insertPolicy = null;
     infoPolicy = null;
     if (moduleCache != null)
     {
         moduleCache.Clear();
         moduleCache = null;
     }
 }
 /// <summary>
 /// Initialize task with fields needed to query server nodes.
 /// </summary>
 public BaseTask(Cluster cluster, Policy policy)
 {
     this.cluster = cluster;
     this.policy = new InfoPolicy(policy);
     this.done = false;
 }
 /// <summary>
 /// Wait for asynchronous task to complete using given sleep interval and timeout in milliseconds.
 /// If task is not complete by timeout, an exception is thrown.  Do not timeout if timeout set to
 /// zero.
 /// </summary>
 public void Wait(int sleepInterval, int timeout)
 {
     policy = new InfoPolicy();
     policy.timeout = timeout;
     TaskWait(sleepInterval);
 }
 /// <summary>
 /// Construct client without initialization.
 /// Should only be used by classes inheriting from this client.
 /// </summary>
 protected internal AerospikeClient(ClientPolicy policy)
 {
     if (policy != null)
     {
         this.readPolicyDefault = policy.readPolicyDefault;
         this.writePolicyDefault = policy.writePolicyDefault;
         this.scanPolicyDefault = policy.scanPolicyDefault;
         this.queryPolicyDefault = policy.queryPolicyDefault;
         this.batchPolicyDefault = policy.batchPolicyDefault;
         this.infoPolicyDefault = policy.infoPolicyDefault;
     }
     else
     {
         this.readPolicyDefault = new Policy();
         this.writePolicyDefault = new WritePolicy();
         this.scanPolicyDefault = new ScanPolicy();
         this.queryPolicyDefault = new QueryPolicy();
         this.batchPolicyDefault = new BatchPolicy();
         this.infoPolicyDefault = new InfoPolicy();
     }
 }
        /// <summary>
        /// Initialize Aerospike client with suitable hosts to seed the cluster map.
        /// The client policy is used to set defaults and size internal data structures.
        /// For each host connection that succeeds, the client will:
        /// <list type="bullet">
        /// <item>Add host to the cluster map</item>
        /// <item>Request host's list of other nodes in cluster</item>
        /// <item>Add these nodes to cluster map</item>
        /// </list>
        /// <para>
        /// In most cases, only one host is necessary to seed the cluster. The remaining hosts 
        /// are added as future seeds in case of a complete network failure.
        /// </para>
        /// <para>
        /// If one connection succeeds, the client is ready to process database requests.
        /// If all connections fail and the policy's failIfNotConnected is true, a connection 
        /// exception will be thrown. Otherwise, the cluster will remain in a disconnected state
        /// until the server is activated.
        /// </para>
        /// </summary>
        /// <param name="policy">client configuration parameters, pass in null for defaults</param>
        /// <param name="hosts">array of potential hosts to seed the cluster</param>
        /// <exception cref="AerospikeException">if all host connections fail</exception>
        public AerospikeClient(ClientPolicy policy, params Host[] hosts)
        {
            if (policy == null)
            {
                policy = new ClientPolicy();
            }
            this.readPolicyDefault = policy.readPolicyDefault;
            this.writePolicyDefault = policy.writePolicyDefault;
            this.scanPolicyDefault = policy.scanPolicyDefault;
            this.queryPolicyDefault = policy.queryPolicyDefault;
            this.batchPolicyDefault = policy.batchPolicyDefault;
            this.infoPolicyDefault = policy.infoPolicyDefault;

            cluster = new Cluster(policy, hosts);
            cluster.InitTendThread(policy.failIfNotConnected);
        }
        /// <summary>
        /// Remove user defined function from server nodes.
        /// </summary>
        /// <param name="policy">info configuration parameters, pass in null for defaults</param>
        /// <param name="serverPath">location of UDF on server nodes.  Example: mylua.lua </param>
        /// <exception cref="AerospikeException">if remove fails</exception>
        public void RemoveUdf(InfoPolicy policy, string serverPath)
        {
            if (policy == null)
            {
                policy = infoPolicyDefault;
            }
            // Send UDF command to one node. That node will distribute the UDF command to other nodes.
            string command = "udf-remove:filename=" + serverPath;
            Node node = cluster.GetRandomNode();
            string response = Info.Request(policy, node, command);

            if (response.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            if (response.StartsWith("error=file_not_found"))
            {
                // UDF has already been removed.
                return;
            }
            throw new AerospikeException("Remove UDF failed: " + response);
        }