A single connection to a Cassandra node.
 /// <summary>
 /// Invoked when a connection is no longer in use by the application
 /// </summary>
 /// <param name="connection"> The connection no longer used. </param>
 /// <param name="scope"> The scope. </param>
 public void ReturnConnection(Connection connection, ConnectionScope scope)
 {
     //no-op
 }
 /// <summary>
 /// Invoked when a connection is no longer in use by the application
 /// </summary>
 /// <param name="connection"> The connection no longer used. </param>
 public void ReturnConnection(Connection connection, ConnectionScope scope)
 {
     //connections are shared, nothing to do here
 }
 public void ReturnConnection(Connection connection)
 {
     _connections.Push(connection);
 }
 /// <summary>
 ///   Invoked when a connection is no longer in use by the application
 /// </summary>
 /// <param name="connection"> The connection no longer used. </param>
 public void ReturnConnection(Connection connection)
 {
     //no-op
 }
 public void ReturnConnection(Connection connection, ConnectionScope scope)
 {
     connection.AllowCleanup = true;
     _connections.Push(connection);
 }
 /// <summary>
 ///   Invoked when a connection is no longer in use by the application
 /// </summary>
 /// <param name="connection"> The connection no longer used. </param>
 public void ReturnConnection(Connection connection)
 {
 }
 /// <summary>
 /// Invoked when a connection is no longer in use by the application
 /// </summary>
 /// <param name="connection"> The connection no longer used. </param>
 /// <param name="scope"> The scope. </param>
 public void ReturnConnection(Connection connection, ConnectionScope scope)
 {
     _baseStrategy.ReturnConnection(connection, scope);
 }
Beispiel #8
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component" /> and optionally releases
        /// the managed resources.
        /// </summary>
        /// <param name="disposing">
        /// true to release both managed and unmanaged resources; false to release only unmanaged
        /// resources.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if(!_disposed && disposing)
            {
                if(State == ConnectionState.Connecting)
                {
                    try
                    {
                        //wait until open is finished (may return immediatly)
                        _openTask.Wait();
                    }
                        // ReSharper disable EmptyGeneralCatchClause
                    catch
                    {
                        //ignore here
                    }
                    // ReSharper restore EmptyGeneralCatchClause
                }

                if(State == ConnectionState.Open)
                {
                    //return connection if any
                    if(_connection != null)
                    {
                        Cluster.ConnectionStrategy.ReturnConnection(_connection, ConnectionScope.Connection);
                        _connection = null;
                    }
                }

                //clear cluster
                _cluster = null;

                //clear database
                _database = string.Empty;

                //dispose any remaining cancel tokens
                if(_userCancelTokenSource != null)
                {
                    _userCancelTokenSource.Dispose();
                    _userCancelTokenSource = null;
                }

                if(_openCancellationTokenSource != null)
                {
                    _openCancellationTokenSource.Dispose();
                    _openCancellationTokenSource = null;
                }

                _disposed = true;
            }
            base.Dispose(disposing);
        }
Beispiel #9
0
        private void CompleteOpen(Logger logger)
        {
            //get a connection
            using(logger.ThreadBinding())
            {
                _connection = Cluster.ConnectionStrategy.GetOrCreateConnection(ConnectionScope.Connection,
                                                                               PartitionKey.None);
            }

            //set database to its default
            _database = Cluster.Config.Database;
        }
Beispiel #10
0
        /// <summary>
        /// Closes the connection to the database. This is the preferred method of closing any open connection.
        /// </summary>
        public override void Close()
        {
            if(State != ConnectionState.Closed)
            {
                var logger = LoggerManager.GetLogger("CqlSharp.CqlConnection.Close");

                try
                {
                    //wait until open is finished (may return immediatly)
                    _openTask.Wait();
                }
                catch(Exception ex)
                {
                    logger.LogVerbose("Closing connection that was not opened correctly: ", ex);
                }

                //return connection if any
                if(_connection != null)
                {
                    Cluster.ConnectionStrategy.ReturnConnection(_connection, ConnectionScope.Connection);
                    _connection = null;
                }

                //clear cluster
                _cluster = null;

                //clear database
                _database = string.Empty;

                //clear open task, such that open can be run again
                _openTask = null;
            }
        }