Class ShipArivalInPortEventListener

  • Direct Known Subclasses:
    WaitTimeForShipArrival

    public abstract class ShipArivalInPortEventListener
    extends java.lang.Object
    Event listener that implements the event listening for the ShipEntersPortEvent for a specific city and then executes execute(). The listener has to be added to the clientServerEventBus by the concrete class.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2013 Created on Feb 19, 2013
    • Field Detail

      • city

        private final ICity city
      • player

        private final IPlayer player
      • clientServerEventBus

        @Autowired
        @Qualifier("serverClientEventBus")
        protected com.google.common.eventbus.AsyncEventBus clientServerEventBus
    • Constructor Detail

      • ShipArivalInPortEventListener

        public ShipArivalInPortEventListener​(ICity city,
                                             IPlayer player)
    • Method Detail

      • handleShipEntersPort

        public void handleShipEntersPort​(ShipEntersPortEvent event)
        Handling the event when a ship enters the port. Subclasses are intended to override this implementation by extension implement the correct logic. This base implementation provides two points:
        1. if the player and city that triggered the event match with the ones listed to by this instance the ship is set on this instance
        2. Then the execute() method is called and if it returns true this instance is unregistered from the event bus. Otherwise the ship is set to null.
        Parameters:
        event - for the ship entering the port
      • execute

        public abstract boolean execute()
        Execute an action.
        Returns:
        flag indicating if the execution was successful and therefor the event listener can be removed.