@Test public void testAddEventCharacterTimedEventLong() throws Exception { final Character chara = MockFactory.mockCharacter(); event = MockFactory.mockTimedEvent(chara); service.addEvent(chara, event, 10L); Thread.sleep(15L); verify(event).execute(); }
@Override public void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.get(chara); if (characterEvents == null) { events.putIfAbsent(chara, new HashMap<TimedEvent, TimerTaskAdapter>()); characterEvents = events.get(chara); } TimerTaskAdapter adaptedEvent = new TimerTaskAdapter(event, interval, repeatFor); synchronized (characterEvents) { if (events.get(chara) != characterEvents) { return; } if (adaptedEvent.getExecutionTimes() == 1) { timer.schedule(adaptedEvent, delay); } else { timer.scheduleAtFixedRate(adaptedEvent, delay, interval); } TimerTaskAdapter previous = characterEvents.put(event, adaptedEvent); if (previous != null) { previous.cancel(); timer.purge(); } } }
TimedEventsServiceImpl implements TimedEventsService { @Override public void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.get(chara); if (characterEvents == null) { events.putIfAbsent(chara, new HashMap<TimedEvent, TimerTaskAdapter>()); characterEvents = events.get(chara); } TimerTaskAdapter adaptedEvent = new TimerTaskAdapter(event, interval, repeatFor); synchronized (characterEvents) { if (events.get(chara) != characterEvents) { return; } if (adaptedEvent.getExecutionTimes() == 1) { timer.schedule(adaptedEvent, delay); } else { timer.scheduleAtFixedRate(adaptedEvent, delay, interval); } TimerTaskAdapter previous = characterEvents.put(event, adaptedEvent); if (previous != null) { previous.cancel(); timer.purge(); } } } }
TimedEventsServiceImpl implements TimedEventsService { @Override public void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.get(chara); if (characterEvents == null) { events.putIfAbsent(chara, new HashMap<TimedEvent, TimerTaskAdapter>()); characterEvents = events.get(chara); } TimerTaskAdapter adaptedEvent = new TimerTaskAdapter(event, interval, repeatFor); synchronized (characterEvents) { if (events.get(chara) != characterEvents) { return; } if (adaptedEvent.getExecutionTimes() == 1) { timer.schedule(adaptedEvent, delay); } else { timer.scheduleAtFixedRate(adaptedEvent, delay, interval); } TimerTaskAdapter previous = characterEvents.put(event, adaptedEvent); if (previous != null) { previous.cancel(); timer.purge(); } } }  }
TimedEventsServiceImpl implements TimedEventsService { @Override public void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.get(chara); if (characterEvents == null) { events.putIfAbsent(chara, new HashMap<TimedEvent, TimerTaskAdapter>()); characterEvents = events.get(chara); } TimerTaskAdapter adaptedEvent = new TimerTaskAdapter(event, interval, repeatFor); synchronized (characterEvents) { if (events.get(chara) != characterEvents) { return; } if (adaptedEvent.getExecutionTimes() == 1) { timer.schedule(adaptedEvent, delay); } else { timer.scheduleAtFixedRate(adaptedEvent, delay, interval); } TimerTaskAdapter previous = characterEvents.put(event, adaptedEvent); if (previous != null) { previous.cancel(); timer.purge(); } } }  @Override void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor); @Override void addEvent(Character chara, TimedEvent event, long delay); @Override void removeCharacterEvents(Character chara); @Override void removeEvent(TimedEvent event); }
TimedEventsServiceImpl implements TimedEventsService { @Override public void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor) { Map<TimedEvent, TimerTaskAdapter> characterEvents = events.get(chara); if (characterEvents == null) { events.putIfAbsent(chara, new HashMap<TimedEvent, TimerTaskAdapter>()); characterEvents = events.get(chara); } TimerTaskAdapter adaptedEvent = new TimerTaskAdapter(event, interval, repeatFor); synchronized (characterEvents) { if (events.get(chara) != characterEvents) { return; } if (adaptedEvent.getExecutionTimes() == 1) { timer.schedule(adaptedEvent, delay); } else { timer.scheduleAtFixedRate(adaptedEvent, delay, interval); } TimerTaskAdapter previous = characterEvents.put(event, adaptedEvent); if (previous != null) { previous.cancel(); timer.purge(); } } }  @Override void addEvent(Character chara, TimedEvent event, long delay, long interval, long repeatFor); @Override void addEvent(Character chara, TimedEvent event, long delay); @Override void removeCharacterEvents(Character chara); @Override void removeEvent(TimedEvent event);  }