* Fixed that PriorityTimer was not canceled. Added gaeId to Timer name.

This commit is contained in:
LevelX2 2015-02-05 22:43:51 +01:00
parent b6c9b5bf02
commit 4e56e584b6
3 changed files with 8 additions and 21 deletions

View file

@ -141,7 +141,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
PlayerPanelExt.this.avatar.repaint();
}
});
timer.init();
timer.init(gameId);
}
}

View file

@ -2,6 +2,7 @@ package mage.utils.timer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import mage.MageException;
import mage.interfaces.Action;
import org.apache.log4j.Logger;
@ -34,9 +35,9 @@ public class PriorityTimer extends TimerTask {
this.taskOnTimeout = taskOnTimeout;
}
public void init() {
public void init(UUID gameId) {
state = States.INIT;
Timer timer = new Timer("Priority Timer", false);
Timer timer = new Timer("Priority Timer-" + gameId.toString(), false);
long delayMs = delay * (int) (1000L / delay);
timer.scheduleAtFixedRate(this, delayMs, delayMs);
}
@ -105,21 +106,4 @@ public class PriorityTimer extends TimerTask {
}
}
public static void main(String[] args) throws Exception {
long delay = 250L;
int count = 5;
PriorityTimer timer = new PriorityTimer(count, delay, new Action() {
@Override
public void execute() throws MageException {
System.out.println("Exit");
System.exit(0);
}
});
timer.init();
timer.start();
Thread.sleep(2000);
timer.pause();
Thread.sleep(3000);
timer.resume();
}
}

View file

@ -141,6 +141,9 @@ public class GameController implements GameCallback {
gameSessionPlayer.CleanUp();
}
ChatManager.getInstance().destroyChatSession(chatId);
for(PriorityTimer priorityTimer: timers.values()) {
priorityTimer.cancel();
}
}
private void init() {
@ -301,7 +304,7 @@ public class GameController implements GameCallback {
PriorityTimer timer = new PriorityTimer(count, delayMs, executeOnNoTimeLeft);
timers.put(playerId, timer);
timer.init();
timer.init(game.getId());
return timer;
}