public CassandraClient Create(CassandraEndpoint endpoint)
        {
            TSocket socket = null;
            TTransport transport = null;
            if (endpoint.Timeout == 0)
            {
                socket = new TSocket(endpoint.Address, endpoint.Port);
            }
            else
            {
                socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout);
            }

            if (this.isBufferSizeSet)
            {
                transport = new TBufferedTransport(socket, this.bufferSize);
            }
            else
            {
                transport = new TBufferedTransport(socket);
            }

            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client cassandraClient = new Cassandra.Client(protocol);
            CassandraClient client = new CassandraClient(cassandraClient, endpoint);

            this.logger.Debug(logger.StringFormatInvariantCulture("Created a new connection using: '{0}'", endpoint.ToString()));

            return client;
        }
 public void Close()
 {
     long startedTicks = DateTime.Now.Ticks;
     if (this.isClientHealthy)
     {
         this.cluster.ConnectionPool.Release(this.cassandraClient);
         this.logger.Debug("Connection released.");
     }
     else
     {
         this.cluster.ConnectionPool.Invalidate(this.cassandraClient);
         this.logger.Debug("Connection returned as invalid.");
     }
     this.cassandraClient = null;
     TimeSpan duration = new TimeSpan(DateTime.Now.Ticks - startedTicks);
     logger.Info(logger.StringFormatInvariantCulture("Releasing / invalidating a connection took {0} ms.", duration.Milliseconds));
 }
 public void Release(CassandraClient cassandraClient)
 {
     this.InjectedClient.CloseTransport();
 }
 public void Invalidate(CassandraClient cassandraClient)
 {
     this.InjectedClient.CloseTransport();
     // lets hurry and invalidate this endpoint for future use =)
     if (this.EndpointManager != null)
     {
         this.EndpointManager.Ban(cassandraClient.Endpoint);
     }
 }
Example #5
0
 public void Release(CassandraClient cassandraClient)
 {
     cassandraClient.CloseTransport();
 }
Example #6
0
 public void Invalidate(CassandraClient cassandraClient)
 {
     cassandraClient.CloseTransport();
 }
 private void UnmarkAsReferenced(CassandraClient client)
 {
     lock (this.referencedClients)
     {
         this.referencedClients.Remove(client);
     }
 }
 private void MarkAsReferenced(CassandraClient borrowedClient)
 {
     lock (this.referencedClients)
     {
         this.referencedClients.Add(borrowedClient);
     }
 }
 private void MarkAsIdle(CassandraClient client)
 {
     lock (this.idleClients)
     {
         this.idleClients.Enqueue(client);
     }
 }
 private void destroy(CassandraClient cassandraClient)
 {
     this.logger.Debug(logger.StringFormatInvariantCulture("Pool '{0}' - Destroying '{1}'.", this.Name, cassandraClient));
     cassandraClient.CloseTransport();
     this.managedClientQuantity--;
 }
 public void Release(CassandraClient cassandraClient)
 {
     this.logger.Debug(logger.StringFormatInvariantCulture("Pool '{0}' - Unmarking client '{1}' as referenced.", this.Name, cassandraClient));
     this.UnmarkAsReferenced(cassandraClient);
     this.logger.Debug(logger.StringFormatInvariantCulture("Marking client '{0}' as idle.", cassandraClient));
     this.MarkAsIdle(cassandraClient);
 }
 public void Invalidate(CassandraClient cassandraClient)
 {
     this.logger.Debug(logger.StringFormatInvariantCulture("Pool '{0}' - Unmarking client '{1}' as referenced.", this.Name, cassandraClient));
     this.UnmarkAsReferenced(cassandraClient);
     this.logger.Debug(logger.StringFormatInvariantCulture("Pool '{0}' - Marking endpoint '{1}' as invalid.", this.Name, cassandraClient.Endpoint));
     this.endpointManager.Ban(cassandraClient.Endpoint);
     this.destroy(cassandraClient);
 }
 public void Open()
 {
     long startedTicks = DateTime.Now.Ticks;
     this.cassandraClient = this.cluster.ConnectionPool.Borrow();
     TimeSpan duration = new TimeSpan(DateTime.Now.Ticks - startedTicks);
     logger.Info(logger.StringFormatInvariantCulture("Getting a connection took {0} ms.", duration.Milliseconds));
     if (this.cassandraClient != null)
     {
         this.logger.Debug("Connection opened");
     }
     else
     {
         string message = String.Format(CultureInfo.CurrentCulture, "Couldn't retrieve a client from the pool whose cluster parent is '{0}'.", this.cluster.FriendlyName);
         this.logger.Fatal(message);
         throw new AquilesException(message);
     }
 }