@Override public void gc(final UIService uiService) { for (final SchedulerCommand command : commandByIDs.values()) { command.cancel(); } commandByIDs.clear(); }
@Override public void update(final PTInstruction update, final UIService uiService) { final long commandID = update.getLong(PROPERTY.COMMAND_ID); if (update.containsKey(PROPERTY.STOP)) { // Stop the command commandByIDs.remove(commandID).cancel(); } else if (update.containsKey(PROPERTY.FIXDELAY)) { // Fix-delay // Wait for execution terminated before scheduling again final SchedulerCommand previousCmd = commandByIDs.remove(commandID); if (previousCmd != null) previousCmd.cancel(); final int delay = update.getInt(PROPERTY.FIXDELAY); final FixDelayCommand command = new FixDelayCommand(uiService, update.getObjectID(), commandID, delay); Scheduler.get().scheduleFixedDelay(command, delay); commandByIDs.put(commandID, command); } else if (update.containsKey(PROPERTY.FIXRATE)) { // Fix-rate final SchedulerCommand previousCmd = commandByIDs.remove(commandID); if (previousCmd != null) previousCmd.cancel(); final int delay = update.getInt(PROPERTY.FIXRATE); final FixRateCommand command = new FixRateCommand(uiService, update.getObjectID(), commandID, delay); Scheduler.get().scheduleFixedDelay(command, delay); commandByIDs.put(commandID, command); } }