Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</execution>
</executions>
<configuration>
<!-- no luck <vscaladocVersion>1.1</vscaladocVersion> -->
<!-- no luck <vscaladocVersion>1.1</vscaladocVersion> -->
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-${java.compile.version}</arg>
Expand Down Expand Up @@ -132,6 +132,12 @@
</distributionManagement>

<repositories>
<repository>
<id>maven</id>
<name>Maven Main Repo</name>
<url>http://repo1.maven.org/maven2/</url>
</repository>

<repository>
<id>scala-tools.org-snapshots</id>
<name>Scala-Tools Maven2 Repository</name>
Expand Down Expand Up @@ -160,9 +166,9 @@
</dependency>

<dependency>
<groupId>org.apache.thrift</groupId>
<groupId>org.apache.cassandra.deps</groupId>
<artifactId>libthrift</artifactId>
<version>917130</version>
<version>0.5.0</version>
</dependency>

<dependency>
Expand All @@ -173,8 +179,8 @@

<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra</artifactId>
<version>0.6.1</version>
<artifactId>cassandra-all</artifactId>
<version>0.7.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object CascalStatistics extends CascalStatistics$MBean {
mbeanServer.registerMBean(this, objectName)
}


/**
* retrieves the stats for the specified host, creating and registering them if they don't
* exist.
Expand All @@ -60,7 +60,7 @@ object CascalStatistics extends CascalStatistics$MBean {
}

def register(pool:SessionPool) = pools = pool :: pools
def unregister(pool:SessionPool) = pools = pools - pool
def unregister(pool:SessionPool) = pools = pools.filterNot(_ == pool)

def creation(host:Host) = get(host).creation
def creationError(host:Host) = get(host).creationError
Expand Down Expand Up @@ -94,7 +94,7 @@ class HostStatistics(host:Host) extends HostStatisticsMBean {
def getTotalUsageTime() = usageTime
def getNumberOfCreationFailures() = createFails
def getNumberOfUsageExceptions() = usageErrors
def getNumberOfSessionsCreated() = created
def getNumberOfSessionsCreated() = created
}

trait HostStatisticsMBean {
Expand All @@ -109,4 +109,4 @@ trait HostStatisticsMBean {
trait CascalStatistics$MBean extends HostStatisticsMBean {
def getNumberOfActiveConnections():Int
def getNumberOfIdleConnections():Int
}
}
28 changes: 15 additions & 13 deletions src/main/scala/com/shorrockin/cascal/model/Column.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shorrockin.cascal.model

import java.nio.ByteBuffer
import java.util.Date
import org.apache.cassandra.thrift.{ColumnPath, ColumnOrSuperColumn}
import org.apache.cassandra.thrift.{Column => CassColumn}
Expand All @@ -15,14 +16,14 @@ import com.shorrockin.cascal.utils.Utils.now
* @author Chris Shorrock
* @param Owner the type of object which owns this column
*/
case class Column[Owner](val name:Array[Byte],
val value:Array[Byte],
case class Column[Owner](val name:ByteBuffer,
val value:ByteBuffer,
val time:Long,
val owner:Owner) extends Gettable[Column[Owner]] {

def this(name:Array[Byte], value:Array[Byte], owner:Owner) = this(name, value, now, owner)
def this(name:Array[Byte], owner:Owner) = this(name, null, now, owner)
def this(name:Array[Byte], value:Array[Byte], date:Date, owner:Owner) = this(name, value, date.getTime, owner)
def this(name:ByteBuffer, value:ByteBuffer, owner:Owner) = this(name, value, now, owner)
def this(name:ByteBuffer, owner:Owner) = this(name, null, now, owner)
def this(name:ByteBuffer, value:ByteBuffer, date:Date, owner:Owner) = this(name, value, date.getTime, owner)


val partial = (value == null)
Expand All @@ -44,7 +45,7 @@ case class Column[Owner](val name:Array[Byte],
case key:StandardKey => cosc.setColumn(new CassColumn(name, value, time))
case sup:SuperColumn =>
val list = Conversions.toJavaList(new CassColumn(name, value, time) :: Nil)
cosc.setSuper_column(new CassSuperColumn(sup.value, list))
cosc.setSuper_column(new CassSuperColumn(sup.value, list))
}
}

Expand All @@ -53,7 +54,7 @@ case class Column[Owner](val name:Array[Byte],
* copy method to create a new instance of this column with a new value and
* the same other values.
*/
def \(newValue:Array[Byte]) = new Column[Owner](name, newValue, time, owner)
def \(newValue:ByteBuffer) = new Column[Owner](name, newValue, time, owner)


/**
Expand All @@ -68,15 +69,16 @@ case class Column[Owner](val name:Array[Byte],
*/
def convertGetResult(colOrSuperCol:ColumnOrSuperColumn):Column[Owner] = {
val col = colOrSuperCol.getColumn
Column(col.getName, col.getValue, col.getTimestamp, owner)
Column(ByteBuffer.wrap(col.getName), ByteBuffer.wrap(col.getValue), col.getTimestamp, owner)
}

private def stringIfPossible(a:Array[Byte]):String = {
if (a.length <= 4) return "Array (" + a.mkString(", ") + ")"
if (a.length > 1000) return a.toString
try { Conversions.string(a) } catch { case _ => a.toString }
private def stringIfPossible(a:ByteBuffer):String = {
if (a == null) return "NULL"
if (a.array.length <= 4) return "Array (" + a.array.mkString(", ") + ")"
if (a.array.length > 1000) return a.array.toString
try { Conversions.string(a) } catch { case _ => a.array.toString }
}

override def toString():String = "%s \\ Column(name = %s, value = %s, time = %s)".format(
owner.toString, stringIfPossible(name), stringIfPossible(value), time)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shorrockin.cascal.model

import java.nio.ByteBuffer
import org.apache.cassandra.thrift.{ColumnParent, ColumnPath, ColumnOrSuperColumn}

/**
Expand All @@ -13,7 +14,7 @@ import org.apache.cassandra.thrift.{ColumnParent, ColumnPath, ColumnOrSuperColum
* @param ListType when listed, what type of object does it return.
*/
trait ColumnContainer[ColumnType, ListType] {
def \(value:Array[Byte]):ColumnType
def \(value:ByteBuffer):ColumnType

val family:ColumnFamily[_]
val key:Key[_, _]
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/shorrockin/cascal/model/Keyspace.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.shorrockin.cascal.model
import java.nio.ByteBuffer

/**
* provides the high level abstraction for the keyspace. can be thought
Expand All @@ -15,4 +16,4 @@ case class Keyspace(val value:String) extends StringValue {
def \(value:String):StandardColumnFamily = new StandardColumnFamily(value, this)
def \\(value:String):SuperColumnFamily = new SuperColumnFamily(value, this)
override def toString = "Keyspace(value = %s)".format(value)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.shorrockin.cascal.model
import java.nio.ByteBuffer

/**
* categorization of a cassandra path component.
Expand All @@ -13,10 +14,10 @@ trait PathComponent[ValueType] { val value:ValueType }
* categorization of a path component who's value is a byte
* @author Chris Shorrock
*/
trait ByteValue extends PathComponent[Array[Byte]]
trait ByteValue extends PathComponent[ByteBuffer]

/**
* categorization of path component who's value is a string
* @author Chris Shorrock
*/
trait StringValue extends PathComponent[String]
trait StringValue extends PathComponent[String]
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.shorrockin.cascal.model

import java.nio.ByteBuffer

/**
* a type of column container which holds standard columns.
*
* @author Chris Shorrock
*/
trait StandardColumnContainer[ColumnType, SliceType] extends ColumnContainer[ColumnType, SliceType] {
def \(name:Array[Byte]):ColumnType
def \(name:Array[Byte], value:Array[Byte]):ColumnType
def \(name:Array[Byte], value:Array[Byte], time:Long):ColumnType
def \(name:ByteBuffer):ColumnType
def \(name:ByteBuffer, value:ByteBuffer):ColumnType
def \(name:ByteBuffer, value:ByteBuffer, time:Long):ColumnType
}
11 changes: 6 additions & 5 deletions src/main/scala/com/shorrockin/cascal/model/StandardKey.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shorrockin.cascal.model

import java.nio.ByteBuffer
import org.apache.cassandra.thrift.{ColumnOrSuperColumn}

/**
Expand All @@ -12,16 +13,16 @@ import org.apache.cassandra.thrift.{ColumnOrSuperColumn}
case class StandardKey(val value:String, val family:StandardColumnFamily) extends Key[Column[StandardKey], Seq[Column[StandardKey]]]
with StandardColumnContainer[Column[StandardKey], Seq[Column[StandardKey]]] {

def \(name:Array[Byte]) = new Column(name, this)
def \(name:Array[Byte], value:Array[Byte]) = new Column(name, value, this)
def \(name:Array[Byte], value:Array[Byte], time:Long) = new Column(name, value, time, this)
def \(name:ByteBuffer) = new Column(name, this)
def \(name:ByteBuffer, value:ByteBuffer) = new Column(name, value, this)
def \(name:ByteBuffer, value:ByteBuffer, time:Long) = new Column(name, value, time, this)

def convertListResult(results:Seq[ColumnOrSuperColumn]):Seq[Column[StandardKey]] = {
results.map { (result) =>
val column = result.getColumn
\(column.getName, column.getValue, column.getTimestamp)
\(ByteBuffer.wrap(column.getName), ByteBuffer.wrap(column.getValue), column.getTimestamp)
}
}

override def toString = "%s \\ StandardKey(value = %s)".format(family.toString, value)
}
}
25 changes: 13 additions & 12 deletions src/main/scala/com/shorrockin/cascal/model/SuperColumn.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shorrockin.cascal.model

import java.nio.ByteBuffer
import org.apache.cassandra.thrift.{ColumnPath, ColumnParent, ColumnOrSuperColumn}
import com.shorrockin.cascal.utils.Conversions

Expand All @@ -10,19 +11,19 @@ import com.shorrockin.cascal.utils.Conversions
*
* @author Chris Shorrock
*/
case class SuperColumn(val value:Array[Byte], val key:SuperKey) extends Gettable[Seq[Column[SuperColumn]]]()
case class SuperColumn(val value:ByteBuffer, val key:SuperKey) extends Gettable[Seq[Column[SuperColumn]]]()
with StandardColumnContainer[Column[SuperColumn], Seq[Column[SuperColumn]]] {
def \(name:Array[Byte]) = new Column(name, this)
def \(name:Array[Byte], value:Array[Byte]) = new Column(name, value, this)
def \(name:Array[Byte], value:Array[Byte], time:Long) = new Column(name, value, time, this)
def \(name:ByteBuffer) = new Column(name, this)
def \(name:ByteBuffer, value:ByteBuffer) = new Column(name, value, this)
def \(name:ByteBuffer, value:ByteBuffer, time:Long) = new Column(name, value, time, this)

val family = key.family
val keyspace = family.keyspace

lazy val columnParent = new ColumnParent(family.value).setSuper_column(value)
lazy val columnPath = new ColumnPath(family.value).setSuper_column(value)

def ::(other:SuperColumn):List[SuperColumn] = other :: this :: Nil
def ::(other:SuperColumn):List[SuperColumn] = other :: this :: Nil

private def convertList[T](v:java.util.List[T]):List[T] = {
scala.collection.JavaConversions.asBuffer(v).toList
Expand All @@ -34,7 +35,7 @@ case class SuperColumn(val value:Array[Byte], val key:SuperKey) extends Gettable
*/
def convertGetResult(colOrSuperCol:ColumnOrSuperColumn):Seq[Column[SuperColumn]] = {
val superCol = colOrSuperCol.getSuper_column
convertList(superCol.getColumns).map { (column) => \(column.getName, column.getValue, column.getTimestamp) }
convertList(superCol.getColumns).map { (column) => \(ByteBuffer.wrap(column.getName), ByteBuffer.wrap(column.getValue), column.getTimestamp) }
}


Expand All @@ -45,16 +46,16 @@ case class SuperColumn(val value:Array[Byte], val key:SuperKey) extends Gettable
def convertListResult(results:Seq[ColumnOrSuperColumn]):Seq[Column[SuperColumn]] = {
results.map { (result) =>
val column = result.getColumn
\(column.getName, column.getValue, column.getTimestamp)
\(ByteBuffer.wrap(column.getName), ByteBuffer.wrap(column.getValue), column.getTimestamp)
}
}

private def stringIfPossible(a:Array[Byte]):String = {
if (a.length <= 4) return "Array (" + a.mkString(", ") + ")"
if (a.length > 1000) return a.toString
try { Conversions.string(a) } catch { case _ => a.toString }
private def stringIfPossible(a:ByteBuffer):String = {
if (a.array.length <= 4) return "Array (" + a.array.mkString(", ") + ")"
if (a.array.length > 1000) return a.array.toString
try { Conversions.string(a) } catch { case _ => a.array.toString }
}

override def toString():String = "%s \\ SuperColumn(value = %s)".format(
key.toString, stringIfPossible(value))
}
}
9 changes: 5 additions & 4 deletions src/main/scala/com/shorrockin/cascal/model/SuperKey.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.shorrockin.cascal.model

import org.apache.cassandra.thrift.{ColumnOrSuperColumn}
import java.nio.ByteBuffer

case class SuperKey(val value:String, val family:SuperColumnFamily) extends Key[SuperColumn, Seq[(SuperColumn, Seq[Column[SuperColumn]])]] {

def \(value:Array[Byte]) = new SuperColumn(value, this)
def \(value:ByteBuffer) = new SuperColumn(value, this)

/**
* converts a list of super columns to the specified return type
*/
def convertListResult(results:Seq[ColumnOrSuperColumn]):Seq[(SuperColumn, Seq[Column[SuperColumn]])] = {
results.map { (result) =>
val nativeSuperCol = result.getSuper_column
val superColumn = this \ nativeSuperCol.getName
val superColumn = this \ ByteBuffer.wrap(nativeSuperCol.getName)
val columns = convertList(nativeSuperCol.getColumns).map { (column) =>
superColumn \ (column.getName, column.getValue, column.getTimestamp)
superColumn \ (ByteBuffer.wrap(column.getName), ByteBuffer.wrap(column.getValue), column.getTimestamp)
}
(superColumn -> columns)
}
Expand All @@ -25,4 +26,4 @@ case class SuperKey(val value:String, val family:SuperColumnFamily) extends Key[
}

override def toString = "%s \\ SuperKey(value = %s)".format(family.toString, value)
}
}
Loading