/** Dequeues and delivers one message. */ public boolean pump() { if (messages.isEmpty()) { return false; } Message message = (Message) messages.pop(); int destAddress = message.destination; if (!stateMachines.containsKey(destAddress)) { throw new IllegalStateException( "Couldn't deliver message addressed to non-existent state machine" + destAddress); } StateMachine stateMachine = (StateMachine) stateMachines.get(destAddress); stateMachine.deliver(message); return true; }