Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Java весна 2013 лекция 3
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18. public final boolean compareAndSet(int expect, int update) {
return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
}
public final int incrementAndGet() {
while (true) {
int current = get(); //get() возвращает текущее значение (volatile)
int next = current + 1;
if (compareAndSet(current, next))
return next;
}
}
27. public class Address {
static private AtomicInteger abonentIdCreator = new AtomicInteger();
final private int abonentId;
public Address(){
this.abonentId = abonentIdCreator.incrementAndGet();
}
public int hashCode() {
return abonentId;
}
}
public interface Abonent {
Address getAddress();
}
28. public abstract class Msg {
final private Address from;
final private Address to;
public Msg(Address from, Address to){
this.from = from;
this.to = to;
}
protected Address getFrom(){
return from;
}
protected Address getTo(){
return to;
}
public abstract void exec(Abonent abonent);
}
29. public abstract class MsgToFrontend extends Msg {
public MsgToFrontend(Address from, Address to) {
super(from, to);
}
public void exec(Abonent abonent) {
if( abonent instanceof Frontend ){
exec((Frontend)abonent);
}
}
public abstract void exec(Frontend frontend);
}
30. public class MsgUpdateUserId extends MsgToFrontend {
final private int sessionId;
final private int userId;
public GameInfoMsg(Address from, Address to, int sessionId, int userId) {
super(from, to);
this. sessionId = sessionId;
this. userId = userId;
}
public void exec(Frontend frontend) {
frontend.updateUserId(sessionId, userId);
}
}