Thanks Nathan,
I got it to compile after I supplied scala-library.jar and it works now:
final Map<String, String> map = STM.newMap();
STM.atomic(new Runnable() {
public void run() {
map.put("1", "2");
}
});
Here is some sample code to show what the use case was in my initial post:
final Map<String, String> map1 = STM.newMap();
final Map<String, String> map2 = STM.newMap();
// add some data to map1 and map2
STM.atomic(Txn txn, new Runnable() {
public void run() {
map1.put("1", "2");
map2.remove("3");
txn.prepare();
// prepare commit was successful if we get here
// now send out notifications that value added to map1 with key "1" and value removed from map2 with key "3"
tx.commit();
}
});
The idea is here that I can do a prepare commit. If it is successful, it is guaranteed that the final commit will succeed. So after the prepare commit I can send my notifications out about what data changed in what day. This way the notifications are send out in the order respective atomic blocks commit. For a real scenario some change log would be walked through to send all the notifications out. When that has been completed the final commit is done. Synchronous notification would be fine enough for me.
Problem is that when I do something like this:
STM.atomic(new Runnable() {
public void run() {
map1.put("1", "2");
// make entry to change log
map2.remove("3");
// make entry to change log
}
});
STM.atomic(new Runnable() {
public void run() {
changelog do: send every change notification out
}
});
I'm not sure that the notifications will be sent out in the order individual atomic blocks commit as there might be context switches between the former atomic block and the latter where the change log is processed.
I'm not looking for something specific that das a prepare commit and then a final commit. My question is only whether there is a way to do what I'm looking for.
Kind regards, Oliver