Cassandra Database(4) Kryo

Cassandra Database(4) Kryo 

Really useful document, I need to read them when I have time if I plan to deal with cassandra database.
http://www.datastax.com/documentation/cassandra/1.2/index.html?pagename=docs&version=1.2&file=index

1. Kryo Introduce
The latest version from the official website is 2.21. Adding to build.sbt

I only try a simple example for java HashMap
package com.sillycat.easycassandraserver.apps

import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.{Input, Output}
import java.util.{ HashMap => JMap }

object KryoDemoApp extends App{

  //java HashMap
  val maps = new JMap[String, Any]()
  maps.put("productName", "iphone4s")
  maps.put("price", 21.33)

  val kryo = new Kryo

  //transfer HashMap to bytes
  val out1 = new Output(new Array[Byte](4096))
  kryo.writeObject(out1, maps)
  out1.close
  val outputBytes1 = out1.toBytes
  println("outputBytes1 of Map = " + outputBytes1)

  //read the bytes back to HashMap
  val in1 = new Input(outputBytes1)
  val outputMap1 = kryo.readObject(in1,classOf[JMap[String, Any]])
  in1.close

  println("outputMap1 of Map = " + outputMap1)

}

The output should be as follow:
outputBytes1 of Map = [B@6581ed9e
outputMap1 of Map = {price=21.33, productName=iphone4s}

2. Chill
https://github.com/twitter/chill
That is a extensions for the KRYO.

…snip...


References:
http://www.datastax.com/documentation/cassandra/1.2/index.html?pagename=docs&version=1.2&file=index

Kryo
https://code.google.com/p/kryo/
http://blog.csdn.net/hengyunabc/article/details/7764509

Chill
https://github.com/twitter/chill




猜你喜欢

转载自sillycat.iteye.com/blog/2011526