package com.netflix.jmeter.connections.a6x;

import java.io.File;
import java.io.FileReader;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.model.ConsistencyLevel;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;
import com.netflix.jmeter.sampler.Connection;
import com.netflix.jmeter.sampler.Operation;

public class AstyanaxConnection extends Connection
{
    public static AstyanaxConnection instance = new AstyanaxConnection();
    public Properties config = new Properties();
    private Keyspace keyspace;

    public Keyspace keyspace()
    {
        if (keyspace != null)
            return keyspace;

        synchronized (AstyanaxConnection.class)
        {
            // double check...
            if (keyspace != null)
                return keyspace;
            try
            {
                
                com.netflix.jmeter.properties.Properties.instance.cassandra.addProperties(config);
                File propFile = new File("cassandra.properties");
                if (propFile.exists())
                    config.load(new FileReader(propFile));
                
                AstyanaxConfigurationImpl configuration = new AstyanaxConfigurationImpl()
                        .setDiscoveryType(NodeDiscoveryType.NONE)
                        .setDefaultReadConsistencyLevel(ConsistencyLevel.valueOf(com.netflix.jmeter.properties.Properties.instance.cassandra.getReadConsistency()))
                        .setDefaultWriteConsistencyLevel(ConsistencyLevel.valueOf(com.netflix.jmeter.properties.Properties.instance.cassandra.getWriteConsistency()));
                AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
                        .forCluster(getClusterName())
                        .forKeyspace(getKeyspaceName())
                        .withAstyanaxConfiguration(configuration)
                        .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(config.getProperty("astyanax.connection.pool", "TokenAware"))
                        .setPort(port)
                        .setMaxConnsPerHost(Integer.parseInt(com.netflix.jmeter.properties.Properties.instance.cassandra.getMaxConnsPerHost()))
                        .setSeeds(StringUtils.join(endpoints, ":" + port + ",")))
                        .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
                        .buildKeyspace(ThriftFamilyFactory.getInstance());
                context.start();
                keyspace = context.getEntity();
                return keyspace;
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
        }
    }

    public Operation newOperation(String columnName)
    {
        return new AstyanaxOperation(columnName);
    }
}

@@ -379,32 +379,100 @@
 figurationImpl;%0A
+import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;%0A
 import com.netfl
@@ -534,16 +534,16 @@
 onitor;%0A
-
 import c
@@ -1289,124 +1289,8 @@
   %7B%0A
-                %0A                com.netflix.jmeter.properties.Properties.instance.cassandra.addProperties(config);%0A
     
@@ -1453,25 +1453,8 @@
 ));%0A
-                %0A
     
@@ -1603,12 +1603,214 @@
 ype.
-NONE
+valueOf(config.getProperty(%22astyanax.connection.discovery%22, %22NONE%22)))%0A                        .setConnectionPoolType(ConnectionPoolType.valueOf(config.getProperty(%22astyanax.connection.pool%22, %22ROUND_ROBIN%22))
 )%0A  
@@ -2493,67 +2493,23 @@
 mpl(
-config.getProperty(%22astyanax.connection.pool%22, %22TokenAware%22
+getClusterName(
 ))%0A 

Update refresh with a6x changes