예제 #1
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!(active && asyncConnQueue.Enqueue(conn)))
     {
         CloseAsyncConn(conn);
     }
 }
예제 #2
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!active || !asyncConnQueue.TryAdd(conn))
     {
         conn.Close();
     }
 }
        public AsyncConnector(
            AsyncCluster cluster,
            AsyncNode node,
            ConnectorListener listener,
            SocketAsyncEventArgs args,
            byte[] buffer
            )
        {
            this.cluster             = cluster;
            this.node                = node;
            this.listener            = listener;
            this.eventArgs           = args;
            this.eventArgs.UserToken = this;
            this.dataBuffer          = buffer;

            this.watch = Stopwatch.StartNew();
            AsyncTimeoutQueue.Instance.Add(this, cluster.connectionTimeout);

            this.conn = new AsyncConnection(node.address, node);
            eventArgs.SetBuffer(dataBuffer, 0, 0);

            if (!conn.ConnectAsync(eventArgs))
            {
                ConnectionCreated();
            }
        }
예제 #4
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (!active || !asyncConnQueue.TryAdd(conn))
     {
         conn.Close();
     }
 }
        private void ExecuteCommand()
        {
            if (complete != 0)
            {
                AlreadyCompleted(complete);
                return;
            }

            try
            {
                node = GetNode();
                eventArgs.RemoteEndPoint = node.address;

                conn = node.GetAsyncConnection();

                if (conn == null)
                {
                    conn = new AsyncConnection(node.address, cluster);
                    eventArgs.SetBuffer(0, 0);

                    if (!conn.ConnectAsync(eventArgs))
                    {
                        ConnectionCreated();
                    }
                }
                else
                {
                    ConnectionReady();
                }
            }
            catch (AerospikeException.InvalidNode)
            {
                if (!RetryOnInit())
                {
                    throw;
                }
            }
            catch (AerospikeException.Connection)
            {
                if (!RetryOnInit())
                {
                    throw;
                }
            }
            catch (SocketException se)
            {
                if (!RetryOnInit())
                {
                    throw GetAerospikeException(se.SocketErrorCode);
                }
            }
            catch (Exception e)
            {
                if (!FailOnApplicationInit())
                {
                    throw new AerospikeException(e);
                }
            }
        }
예제 #6
0
 private void CloseConnection()
 {
     if (conn != null)
     {
         conn.Close();
         conn = null;
     }
 }
 private void CloseConnection()
 {
     if (conn != null)
     {
         node.CloseAsyncConnOnError(conn);
         conn = null;
     }
 }
        private void ExecuteCommand()
        {
            iteration++;

            try
            {
                node = (AsyncNode)GetNode(cluster);
                node.ValidateErrorCount();
                eventArgs.RemoteEndPoint = node.address;

                conn = node.GetAsyncConnection();

                if (conn == null)
                {
                    node.IncrAsyncConnTotal();
                    conn = new AsyncConnection(node.address, node);
                    eventArgs.SetBuffer(segment.buffer, segment.offset, 0);

                    if (!conn.ConnectAsync(eventArgs))
                    {
                        ConnectionCreated();
                    }
                }
                else
                {
                    ConnectionReady();
                }
                ErrorCount = 0;
            }
            catch (AerospikeException.Connection aec)
            {
                ErrorCount++;
                ConnectionFailed(aec);
            }
            catch (AerospikeException.Backoff aeb)
            {
                ErrorCount++;
                Backoff(aeb);
            }
            catch (AerospikeException ae)
            {
                ErrorCount++;
                FailOnApplicationError(ae);
            }
            catch (SocketException se)
            {
                ErrorCount++;
                ConnectionFailed(GetAerospikeException(se.SocketErrorCode));
            }
            catch (Exception e)
            {
                ErrorCount++;
                FailOnApplicationError(new AerospikeException(e));
            }
        }
예제 #9
0
 /// <summary>
 /// Put asynchronous connection back into connection pool.
 /// </summary>
 /// <param name="conn">socket connection</param>
 public void PutAsyncConnection(AsyncConnection conn)
 {
     if (active)
     {
         asyncConnQueue.Enqueue(conn);
     }
     else
     {
         conn.Close();
     }
 }
        /// <summary>
        /// Get asynchronous socket connection from connection pool for the server node.
        /// </summary>
        public AsyncConnection GetAsyncConnection()
        {
            // Try to find connection in pool.
            AsyncConnection conn = null;

            while (asyncConnQueue.TryDequeue(out conn))
            {
                if (conn.IsValid())
                {
                    return(conn);
                }
                conn.Close();
            }
            return(null);
        }
예제 #11
0
        /// <summary>
        /// Get asynchronous socket connection from connection pool for the server node.
        /// </summary>
        public AsyncConnection GetAsyncConnection()
        {
            // Try to find connection in pool.
            AsyncConnection conn = null;

            while (asyncConnQueue.TryDequeue(out conn))
            {
                if (cluster.IsConnCurrentTran(conn.LastUsed) && conn.IsValid())
                {
                    return(conn);
                }
                conn.Close();
            }
            return(null);
        }
        private void ExecuteCommand()
        {
            try
            {
                node = (AsyncNode)GetNode();
                eventArgs.RemoteEndPoint = node.address;

                conn = node.GetAsyncConnection();

                if (conn == null)
                {
                    conn = new AsyncConnection(node.address, cluster);
                    eventArgs.SetBuffer(segment.buffer, segment.offset, 0);

                    if (!conn.ConnectAsync(eventArgs))
                    {
                        ConnectionCreated();
                    }
                }
                else
                {
                    ConnectionReady();
                }
            }
            catch (AerospikeException.Connection)
            {
                if (!RetryOnInit())
                {
                    throw;
                }
            }
            catch (SocketException se)
            {
                if (!RetryOnInit())
                {
                    throw GetAerospikeException(se.SocketErrorCode);
                }
            }
            catch (Exception e)
            {
                if (!FailOnApplicationInit())
                {
                    throw new AerospikeException(e);
                }
            }
        }
예제 #13
0
        private void ExecuteCommand()
        {
            iteration++;

            try
            {
                if (partition != null)
                {
                    node = (AsyncNode)GetNode(cluster, policy, partition, isRead);
                }
                eventArgs.RemoteEndPoint = node.address;

                conn = node.GetAsyncConnection();

                if (conn == null)
                {
                    conn = new AsyncConnection(node.address, cluster, node);
                    eventArgs.SetBuffer(segment.buffer, segment.offset, 0);

                    if (!conn.ConnectAsync(eventArgs))
                    {
                        ConnectionCreated();
                    }
                }
                else
                {
                    ConnectionReady();
                }
            }
            catch (AerospikeException.Connection aec)
            {
                ConnectionFailed(aec);
            }
            catch (SocketException se)
            {
                ConnectionFailed(GetAerospikeException(se.SocketErrorCode));
            }
            catch (Exception e)
            {
                FailOnApplicationError(new AerospikeException(e));
            }
        }
예제 #14
0
        /// <summary>
        /// Get asynchronous socket connection from connection pool for the server node.
        /// </summary>
        public AsyncConnection GetAsyncConnection()
        {
            // Try to find connection in pool.
            AsyncConnection conn = null;

            while (asyncConnQueue.TryDequeue(out conn))
            {
                if (!cluster.IsConnCurrentTran(conn.LastUsed))
                {
                    CloseAsyncConn(conn);
                    continue;
                }

                if (!conn.IsValid())
                {
                    CloseAsyncConnOnError(conn);
                    continue;
                }
                return(conn);
            }
            return(null);
        }
        internal void Fail(string msg)
        {
            if (Interlocked.CompareExchange(ref state, 1, 0) == 0)
            {
                if (conn != null)
                {
                    conn.Close();
                    conn = null;
                }

                try
                {
                    listener.OnFailure(msg);
                }
                catch (Exception e)
                {
                    if (Log.WarnEnabled())
                    {
                        Log.Warn("OnFailure() error: " + Util.GetErrorMessage(e));
                    }
                }
            }
        }
 private void ResetConnection()
 {
     if (watch != null)
     {
         // A lock on reset is required when a client timeout is specified.
         lock (this)
         {
             if (conn != null)
             {
                 conn.Close();
                 conn = null;
             }
         }
     }
     else
     {
         if (conn != null)
         {
             conn.Close();
             conn = null;
         }
     }
 }
예제 #17
0
        private void ExecuteCommand()
        {
            if (complete != 0)
            {
                AlreadyCompleted(complete);
                return;
            }

            try
            {
                node = GetNode();
                eventArgs.RemoteEndPoint = node.address;

                conn = node.GetAsyncConnection();

                if (conn == null)
                {
                    conn = new AsyncConnection(node.address, cluster);
                    eventArgs.SetBuffer(segment.buffer, segment.offset, 0);

                    if (!conn.ConnectAsync(eventArgs))
                    {
                        ConnectionCreated();
                    }
                }
                else
                {
                    ConnectionReady();
                }
            }
            catch (AerospikeException.InvalidNode)
            {
                failedNodes++;
                if (!RetryOnInit())
                {
                    throw;
                }
            }
            catch (AerospikeException.Connection)
            {
                failedConns++;
                if (!RetryOnInit())
                {
                    throw;
                }
            }
            catch (SocketException se)
            {
                if (!RetryOnInit())
                {
                    throw GetAerospikeException(se.SocketErrorCode);
                }
            }
            catch (Exception e)
            {
                if (!FailOnApplicationInit())
                {
                    throw new AerospikeException(e);
                }
            }
        }
예제 #18
0
 internal void CloseAsyncConnOnError(AsyncConnection conn)
 {
     IncrErrorCount();
     CloseAsyncConn(conn);
 }
예제 #19
0
 private void ResetConnection()
 {
     if (watch != null)
     {
         // A lock on reset is required when a client timeout is specified.
         lock (this)
         {
             if (conn != null)
             {
                 conn.Close();
                 conn = null;
             }
         }
     }
     else
     {
         if (conn != null)
         {
             conn.Close();
             conn = null;
         }
     }
 }
예제 #20
0
 private void CloseAsyncConn(AsyncConnection conn)
 {
     DecrAsyncConnTotal();
     IncrAsyncConnClosed();
     conn.Close();
 }