20. public class Address {
static private AtomicInteger abonentIdCreator = new AtomicInteger();
final private int abonentId;
public Address(){
this.abonentId = abonentIdCreator.incrementAndGet();
}
public int getAbonentId() {
return abonentId;
}
}
public interface Abonent {
Address getAddress();
}
21. 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);
}
22. 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);
}
23. 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);
}
}