diff --git a/pom.xml b/pom.xml
index 93ed10a2..4bff037a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -241,6 +241,12 @@
2.10.0
+
+ com.netflix.astyanax
+ astyanax
+ 1.56.48
+
+
diff --git a/src/com/comcast/cmb/common/controller/CMBControllerServlet.java b/src/com/comcast/cmb/common/controller/CMBControllerServlet.java
index ba89b9ec..8d52dd38 100644
--- a/src/com/comcast/cmb/common/controller/CMBControllerServlet.java
+++ b/src/com/comcast/cmb/common/controller/CMBControllerServlet.java
@@ -51,7 +51,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
-import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ScheduledThreadPoolExecutor;
diff --git a/src/com/comcast/cmb/common/persistence/AbstractCassandraPersistence.java b/src/com/comcast/cmb/common/persistence/AbstractCassandraPersistence.java
index 79a727de..dc279a26 100644
--- a/src/com/comcast/cmb/common/persistence/AbstractCassandraPersistence.java
+++ b/src/com/comcast/cmb/common/persistence/AbstractCassandraPersistence.java
@@ -3,23 +3,57 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Random;
import com.comcast.cmb.common.util.CMBProperties;
-import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
-import me.prettyprint.cassandra.service.template.SuperCfTemplate;
-import me.prettyprint.hector.api.HConsistencyLevel;
-import me.prettyprint.hector.api.Keyspace;
-import me.prettyprint.hector.api.Serializer;
-import me.prettyprint.hector.api.beans.ColumnSlice;
-import me.prettyprint.hector.api.beans.HSuperColumn;
-import me.prettyprint.hector.api.beans.Row;
-import me.prettyprint.hector.api.beans.SuperSlice;
-import me.prettyprint.hector.api.exceptions.HectorException;
-import me.prettyprint.hector.api.mutation.MutationResult;
-
public abstract class AbstractCassandraPersistence {
+ protected static Random rand = new Random();
+
+ public static enum CMB_SERIALIZER { STRING_SERIALIZER, COMPOSITE_SERIALIZER };
+
+ public static class CmbColumn {
+ public CmbColumn(N name, V value) {
+ this.name = name;
+ this.value = value;
+ }
+ public N name;
+ public V value;
+ }
+
+ public static class CmbRow {
+ public CmbRow(K key, List> row) {
+ this.key = key;
+ this.row = row;
+ }
+ public K key;
+ public List> row;
+ }
+
+ public static class CmbColumnSlice {
+ public CmbColumnSlice(List> slice) {
+ this.slice = slice;
+ }
+ public List> slice;
+ }
+
+ public static class CmbSuperColumnSlice {
+ public CmbSuperColumnSlice(List> slice) {
+ this.slice = slice;
+ }
+ public List> slice;
+ }
+
+ public static class CmbSuperColumn {
+ public CmbSuperColumn(SN superName, List> columns) {
+ this.superName = superName;
+ this.columns = columns;
+ }
+ public SN superName;
+ public List> columns;
+ }
+
public static final String CLUSTER_NAME = CMBProperties.getInstance().getClusterName();
public static final String CLUSTER_URL = CMBProperties.getInstance().getClusterUrl();
@@ -44,606 +78,120 @@ public static long getTimestampFromHash(long t){
t = t >> 21;
return t;
}
+
+ public java.util.UUID getTimeUUID(long timeMillis) throws InterruptedException {
+ return new java.util.UUID(newTime(timeMillis, false), com.eaio.uuid.UUIDGen.getClockSeqAndNode());
+ }
+
+ public java.util.UUID getUniqueTimeUUID(long millis) {
+ return new java.util.UUID(com.eaio.uuid.UUIDGen.createTime(millis), com.eaio.uuid.UUIDGen.getClockSeqAndNode());
+ }
+
+ public long getTimeLong(long timeMillis) throws InterruptedException {
+ long newTime = timeMillis * 1000000000 + (System.nanoTime() % 1000000) * 1000 + rand.nextInt(999999);
+ return newTime;
+ }
public abstract boolean isAlive();
- public abstract Keyspace getKeySpace(HConsistencyLevel consistencyLevel);
-
- /**
- * Update single key value pair in column family.
- *
- * @param template
- * column family
- * @param key
- * row key
- * @param column
- * column name
- * @param value
- * value K - type of row-key N - type of column name V - type of
- * column value
- * @throws HectorException
- */
- public abstract void update(String columnFamily, K key, N column, V value, Serializer keySerializer, Serializer nameSerializer, Serializer valueSerializer, HConsistencyLevel level)
- throws HectorException;
+ public abstract void update(String keyspace, String columnFamily, K key, N column, V value,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER nameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
- /**
- * Insert single key value pair for a super column.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param keySerializer
- * The serializer for the key
- * @param superName
- * super column name
- * @param ttl
- * The time to live
- * @param superNameSerializer
- * serializer for the super column name
- * @param subColumnNameValues
- * name, value pair for the sub columns
- * @param columnSerializer
- * the serializer for sub column name
- * @param valueSerializer
- * the serializer for sub column value K - type of row-key SN -
- * type of super column name N - type of sub column name V - type
- * of column value
- * @throws HectorException
- */
- public abstract MutationResult insertSuperColumn(
- String columnFamily, K key, Serializer keySerializer,
- SN superName, Integer ttl, Serializer superNameSerializer,
- Map subColumnNameValues, Serializer columnSerializer,
- Serializer valueSerializer, HConsistencyLevel level)
- throws HectorException;
+ public abstract void insertSuperColumn(String keyspace, String columnFamily, K key, CMB_SERIALIZER keySerializer, SN superName, Integer ttl,
+ CMB_SERIALIZER superNameSerializer, Map subColumnNameValues, CMB_SERIALIZER columnSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception;
- /**
- * Insert a map of key value pairs for a super column.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param keySerializer
- * The serializer for the key
- * @param superNameSubColumnsMap
- * A map of super column names as the key and a map of sub-column
- * name values as the value
- * @param ttl
- * The time to live
- * @param superNameSerializer
- * serializer for the super column name
- * @param subColumnNameValues
- * name, value pair for the sub columns
- * @param columnSerializer
- * the serializer for sub column name
- * @param valueSerializer
- * the serializer for sub column value K - type of row-key SN -
- * type of super column name N - type of sub column name V - type
- * of column value
- * @throws HectorException
- */
- public abstract MutationResult insertSuperColumns(
- String columnFamily, K key, Serializer keySerializer,
+ public abstract void insertSuperColumns(
+ String keyspace, String columnFamily, K key, CMB_SERIALIZER keySerializer,
Map> superNameSubColumnsMap, int ttl,
- Serializer superNameSerializer, Serializer columnSerializer,
- Serializer valueSerializer, HConsistencyLevel level)
- throws HectorException;
-
- /**
- * Read single value from column family.
- *
- * @param template
- * column family
- * @param key
- * row key
- * @param column
- * column name
- * @return value of type T N - type of column name V - type of column value
- * Note: Assumed the row key is a string
- * @throws HectorException
- *
- */
- public abstract V read(ColumnFamilyTemplate template,
- String key, N column, V returnType) throws HectorException;
-
- /**
- * Read next numRows rows with a maximum of 100 columns per row.
- *
- * @param columnFamily
- * column family
- * @param lastKey
- * last key read before or null
- * @param numRows
- * maximum number of rows to read
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- */
- public abstract List> readNextNRows(
- String columnFamily, K lastKey, int numRows,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level);
-
- /**
- * Read next numRows rows with a maximum of numCols columns per row.
- *
- * @param columnFamily
- * column family
- * @param lastKey
- * last key read before or null
- * @param numRows
- * maximum number of rows to read
- * @param numCols
- * maximum number of columns to read
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- */
- public abstract List> readNextNRows(
- String columnFamily, K lastKey, int numRows, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level);
-
- /**
- * Read next numRows rows with a maximum of numCols columns per row. Ensure
- * all returned rows are non-empty rows.
- *
- * @param columnFamily
- * column family
- * @param lastKey
- * last key read before or null
- * @param numRows
- * maximum number of rows to read
- * @param numCols
- * maximum number of columns to read
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- */
- public abstract List> readNextNNonEmptyRows(
- String columnFamily, K lastKey, int numRows, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level);
-
- /**
- * Read next numRows rows obeying single where clause.
- *
- * @param columnFamily
- * column family
- * @param lastKey
- * last key read before or null
- * @param whereColumn
- * where clause column
- * @param whereValue
- * where clause value
- * @param numRows
- * maximum number of rows
- * @param numCols
- * maximum number of columns
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- */
- public abstract List> readNextNRows(
- String columnFamily, K lastKey, N whereColumn, V whereValue,
- int numRows, int numCols, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
-
- /**
- * Read next numRows rows obeying complex where clause.
- *
- * @param columnFamily
- * column family
- * @param lastKey
- * last key read before or null
- * @param columnValues
- * hash map with key value pairs for where clause
- * @param numRows
- * maximum number of rows to read
- * @param numCols
- * maximum number of columns to read
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- */
- public abstract List> readNextNRows(
- String columnFamily, K lastKey, Map columnValues,
- int numRows, int numCols, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
+ CMB_SERIALIZER superNameSerializer, CMB_SERIALIZER columnSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readNextNNonEmptyRows(
+ String keyspace, String columnFamily, K lastKey, int numRows, int numCols,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER columnNameSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readNextNRows(
+ String keyspace, String columnFamily, K lastKey, int numRows, int numCols,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER columnNameSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readNextNRows(
+ String keyspace, String columnFamily, K lastKey, N whereColumn, V whereValue,
+ int numRows, int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readNextNRows(
+ String keyspace, String columnFamily, K lastKey, Map columnValues,
+ int numRows, int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract CmbColumnSlice readColumnSlice(
+ String keyspace, String columnFamily, K key, N firstColumnName, N lastColumnName,
+ int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract CmbSuperColumnSlice readRowFromSuperColumnFamily(
+ String keyspace, String columnFamily, K key, SN firstColumnName, SN lastColumnName,
+ int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER superNameSerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract CmbSuperColumn readColumnFromSuperColumnFamily(
+ String keyspace, String columnFamily, K key, SN columnName,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER superNameSerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readMultipleColumnsFromSuperColumnFamily(
+ String keyspace, String columnFamily, Collection keys,
+ Collection columnNames, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER superNameSerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer) throws Exception;
+
+ public abstract List> readColumnsFromSuperColumnFamily(
+ String keyspace, String columnFamily, K key, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER superNameSerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer,
+ SN firstCol, SN lastCol, int numCol) throws Exception;
+
+ public abstract void insertRow(K rowKey,
+ String keyspace, String columnFamily, Map columnValues,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER nameSerializer,
+ CMB_SERIALIZER valueSerializer, Integer ttl) throws Exception;
+
+ public abstract void insertRows(
+ String keyspace, Map> rowColumnValues, String columnFamily,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER nameSerializer,
+ CMB_SERIALIZER valueSerializer, Integer ttl) throws Exception;
+
+ public abstract void delete(String keyspace, String columnFamily, K key, N column,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER columnSerializer) throws Exception;
+
+ public abstract void deleteBatch(String keyspace, String columnFamily,
+ List keyList, List columnList, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnSerializer) throws Exception;
- /**
- * Read single row by row key.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param numCols
- * maximum number of columns
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- * @return row Will get row starting from the beginning
- */
- public abstract ColumnSlice readColumnSlice(
- String columnFamily, K key, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level);
-
- /**
- * Read single row by row key.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param firstColumnName
- * the beginning of the slice column
- * @param lastColumnName
- * the end of the slice column
- * @param numCols
- * maximum number of columns
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- * @return row
- */
- public abstract ColumnSlice readColumnSlice(
- String columnFamily, K key, N firstColumnName, N lastColumnName,
- int numCols, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
-
- /**
- * Read a row slice by row key and super column slice.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param firstColumnName
- * the beginning of the slice column
- * @param lastColumnName
- * the end of the slice column
- * @param numCols
- * maximum number of columns
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- * @return row
- */
- public abstract SuperSlice readRowFromSuperColumnFamily(
- String columnFamily, K key, SN firstColumnName, SN lastColumnName,
- int numCols, Serializer keySerializer,
- Serializer superNameSerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
-
- /**
- * Read a single column by row key using SuperColumnQuery.
- *
- * @param columnFamily
- * column family
- * @param key
- * row key
- * @param columnName
- * the column key of the super column
- * @param keySerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * consistency level
- * @return list of rows K - type of row-key N - type of column name V - type
- * of column value
- * @return row
- */
- public abstract HSuperColumn readColumnFromSuperColumnFamily(
- String columnFamily, K key, SN columnName,
- Serializer keySerializer, Serializer superNameSerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
-
- public abstract List> readMultipleColumnsFromSuperColumnFamily(
- String columnFamily, Collection keys,
- Collection columnNames, Serializer keySerializer,
- Serializer superNameSerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level);
-
- /**
- * Read multiple supercolumns from a column family given roe-key, and optional first-col, last-col and numCol
- * @param
- * @param
- * @param
- * @param
- * @param columnFamily
- * @param key
- * @param keySerializer
- * @param superNameSerializer
- * @param columnNameSerializer
- * @param valueSerializer
- * @param level
- * @param firstCol The starting of the range
- * @param lastCol The end of the range
- * @param numCol the number of columns to read
- * @return
- */
- public abstract List> readColumnsFromSuperColumnFamily(
- String columnFamily, K key, Serializer keySerializer,
- Serializer superNameSerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level, SN firstCol, SN lastCol, int numCol);
-
- /**
- * Insert or update single row.
- *
- * @param rowKey
- * row key
- * @param columnFamily
- * column family
- * @param columnValues
- * hash map containing key value pairs for columns to insert or
- * update
- * @param level
- * consistency level
- * @return Note: This method assumes a String for key, column-name & value
- */
- public abstract MutationResult insertOrUpdateRow(String rowKey,
- String columnFamily, Map columnValues,
- HConsistencyLevel level);
-
- /**
- * Insert or update single row with ttl.
- *
- * @param rowKey
- * row key
- * @param columnFamily
- * column family
- * @param columnValues
- * hash map containing key value pairs for columns to insert or
- * update
- * @param level
- * consistency level
- * @param ttl
- * time to live
- * @return Note: This method assumes a String for key, column-name & value
- */
- public abstract MutationResult insertRow(String rowKey,
- String columnFamily, Map columnValues,
- HConsistencyLevel level, Integer ttl);
-
- /**
- * Insert or update single row with ttl. K is the key type, N is column name
- * type and V is the column value type
- *
- * @param rowKey
- * row key
- * @param columnFamily
- * column family
- * @param columnValues
- * hash map containing key value pairs for columns to insert or
- * update
- * @param level
- * consistency level
- * @param ttl
- * time to live
- * @return Note: This method assumes a String for key, column-name & value
- */
- public abstract MutationResult insertRow(K rowKey,
- String columnFamily, Map columnValues,
- Serializer keySerializer, Serializer nameSerializer,
- Serializer valueSerializer, HConsistencyLevel level, Integer ttl);
-
- /**
- * Insert or update single row with ttl. K is the key type, N is column name
- * type and V is the column value type
- *
- * @param rowColumnValues
- * A map containing row keys and a map of column names, column
- * values
- * @param columnFamily
- * column family
- * @param level
- * consistency level
- * @param ttl
- * time to live
- * @return Note: This method assumes a String for key, column-name & value
- */
- public abstract MutationResult insertRows(
- Map> rowColumnValues, String columnFamily,
- Serializer keySerializer, Serializer nameSerializer,
- Serializer valueSerializer, HConsistencyLevel level, Integer ttl);
-
- /**
- *
- * @param columnFamily
- * @param key
- * @param column
- * @param keySerializer
- * @param columnSerializer
- * @param level
- * @throws HectorException
- */
- public abstract void delete(String columnFamily, K key, N column,
- Serializer keySerializer, Serializer columnSerializer,
- HConsistencyLevel level) throws HectorException;
-
-
- /**
- * Delete single column value or the entire row
- *
- * @param template
- * column family
- * @param key
- * row key
- * @param column
- * column name. If column is null, the entire row is deleted
- * @throws HectorException
- */
- public abstract void deleteBatch(String columnFamily,
- List keyList, List columnList, Serializer keySerializer,
- HConsistencyLevel level, Serializer columnSerializer)
- throws HectorException;
-
- /**
- * Delete single column value or the entire row
- *
- * @param template
- * column family
- * @param key
- * row key
- * @param superColumn
- * column name. If column is null, the entire row is deleted
- * @throws HectorException
- */
public abstract void deleteSuperColumn(
- String superColumnFamily, K key, SN superColumn, Serializer keySerializer, Serializer superColumnSerializer,
- HConsistencyLevel level)
- throws HectorException;
-
- /**
- * Create a unique time based UUID
- *
- * @param timeMillis
- * Time in milli seconds since Jan 1, 1970
- * @throws InterruptedException
- */
- public abstract java.util.UUID getTimeUUID(long timeMillis)
- throws InterruptedException;
-
- /**
- * Create a unique time based UUID
- *
- * @param millis
- * time
- */
- public abstract java.util.UUID getUniqueTimeUUID(long millis);
-
- /**
- * Create a unique time based long value
- *
- * @param timeMillis
- * Time in milli seconds since Jan 1, 1970
- * @throws InterruptedException
- */
- public abstract long getTimeLong(long timeMillis)
- throws InterruptedException;
+ String keyspace, String superColumnFamily, K key, SN superColumn, CMB_SERIALIZER keySerializer, CMB_SERIALIZER superColumnSerializer) throws Exception;
- /**
- * Return the column count.
- *
- * @param columnFamily
- * The name of the column family.
- * @param key
- * The row key (as a string)
- * @param level
- * The consistency level of the keyspace.
- */
- public abstract int getCount(String columnFamily, K key,
- Serializer keySerializer, Serializer columnNameSerializer,
- HConsistencyLevel level) throws HectorException;
+ public abstract int getCount(String keyspace, String columnFamily, K key,
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER columnNameSerializer) throws Exception;
- /**
- * Increment Cassandra counter by incrementBy
- * @param
- * @param
- * @param columnFamily
- * @param rowKey
- * @param columnName
- * @param incrementBy
- * @param keySerializer
- * @param columnNameSerializer
- * @param level
- */
- public abstract void incrementCounter(String columnFamily, K rowKey,
- String columnName, int incrementBy, Serializer keySerializer,
- Serializer columnNameSerializer, HConsistencyLevel level);
+ public abstract void incrementCounter(String keyspace, String columnFamily, K rowKey,
+ String columnName, int incrementBy, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer) throws Exception;
- /**
- * Decrement Cassandra counter by decrementBy
- *
- * @param
- * @param
- * @param columnFamily
- * @param rowKey
- * @param columnName
- * @param decrementBy
- * @param keySerializer
- * @param columnNameSerializer
- * @param level
- */
- public abstract void decrementCounter(String columnFamily, K rowKey,
- String columnName, int decrementBy, Serializer keySerializer,
- Serializer columnNameSerializer, HConsistencyLevel level);
+ public abstract void decrementCounter(String keyspace, String columnFamily, K rowKey,
+ String columnName, int decrementBy, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer) throws Exception;
- /**
- * Decrement Cassandra counter by decrementBy
- *
- * @param
- * @param
- * @param columnFamily
- * @param rowKey
- * @param columnName
- * @param decrementBy
- * @param keySerializer
- * @param columnNameSerializer
- * @param level
- */
- public abstract void deleteCounter(String columnFamily, K rowKey,
- N columnName, Serializer keySerializer,
- Serializer columnNameSerializer, HConsistencyLevel level);
+ public abstract void deleteCounter(String keyspace, String columnFamily, K rowKey,
+ N columnName, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer) throws Exception;
- /**
- * Return current value of Cassandra counter
- *
- * @param
- * @param
- * @param columnFamily
- * @param rowKey
- * @param columnName
- * @param keySerializer
- * @param columnNameSerializer
- * @param level
- * @return
- */
- public abstract long getCounter(String columnFamily, K rowKey,
- N columnName, Serializer keySerializer,
- Serializer columnNameSerializer, HConsistencyLevel level);
+ public abstract long getCounter(String keyspace, String columnFamily, K rowKey,
+ N columnName, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer) throws Exception;
}
\ No newline at end of file
diff --git a/src/com/comcast/cmb/common/persistence/CassandraAstyanaxPersistence.java b/src/com/comcast/cmb/common/persistence/CassandraAstyanaxPersistence.java
index de7ebe1e..7f96d81d 100644
--- a/src/com/comcast/cmb/common/persistence/CassandraAstyanaxPersistence.java
+++ b/src/com/comcast/cmb/common/persistence/CassandraAstyanaxPersistence.java
@@ -1,23 +1,53 @@
package com.comcast.cmb.common.persistence;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
-import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
-import me.prettyprint.cassandra.service.template.SuperCfTemplate;
-import me.prettyprint.hector.api.HConsistencyLevel;
-import me.prettyprint.hector.api.Keyspace;
-import me.prettyprint.hector.api.Serializer;
-import me.prettyprint.hector.api.beans.ColumnSlice;
-import me.prettyprint.hector.api.beans.HSuperColumn;
-import me.prettyprint.hector.api.beans.Row;
-import me.prettyprint.hector.api.beans.SuperSlice;
-import me.prettyprint.hector.api.exceptions.HectorException;
-import me.prettyprint.hector.api.mutation.MutationResult;
+import com.comcast.cmb.common.util.CMBProperties;
+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.thrift.ThriftFamilyFactory;
public class CassandraAstyanaxPersistence extends AbstractCassandraPersistence {
+
+ private static Map keyspaces = new HashMap();
+
+ private void init() {
+
+ List keyspaceNames = new ArrayList();
+ keyspaceNames.add(CMBProperties.getInstance().getCMBKeyspace());
+ keyspaceNames.add(CMBProperties.getInstance().getCNSKeyspace());
+ keyspaceNames.add(CMBProperties.getInstance().getCQSKeyspace());
+
+ for (String k : keyspaceNames) {
+
+ AstyanaxContext context = new AstyanaxContext.Builder()
+ .forCluster(CLUSTER_NAME)
+ .forKeyspace(CMBProperties.getInstance().getCMBKeyspace())
+ .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
+ .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
+ )
+ .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("CMBAstyananxConnectionPool")
+ //.setPort(9160)
+ .setMaxConnsPerHost(1)
+ .setSeeds(AbstractCassandraPersistence.CLUSTER_URL)
+ )
+ .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
+ .buildKeyspace(ThriftFamilyFactory.getInstance());
+
+ context.start();
+ Keyspace keyspace = context.getClient();
+
+ keyspaces.put(CMBProperties.getInstance().getCMBKeyspace(), keyspace);
+ }
+ }
@Override
public boolean isAlive() {
@@ -26,266 +56,209 @@ public boolean isAlive() {
}
@Override
- public Keyspace getKeySpace(HConsistencyLevel consistencyLevel) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void update(String columnFamily, K key, N column, V value, Serializer keySerializer, Serializer nameSerializer, Serializer valueSerializer, HConsistencyLevel level)
- throws HectorException {
+ public void update(String keyspace, String columnFamily, K key,
+ N column, V value, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER nameSerializer, CMB_SERIALIZER valueSerializer)
+ throws Exception {
// TODO Auto-generated method stub
-
+
}
@Override
- public MutationResult insertSuperColumn(String columnFamily,
- K key, Serializer keySerializer, SN superName, Integer ttl,
- Serializer superNameSerializer, Map subColumnNameValues,
- Serializer columnSerializer, Serializer valueSerializer,
- HConsistencyLevel level) throws HectorException {
+ public void insertSuperColumn(String keyspace,
+ String columnFamily, K key, CMB_SERIALIZER keySerializer,
+ SN superName, Integer ttl, CMB_SERIALIZER superNameSerializer,
+ Map subColumnNameValues, CMB_SERIALIZER columnSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception {
// TODO Auto-generated method stub
- return null;
+
}
@Override
- public MutationResult insertSuperColumns(String columnFamily,
- K key, Serializer keySerializer,
+ public void insertSuperColumns(String keyspace,
+ String columnFamily, K key, CMB_SERIALIZER keySerializer,
Map> superNameSubColumnsMap, int ttl,
- Serializer superNameSerializer, Serializer columnSerializer,
- Serializer valueSerializer, HConsistencyLevel level)
- throws HectorException {
+ CMB_SERIALIZER superNameSerializer,
+ CMB_SERIALIZER columnSerializer, CMB_SERIALIZER valueSerializer)
+ throws Exception {
// TODO Auto-generated method stub
- return null;
+
}
@Override
- public V read(ColumnFamilyTemplate template, String key,
- N column, V returnType) throws HectorException {
+ public List> readNextNNonEmptyRows(
+ String keyspace, String columnFamily, K lastKey, int numRows,
+ int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer)
+ throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
- public List> readNextNRows(String columnFamily,
- K lastKey, int numRows, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List> readNextNRows(String columnFamily,
- K lastKey, int numRows, int numCols, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List> readNextNNonEmptyRows(
+ public List> readNextNRows(String keyspace,
String columnFamily, K lastKey, int numRows, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List> readNextNRows(String columnFamily,
- K lastKey, N whereColumn, V whereValue, int numRows, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List> readNextNRows(String columnFamily,
- K lastKey, Map columnValues, int numRows, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level) {
+ CMB_SERIALIZER keySerializer, CMB_SERIALIZER columnNameSerializer,
+ CMB_SERIALIZER valueSerializer) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
- public ColumnSlice readColumnSlice(String columnFamily,
- K key, int numCols, Serializer keySerializer,
- Serializer columnNameSerializer, Serializer valueSerializer,
- HConsistencyLevel level) {
+ public List> readNextNRows(String keyspace,
+ String columnFamily, K lastKey, N whereColumn, V whereValue,
+ int numRows, int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer)
+ throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
- public ColumnSlice readColumnSlice(String columnFamily,
- K key, N firstColumnName, N lastColumnName, int numCols,
- Serializer keySerializer, Serializer columnNameSerializer,
- Serializer valueSerializer, HConsistencyLevel level) {
+ public List> readNextNRows(String keyspace,
+ String columnFamily, K lastKey, Map columnValues,
+ int numRows, int numCols, CMB_SERIALIZER keySerializer,
+ CMB_SERIALIZER columnNameSerializer, CMB_SERIALIZER valueSerializer)
+ throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
- public