1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-11-17 16:09:32 -08:00

Add a setting to the timeout delay.

This commit is contained in:
Danila Fedorin 2017-08-07 09:22:11 -07:00
parent 40bdbd1948
commit b8f8c4486a
2 changed files with 30 additions and 2 deletions

View File

@ -30,6 +30,10 @@ public class Configuration {
*/
private static final TomlWriter TOML_WRITER = new TomlWriter();
/**
* The computation delay for which the thread can run without interruption.
*/
private double computationDelay = 0;
/**
* The implementation of the number that should be used.
*/
@ -51,10 +55,12 @@ public class Configuration {
/**
* Creates a new configuration with the given values.
*
* @param computationDelay the delay before the computation gets killed.
* @param numberImplementation the number implementation, like "naive" or "precise"
* @param disabledPlugins the list of disabled plugins.
*/
public Configuration(String numberImplementation, String[] disabledPlugins) {
public Configuration(double computationDelay, String numberImplementation, String[] disabledPlugins) {
this.computationDelay = computationDelay;
this.numberImplementation = numberImplementation;
this.disabledPlugins.addAll(Arrays.asList(disabledPlugins));
}
@ -75,6 +81,7 @@ public class Configuration {
* @param otherConfiguration the configuration to copy from.
*/
public void copyFrom(Configuration otherConfiguration) {
this.computationDelay = otherConfiguration.computationDelay;
this.numberImplementation = otherConfiguration.numberImplementation;
this.disabledPlugins.addAll(otherConfiguration.disabledPlugins);
}
@ -130,4 +137,23 @@ public class Configuration {
return disabledPlugins;
}
/**
* Gets the computation delay specified in the configuration.
*
* @return the computaton delay.
*/
public double getComputationDelay() {
return computationDelay;
}
/**
* Sets the computation delay.
*
* @param computationDelay the new computation delay.
*/
public void setComputationDelay(double computationDelay) {
this.computationDelay = computationDelay;
}
}

View File

@ -129,7 +129,9 @@ public class AbacusController implements PluginListener {
*/
private final Runnable TIMER_RUNNABLE = () -> {
try {
Thread.sleep(30 * 1000);
Configuration abacusConfig = abacus.getConfiguration();
if(abacusConfig.getComputationDelay() != 0)
Thread.sleep((long) (abacusConfig.getComputationDelay() * 1000));
} catch (InterruptedException e) {
e.printStackTrace();
}