* Fixed draft start handling to prevent unneccessary waiting check start thread.

This commit is contained in:
LevelX2 2014-10-12 12:35:24 +02:00
parent b206983e75
commit 03337221c9
3 changed files with 29 additions and 13 deletions

View file

@ -149,19 +149,9 @@ public class DraftController {
return false;
}
private synchronized void startDraft() {
for (final Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
if (!entry.getValue().init()) {
logger.fatal("Unable to initialize client for playerId " + entry.getKey());
//TODO: generate client error message
return;
}
}
draft.start();
}
private void checkStart() {
if (allJoined()) {
private synchronized void checkStart() {
if (!draft.isStarted() && allJoined()) {
draft.setStarted();
ThreadExecutor.getInstance().getCallExecutor().execute(
new Runnable() {
@Override
@ -172,6 +162,17 @@ public class DraftController {
}
}
private void startDraft() {
for (final Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
if (!entry.getValue().init()) {
logger.fatal("Unable to initialize client for playerId " + entry.getKey());
//TODO: generate client error message
return;
}
}
draft.start();
}
private boolean allJoined() {
if (!draft.allJoined()) {
return false;

View file

@ -56,6 +56,9 @@ public interface Draft extends MageItem, Serializable {
int getCardNum();
boolean addPick(UUID playerId, UUID cardId);
void start();
boolean isStarted();
void setStarted();
boolean allJoined();
void leave(UUID playerId);
void autoPick(UUID playerId);
@ -68,4 +71,5 @@ public interface Draft extends MageItem, Serializable {
boolean isAbort();
void setAbort(boolean abort);
}

View file

@ -64,6 +64,7 @@ public abstract class DraftImpl implements Draft {
protected int[] times = {75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5};
protected boolean abort = false;
protected boolean started = false;
protected transient TableEventSource tableEventSource = new TableEventSource();
protected transient PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource();
@ -340,4 +341,14 @@ public abstract class DraftImpl implements Draft {
this.abort = abort;
}
@Override
public boolean isStarted() {
return started;
}
@Override
public void setStarted() {
started = true;
}
}