Ejemplo n.º 1
0
        /// <summary>
        /// Get many info values by name 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>
        /// <param name="names">names of variables to retrieve</param>
        public static Dictionary <string, string> Request(InfoPolicy policy, Node node, params string[] names)
        {
            int        timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                Dictionary <string, string> result = Request(conn, names);
                node.PutConnection(conn);
                return(result);
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                conn.Close();
                throw;
            }
        }
        /// <summary>
        /// Get one info value by name 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>
        /// <param name="name">name of variable to retrieve</param>
        public static string Request(InfoPolicy policy, Node node, string name)
        {
            int        timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                string result = Request(conn, name);
                node.PutConnection(conn);
                return(result);
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnection(conn);
                throw;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Copy client policy from another client policy.
 /// </summary>
 public ClientPolicy(ClientPolicy other)
 {
     this.user                 = other.user;
     this.password             = other.password;
     this.clusterName          = other.clusterName;
     this.timeout              = other.timeout;
     this.maxConnsPerNode      = other.maxConnsPerNode;
     this.connPoolsPerNode     = other.connPoolsPerNode;
     this.maxSocketIdle        = other.maxSocketIdle;
     this.tendInterval         = other.tendInterval;
     this.failIfNotConnected   = other.failIfNotConnected;
     this.readPolicyDefault    = new Policy(other.readPolicyDefault);
     this.writePolicyDefault   = new WritePolicy(other.writePolicyDefault);
     this.scanPolicyDefault    = new ScanPolicy(other.scanPolicyDefault);
     this.queryPolicyDefault   = new QueryPolicy(other.queryPolicyDefault);
     this.batchPolicyDefault   = new BatchPolicy(other.batchPolicyDefault);
     this.infoPolicyDefault    = new InfoPolicy(other.infoPolicyDefault);
     this.tlsPolicy            = (other.tlsPolicy != null) ? new TlsPolicy(other.tlsPolicy) : null;
     this.ipMap                = other.ipMap;
     this.requestProleReplicas = other.requestProleReplicas;
     this.useServicesAlternate = other.useServicesAlternate;
 }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
 public AsyncInfo(AsyncCluster cluster, InfoPolicy policy, InfoListener listener, AsyncNode node, params string[] commands)
     : base(cluster, CreatePolicy(policy), null, node, false)
 {
     this.listener = listener;
     this.commands = commands;
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initialize task that has already completed.
 /// </summary>
 public BaseTask()
 {
     this.cluster = null;
     this.policy  = null;
     this.done    = true;
 }
Ejemplo n.º 8
0
 /// <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);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initialize task that has already completed.
 /// </summary>
 public BaseTask()
 {
     this.cluster = null;
     this.policy = null;
     this.done = true;
 }
Ejemplo n.º 10
0
 /// <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;
 }
Ejemplo n.º 11
0
 /// <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;
 }
Ejemplo n.º 12
0
 /// <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);
        }