Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created June 29, 2010 04:15
Show Gist options
  • Save afeinberg/456790 to your computer and use it in GitHub Desktop.
Save afeinberg/456790 to your computer and use it in GitHub Desktop.
def increment(key: String):Int = {
var rv:Int = -1
if (client.applyUpdate(new UpdateAction[String,String] {
def update(storeClient: StoreClient[String,String]) {
val value:Versioned[String] = storeClient.get(key)
if (value == null) {
storeClient.put(key, new Versioned[String]("1"))
}
else {
value.setObject((value.getValue.toInt + 1).toString)
storeClient.put(key, value)
rv = value.getValue.toInt
}
}
}, 100))
rv
else
throw new RuntimeException("Unable to update the counter, too many conflicts.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment