Commit 0a3f7cd5 authored by Sören Henning's avatar Sören Henning

removed debuggings and handle termination

parent d1b9147e
package watchme;
import java.time.Duration;
import java.util.function.LongUnaryOperator;
/**
......@@ -11,14 +12,15 @@ public class CallConfiguration {
private Method method;
private LongUnaryOperator valueFunction;
private LongUnaryOperator timeFunction;
private Duration executionDuration;
private boolean multiThreaded;
public CallConfiguration(Method method, LongUnaryOperator valueFunction, LongUnaryOperator timeFunction, boolean multiThreaded) {
public CallConfiguration(Method method, LongUnaryOperator valueFunction, LongUnaryOperator timeFunction, Duration executionDuration, boolean multiThreaded) {
super();
this.method = method;
this.valueFunction = valueFunction;
this.timeFunction = timeFunction;
this.executionDuration = executionDuration;
this.multiThreaded = multiThreaded;
}
......@@ -46,6 +48,14 @@ public class CallConfiguration {
this.timeFunction = timeFunction;
}
public Duration getExecutionDuration() {
return executionDuration;
}
public void setExecutionDuration(Duration executionDuration) {
this.executionDuration = executionDuration;
}
public boolean isMultiThreaded() {
return multiThreaded;
}
......
package watchme;
import java.util.concurrent.Executor;
import java.time.Instant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
......@@ -10,8 +11,10 @@ import java.util.concurrent.Executors;
public class Caller implements Runnable {
private final Method method;
private final Executor executor;
private final ExecutorService executor;
private final SleepService sleepService;
private final Instant endTime;
public Caller(final CallConfiguration configuration) {
this.sleepService = new SleepService(configuration.getTimeFunction());
......@@ -22,13 +25,15 @@ public class Caller implements Runnable {
}
this.method = configuration.getMethod();
this.method.setSleepService(new SleepService(configuration.getValueFunction()));
this.endTime = Instant.now().plus(configuration.getExecutionDuration());
}
public void run() {
while(true) {
while(Instant.now().isBefore(this.endTime)) {
this.executor.execute(this.method);
this.sleepService.sleep();
}
this.executor.shutdown();
}
}
......@@ -13,8 +13,6 @@ public class FooMethod extends Method {
public void foo() {
this.sleepService.sleep();
System.out.println("Hello from foo()!");
//System.out.println(Instant.now() + ": " + "Hello from foo()!");
}
}
......@@ -4,35 +4,44 @@ import watchme.function.FunctionSum;
import watchme.function.Noise;
import watchme.function.StaticAnomaly;
import java.time.Duration;
public enum Scenario {
CONSTANT_WITH_ANOMALY(new CallConfiguration(new FooMethod(),
new FunctionSum(x -> 100, new Noise(10, 12161608), new StaticAnomaly(100, 3_000)),
new FunctionSum(x -> 100, new Noise(50, 12101608)),
new FunctionSum(x -> 100),
Duration.ofSeconds(5),
true)),
LINEAR_WITH_ANOMALY(new CallConfiguration(new FooMethod(),
new FunctionSum(x -> (long) ((500.0/4_000) * x), new Noise(10, 908170816), new StaticAnomaly(100, 3_000)),
new FunctionSum(x -> 100, new Noise(50, 9211708)),
Duration.ofSeconds(5),
true)),
SINUS_WITH_ANOMALY(new CallConfiguration(new FooMethod(),
new FunctionSum(x -> (long) ((100 * Math.sin(((2*Math.PI) / 10_000) * x)) + 200), new Noise(10, 9261708), new StaticAnomaly(-100, 3_000)),
new FunctionSum(x -> 100, new Noise(50, 9301708)),
Duration.ofSeconds(50),
true)),
EXPONENTIAL(new CallConfiguration(new FooMethod(),
new FunctionSum(x -> (long) ((Math.exp(x / (4_000/8)) - 1) / (3_000 / 400)) + 100, new Noise(10, 9311708)),
new FunctionSum(x -> 100, new Noise(50, 9321708)),
Duration.ofSeconds(5),
true)),
CONSTANT_SLOW(new CallConfiguration(new FooMethod(),
x -> 100,
x -> 2000,
Duration.ofSeconds(60),
true)),
UNAMED(new CallConfiguration(new FooMethod(),
x -> (long) (100 * Math.sin((double) x / (10*1000)) + 200),
x -> x,
Duration.ofSeconds(5),
true)),
INCREASING_SPEED(new CallConfiguration(new FooMethod(),
x -> 10,
x -> (long) (x * ((double) -1_000 / 10_000)) + 1_000,
Duration.ofSeconds(60),
true));
private CallConfiguration configuration;
......
......@@ -19,11 +19,8 @@ public class SleepService {
}
public void sleep() {
// Time in milliseconds since instantiation
long timestamp = Duration.between(instantiationTime, Instant.now()).toMillis();
// Time to sleep in milliseconds
long sleepTime = Math.max(this.function.applyAsLong(timestamp), 0);
//System.out.println(" -> sleep:" + sleepTime);
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
......
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