Commit 3e21274b authored by Xiaoying Pu's avatar Xiaoying Pu

now the thing should display break msg after time's up for a chunk of...

now the thing should display break msg after time's up for a chunk of decisions; mousetracker can still complain about moving mouse too slow and stuff tho
parent 8d85eeb6
......@@ -12,5 +12,6 @@ public enum ActionType {
CONNECT_UDP,
START_ONE_DECISION,
START_MULTI_DECISION,
SLEEP_FOR_DECISIONS,
END_SHOWING_DIGIT;
}
......@@ -17,6 +17,7 @@ public class Configurator {
private static int tSTask;
private static int tPause;
private static int tDecisions;
private static int nTrials;
/**
* @throws java.io.IOException
......@@ -46,18 +47,28 @@ public class Configurator {
String strNHighWorkLoad = prop.getProperty("tSTask");
String strTPause = prop.getProperty("tPause");
String strTDecisions = prop.getProperty("tDecisions");
String strnTrial = prop.getProperty("nTrials");
try {
tPTask = Integer.parseInt(strNTrials);
tSTask = Integer.parseInt(strNHighWorkLoad);
tPause = Integer.parseInt(strTPause);
tDecisions = Integer.parseInt(strTDecisions);
nTrials = Integer.parseInt(strnTrial);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
public static int getnTrials() {
return nTrials;
}
public static int gettDecisions() {
return tDecisions;
}
public static int gettPTask() {
setup();
return tPTask;
......
......@@ -3,6 +3,7 @@ package util;
import digit.DigitTaskFacade;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import main.Dm_task;
......@@ -30,6 +31,8 @@ public class Trial extends Thread {
private BlockingQueue<ProtoAction> actionQueue;
private EventListener theListener;
private final int maxIteration;
private AtomicInteger iterations;
/**
* The constructor
......@@ -41,6 +44,9 @@ public class Trial extends Thread {
this.theListener = new ResponseListener();
this.sFacade.addListener(theListener);
this.pFacade.addListener(theListener);
this.maxIteration = Configurator.getnTrials();
}
public void startTrial() {
......@@ -119,6 +125,27 @@ public class Trial extends Thread {
}
}
class SleepForDecisions extends ProtoAction {
public SleepForDecisions(ActionType type) {
super(type);
}
@Override
public void run() {
int tDecisions = Configurator.gettDecisions();
try {
Thread.sleep(tDecisions);
} catch (InterruptedException ex) {
Logger.getLogger(Dm_task.class.getName()).log(Level.SEVERE, null, ex);
}
pFacade.endDecision();
// own goal
theListener.run(EventType.DECISION_FINISHED);
}
}
/**
* Show digit, wait, hide digit, start decision-making
*/
......@@ -132,6 +159,11 @@ public class Trial extends Thread {
public void run() {
ActionType type = this.getType();
// check if there's yet another iteration
if (iterations.addAndGet(1) >= maxIteration) {
actionQueue.add(new QuitAction(ActionType.QUIT_TRIAL));
return;
}
// how ugly is this
if (type == ActionType.START_HWL_DIGIT
|| type == ActionType.START_LWL_DIGIT) {
......@@ -147,7 +179,7 @@ public class Trial extends Thread {
// start UDP to MouseTracker
pFacade.startAndWait(curState);
}
//TODO: add sleep to action queue
int tTask = Configurator.gettSTask();
try {
......@@ -155,22 +187,13 @@ public class Trial extends Thread {
} catch (InterruptedException ex) {
Logger.getLogger(Dm_task.class.getName()).log(Level.SEVERE, null, ex);
}
// immediately after
sFacade.endDigitShowing();
System.out.println("Digit should go away now");
// YOOOOOO the UDHHander constructor blocked!!!!!!!!!!
// TODO make that setup method public and give it an action type
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(Dm_task.class.getName()).log(Level.SEVERE, null, ex);
}
/* TODO: how to handle the deicion making task returned?
Wait for an event;
if timed out, event should be fired regardless, but where should the timer be???
Add a timer to the actionqueue?, if timed up, remove listener?
*/
actionQueue.add(new SleepForDecisions(ActionType.SLEEP_FOR_DECISIONS));
}
}
}
......@@ -10,3 +10,6 @@ tPause = 4000
tDecisions = 30000
nTrials = 10
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment