View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.translator.observer.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.observer.support.ObserverListState;
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=ObserverRunningState.class, 
25  					symbol={PlayerListEnd.class}, 
26  					transition={})}
27  )
28  public class PlayerListState extends ObserverListState<Player, TranslatorContext> {
29  
30  	public PlayerListState() {
31  		super(PlayerListStart.class, Player.class, PlayerListEnd.class);
32  	}
33  	
34  	@Override
35  	public void stateLeaving(TranslatorContext context,
36  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
37  		long simTime = 
38  			(symbol instanceof IWorldChangeEvent ? ((IWorldChangeEvent)symbol).getSimTime() : 0);
39  		context.getEventQueue().pushEvent(new PlayerListObtained(getList(), simTime));
40  		newList();
41  	}
42  	
43  	@Override
44  	protected void innerStateSymbol(TranslatorContext context,
45  			InfoMessage symbol) {
46  		super.innerStateSymbol(context, symbol);
47  		if (symbol instanceof Player) {
48  			context.getEventQueue().pushEvent((Player)symbol);
49  		}
50  	}
51  
52  }