2010-11-12 16:09:31 +13:00
|
|
|
package akka.stm.example;
|
2010-08-16 11:38:39 +12:00
|
|
|
|
2010-10-26 12:49:25 +02:00
|
|
|
import akka.stm.*;
|
2010-08-16 11:38:39 +12:00
|
|
|
|
|
|
|
|
public class TransactionalMapExample {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
System.out.println();
|
|
|
|
|
System.out.println("TransactionalMap example");
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
|
|
final TransactionalMap<String, User> users = new TransactionalMap<String, User>();
|
|
|
|
|
|
|
|
|
|
// fill users map (in a transaction)
|
|
|
|
|
new Atomic() {
|
|
|
|
|
public Object atomically() {
|
|
|
|
|
users.put("bill", new User("bill"));
|
|
|
|
|
users.put("mary", new User("mary"));
|
|
|
|
|
users.put("john", new User("john"));
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
|
|
|
|
|
System.out.println("users: " + users);
|
|
|
|
|
|
|
|
|
|
// access users map (in a transaction)
|
|
|
|
|
User user = new Atomic<User>() {
|
|
|
|
|
public User atomically() {
|
|
|
|
|
return users.get("bill").get();
|
|
|
|
|
}
|
|
|
|
|
}.execute();
|
|
|
|
|
|
|
|
|
|
System.out.println("user: " + user);
|
|
|
|
|
}
|
|
|
|
|
}
|