public
Last active

Demo Adapting asynchbase to Scala

  • Download Gist
asynchbase.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 
package ca.underflow.hbase
 
import org.hbase.async._
import com.stumbleupon.async._
 
object Demo extends App {
 
// This let's us pass inline functions to the deferred
// object returned by most asynchbase methods
implicit def conv[A, B](f: B A): Callback[A, B] = {
new Callback[A, B]() {
def call(b: B) = f(b)
}
}
 
// Specify your zookeeper connection below
val client = new HBaseClient("localhost")
// Our dummy data
val put = new PutRequest("table", "row", "family", "column", "value")
// asynchbase client methods
client.ensureTableFamilyExists("table", "family") addCallback {
o: Object println("Put Succeeded")
} addErrback {
e: Exception
println("Table Assertion Error")
println(e.getMessage())
} join // wait for the assertion to continue
 
client.put(put) addCallback { o: Object
println("Inserted into Table")
} addErrback { e: Exception
println("Insertion error")
println(e.getMessage())
} join // need to wait, or else the app exits
 
println("Hello World")
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.