Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created April 20, 2012 17:47
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save groundwater/2430613 to your computer and use it in GitHub Desktop.
Save groundwater/2430613 to your computer and use it in GitHub Desktop.
Demo Adapting asynchbase to Scala
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")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment