View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.translator.server.state;
2   
3   import cz.cuni.amis.fsm.FSMState;
4   import cz.cuni.amis.fsm.FSMTransition;
5   import cz.cuni.amis.fsm.IFSMState;
6   import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
7   import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldChangeEvent;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
9   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerListEnd;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerListStart;
11  import cz.cuni.amis.pogamut.ut2004.communication.translator.TranslatorContext;
12  import cz.cuni.amis.pogamut.ut2004.communication.translator.server.support.ServerListState;
13  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.PlayerListObtained;
14  
15  /**
16   * Takes care of the player list. It stores them inside a List object and when END message comes it sends
17   * them to the world view via PlayerListObtained event.
18   * <p><p>
19   * Last state of the handshake - we switch from this state to the ConfigureMessageExpectedState. 
20   * 
21   * @author Jimmy
22   */
23  @FSMState(map={@FSMTransition(
24  					state = ServerRunningState.class,
25  					symbol={PlayerListEnd.class}, 
26  					transition={})}
27  )
28  public class PlayerListState extends ServerListState<Player, TranslatorContext> {
29  
30  	public PlayerListState() {
31  		super(PlayerListStart.class, Player.class, PlayerListEnd.class);
32  	}
33  	
34  	@Override
35  	protected void innerStateSymbol(TranslatorContext context,
36  			InfoMessage symbol) {
37  		// TODO Auto-generated method stub
38  		super.innerStateSymbol(context, symbol);
39  		if (symbol instanceof Player) {
40  			context.getEventQueue().pushEvent((Player)symbol);
41  		}
42  	}
43  	
44  	@Override
45  	public void stateLeaving(TranslatorContext context,
46  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
47  		super.stateLeaving(context, toState, symbol);
48  		long simTime = 
49  			(symbol instanceof IWorldChangeEvent ? ((IWorldChangeEvent)symbol).getSimTime() : 0);
50  		context.getEventQueue().pushEvent(new PlayerListObtained(getList(), simTime));
51  		newList();
52  	}
53  
54  }