Created
June 29, 2010 04:15
-
-
Save afeinberg/456790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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