// Path: src/main/java/com/wizecommerce/hecuba/util/ClientManagerUtils.java
// public class ClientManagerUtils {
// 	private static final ClientManagerUtils instance = new ClientManagerUtils();
// 
// 	private ClientManagerUtils() {
// 	}
// 
// 	public static ClientManagerUtils getInstance() {
// 		return instance;
// 	}
// 
// 	public String convertValueForStorage(Object input) {
// 		if (input == null) {
// 			return "null";
// 		}
// 
// 		if (input instanceof Date) {
// 			return HecubaConstants.DATE_FORMATTER.print(((Date) input).getTime());
// 		}
// 
// 		return input.toString();
// 	}
// }
// 
// Path: src/main/java/com/wizecommerce/hecuba/util/ConfigUtils.java
// public class ConfigUtils {
// 	private static ConfigUtils ourInstance = new ConfigUtils();
// 
// 	private static Configuration mainConfiguration = new CompositeConfiguration();
// 
// 	public static ConfigUtils getInstance() {
// 		return ourInstance;
// 	}
// 
// 	public static ConfigUtils getInstance(Configuration configuration) {
// 		mainConfiguration = configuration;
// 		return ourInstance;
// 	}
// 
// 	private ConfigUtils() {
// 	}
// 
// 	public Configuration getConfiguration() {
// 		return mainConfiguration;
// 	}
// }


import java.nio.ByteBuffer;
import java.util.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import com.google.common.base.Joiner;
import com.netflix.astyanax.*;
import com.netflix.astyanax.clock.ClockType;
import com.netflix.astyanax.connectionpool.Host;
import com.netflix.astyanax.connectionpool.HostStats;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.connectionpool.impl.*;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.model.*;
import com.netflix.astyanax.query.ColumnQuery;
import com.netflix.astyanax.query.PreparedIndexExpression;
import com.netflix.astyanax.query.RowQuery;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;
import com.wizecommerce.hecuba.*;
import com.wizecommerce.hecuba.util.ClientManagerUtils;
import com.wizecommerce.hecuba.util.ConfigUtils;
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wizecommerce.hecuba.astyanax;





/**
 * @author Eran Chinthaka Withana
 */
public class AstyanaxBasedHecubaClientManager<K> extends HecubaClientManager<K> {

	Keyspace keyspace;
	ColumnFamily<K, String> columnFamily;
	ColumnFamily<String, K> secondaryIndexColumnFamily;
	AstyanaxConfigurationImpl astyanaxConfigurationImpl;
	ConnectionPoolConfigurationImpl connectionPoolConfigurationImpl;
	CountingConnectionPoolMonitor connectionPoolMonitor;
	AstyanaxContext<Keyspace> context;
	AstyanaxContext<Cluster> clusterContext;
	Serializer<K> keySerializer;

	private Clock clock = ClockType.ASYNC_MICRO.get();

	public AstyanaxBasedHecubaClientManager() {

	}

	public AstyanaxBasedHecubaClientManager(CassandraParamsBean parameters, Serializer<K> keySerializer) {
		super(parameters);
		initialize(getClusterName(), getLocationURL(), getPort(), getKeyspace());
		this.columnFamily = new ColumnFamily<K, String>(getColumnFamilyName(), keySerializer, StringSerializer.get());
		this.keySerializer = keySerializer;

		if (columnsToIndexOnColumnNameAndValue != null && columnsToIndexOnColumnNameAndValue.size() > 0) {
			String secondaryIndexedColumnFamily = ConfigUtils.getInstance().getConfiguration().getString(
					HecubaConstants.GLOBAL_PROP_NAME_PREFIX + "." + columnFamily + ".secondaryIndexCF",
					columnFamily.getName() + HecubaConstants.SECONDARY_INDEX_CF_NAME_SUFFIX);
			this.secondaryIndexColumnFamily = new ColumnFamily<String, K>(secondaryIndexedColumnFamily,
					StringSerializer.get(), keySerializer);


		}
	}

	public void initialize(String clusterName, String locationUrls, String port, String keyspaceName) {
		astyanaxConfigurationImpl = new AstyanaxConfigurationImpl();
// Path: src/main/java/com/wizecommerce/hecuba/util/ClientManagerUtils.java
// public class ClientManagerUtils {
// 	private static final ClientManagerUtils instance = new ClientManagerUtils();
// 
// 	private ClientManagerUtils() {
// 	}
// 
// 	public static ClientManagerUtils getInstance() {
// 		return instance;
// 	}
// 
// 	public String convertValueForStorage(Object input) {
// 		if (input == null) {
// 			return "null";
// 		}
// 
// 		if (input instanceof Date) {
// 			return HecubaConstants.DATE_FORMATTER.print(((Date) input).getTime());
// 		}
// 
// 		return input.toString();
// 	}
// }
// 
// Path: src/main/java/com/wizecommerce/hecuba/util/ConfigUtils.java
// public class ConfigUtils {
// 	private static ConfigUtils ourInstance = new ConfigUtils();
// 
// 	private static Configuration mainConfiguration = new CompositeConfiguration();
// 
// 	public static ConfigUtils getInstance() {
// 		return ourInstance;
// 	}
// 
// 	public static ConfigUtils getInstance(Configuration configuration) {
// 		mainConfiguration = configuration;
// 		return ourInstance;
// 	}
// 
// 	private ConfigUtils() {
// 	}
// 
// 	public Configuration getConfiguration() {
// 		return mainConfiguration;
// 	}
// }


// Path: src/main/java/com/wizecommerce/hecuba/astyanax/AstyanaxBasedHecubaClientManager.java
import java.nio.ByteBuffer;
import java.util.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import com.google.common.base.Joiner;
import com.netflix.astyanax.*;
import com.netflix.astyanax.clock.ClockType;
import com.netflix.astyanax.connectionpool.Host;
import com.netflix.astyanax.connectionpool.HostStats;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.connectionpool.impl.*;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.model.*;
import com.netflix.astyanax.query.ColumnQuery;
import com.netflix.astyanax.query.PreparedIndexExpression;
import com.netflix.astyanax.query.RowQuery;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;
import com.wizecommerce.hecuba.*;
import com.wizecommerce.hecuba.util.ClientManagerUtils;
import com.wizecommerce.hecuba.util.ConfigUtils;

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.wizecommerce.hecuba.astyanax;





/**
 * @author Eran Chinthaka Withana
 */
public class AstyanaxBasedHecubaClientManager<K> extends HecubaClientManager<K> {

	Keyspace keyspace;
	ColumnFamily<K, String> columnFamily;
	ColumnFamily<String, K> secondaryIndexColumnFamily;
	AstyanaxConfigurationImpl astyanaxConfigurationImpl;
	ConnectionPoolConfigurationImpl connectionPoolConfigurationImpl;
	CountingConnectionPoolMonitor connectionPoolMonitor;
	AstyanaxContext<Keyspace> context;
	AstyanaxContext<Cluster> clusterContext;
	Serializer<K> keySerializer;

	private Clock clock = ClockType.ASYNC_MICRO.get();

	public AstyanaxBasedHecubaClientManager() {

	}

	public AstyanaxBasedHecubaClientManager(CassandraParamsBean parameters, Serializer<K> keySerializer) {
		super(parameters);
		initialize(getClusterName(), getLocationURL(), getPort(), getKeyspace());
		this.columnFamily = new ColumnFamily<K, String>(getColumnFamilyName(), keySerializer, StringSerializer.get());
		this.keySerializer = keySerializer;

		if (columnsToIndexOnColumnNameAndValue != null && columnsToIndexOnColumnNameAndValue.size() > 0) {
			String secondaryIndexedColumnFamily = ConfigUtils.getInstance().getConfiguration().getString(
					HecubaConstants.GLOBAL_PROP_NAME_PREFIX + "." + columnFamily + ".secondaryIndexCF",
					columnFamily.getName() + HecubaConstants.SECONDARY_INDEX_CF_NAME_SUFFIX);
			this.secondaryIndexColumnFamily = new ColumnFamily<String, K>(secondaryIndexedColumnFamily,
					StringSerializer.get(), keySerializer);


		}
	}

	public void initialize(String clusterName, String locationUrls, String port, String keyspaceName) {
		astyanaxConfigurationImpl = new AstyanaxConfigurationImpl();
		final Configuration configuration = ConfigUtils.getInstance().getConfiguration();