mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
* Fixed that PriorityTimer was not canceled. Added gaeId to Timer name.
This commit is contained in:
parent
b6c9b5bf02
commit
4e56e584b6
3 changed files with 8 additions and 21 deletions
|
|
@ -141,7 +141,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
PlayerPanelExt.this.avatar.repaint();
|
PlayerPanelExt.this.avatar.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
timer.init();
|
timer.init(gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package mage.utils.timer;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.UUID;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.interfaces.Action;
|
import mage.interfaces.Action;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
@ -34,9 +35,9 @@ public class PriorityTimer extends TimerTask {
|
||||||
this.taskOnTimeout = taskOnTimeout;
|
this.taskOnTimeout = taskOnTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init(UUID gameId) {
|
||||||
state = States.INIT;
|
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);
|
long delayMs = delay * (int) (1000L / delay);
|
||||||
timer.scheduleAtFixedRate(this, delayMs, delayMs);
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,9 @@ public class GameController implements GameCallback {
|
||||||
gameSessionPlayer.CleanUp();
|
gameSessionPlayer.CleanUp();
|
||||||
}
|
}
|
||||||
ChatManager.getInstance().destroyChatSession(chatId);
|
ChatManager.getInstance().destroyChatSession(chatId);
|
||||||
|
for(PriorityTimer priorityTimer: timers.values()) {
|
||||||
|
priorityTimer.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
@ -301,7 +304,7 @@ public class GameController implements GameCallback {
|
||||||
|
|
||||||
PriorityTimer timer = new PriorityTimer(count, delayMs, executeOnNoTimeLeft);
|
PriorityTimer timer = new PriorityTimer(count, delayMs, executeOnNoTimeLeft);
|
||||||
timers.put(playerId, timer);
|
timers.put(playerId, timer);
|
||||||
timer.init();
|
timer.init(game.getId());
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue