package nl.ru.ai.projects.parrot.tools;
import nl.ru.ai.projects.parrot.dronecontrol.SensoryDataInterface;
import nl.ru.ai.projects.parrot.dronecontrol.simulator.Simulator;
private static Sleeper instance = null;
private SensoryDataInterface sensoryDataInterface = null;
private Sleeper(SensoryDataInterface sensoryDataInterface) {
this.sensoryDataInterface = sensoryDataInterface;
}
public static synchronized Sleeper
getInstance(SensoryDataInterface sensoryDataInterface) {
if ( instance == null )
instance = new Sleeper(sensoryDataInterface);
return instance;
}
public void sleep(
long millis)
throws InterruptedException {
if (sensoryDataInterface != null) {
sensoryDataInterface.droneSleep(millis);
} else {
long start = Simulator.getInstance().getCurrentTimeStamp();
while ( Simulator.getInstance().getCurrentTimeStamp()-start < millis );
}
}
}