diff --git a/uc1-workload-generator/src/main/java/theodolite/uc1/workloadgenerator/LoadGenerator.java b/uc1-workload-generator/src/main/java/theodolite/uc1/workloadgenerator/LoadGenerator.java index d9bbbe47d309912a3d2eb38489b0789fd625888d..e352d8d59dc5470913a4e8300c49f62b613d7cd7 100644 --- a/uc1-workload-generator/src/main/java/theodolite/uc1/workloadgenerator/LoadGenerator.java +++ b/uc1-workload-generator/src/main/java/theodolite/uc1/workloadgenerator/LoadGenerator.java @@ -5,13 +5,11 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Objects; import java.util.Properties; -import java.util.concurrent.TimeUnit; import org.apache.kafka.clients.producer.ProducerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGenerator; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGeneratorBuilder; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -69,7 +67,7 @@ public final class LoadGenerator { KafkaWorkloadGeneratorBuilder.<ActivePowerRecord>builder() .setKeySpace(new KeySpace("s_", numSensors)) .setThreads(threads) - .setPeriod(new Period(periodMs, TimeUnit.MILLISECONDS)) + .setPeriod(Duration.of(periodMs, ChronoUnit.MILLIS)) .setDuration(Duration.of(MAX_DURATION_IN_DAYS, ChronoUnit.DAYS)) .setGeneratorFunction( sensor -> new ActivePowerRecord(sensor, System.currentTimeMillis(), value)) diff --git a/uc2-workload-generator/src/main/java/theodolite/uc2/workloadgenerator/LoadGenerator.java b/uc2-workload-generator/src/main/java/theodolite/uc2/workloadgenerator/LoadGenerator.java index 60f20518f6257e85bfe4bf6edd0e68224da0eb5f..cdcc01f217fc4c45d939e93f343f1e2e1fd22d3c 100644 --- a/uc2-workload-generator/src/main/java/theodolite/uc2/workloadgenerator/LoadGenerator.java +++ b/uc2-workload-generator/src/main/java/theodolite/uc2/workloadgenerator/LoadGenerator.java @@ -5,13 +5,11 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Objects; import java.util.Properties; -import java.util.concurrent.TimeUnit; import org.apache.kafka.clients.producer.ProducerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGenerator; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGeneratorBuilder; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -73,7 +71,7 @@ public class LoadGenerator { KafkaWorkloadGeneratorBuilder.<ActivePowerRecord>builder() .setKeySpace(new KeySpace("s_", numSensors)) .setThreads(threads) - .setPeriod(new Period(periodMs, TimeUnit.MILLISECONDS)) + .setPeriod(Duration.of(periodMs, ChronoUnit.MILLIS)) .setDuration(Duration.of(MAX_DURATION_IN_DAYS, ChronoUnit.DAYS)) .setBeforeAction(() -> { if (sendRegistry) { diff --git a/uc3-workload-generator/src/main/java/theodolite/uc3/workloadgenerator/LoadGenerator.java b/uc3-workload-generator/src/main/java/theodolite/uc3/workloadgenerator/LoadGenerator.java index 6e8e2d897895989c7eb88ebe970a59849911a679..3a64e55db1606b924e173f223af33938093b4262 100644 --- a/uc3-workload-generator/src/main/java/theodolite/uc3/workloadgenerator/LoadGenerator.java +++ b/uc3-workload-generator/src/main/java/theodolite/uc3/workloadgenerator/LoadGenerator.java @@ -5,13 +5,11 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Objects; import java.util.Properties; -import java.util.concurrent.TimeUnit; import org.apache.kafka.clients.producer.ProducerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGenerator; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGeneratorBuilder; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -61,7 +59,7 @@ public class LoadGenerator { KafkaWorkloadGeneratorBuilder.<ActivePowerRecord>builder() .setKeySpace(new KeySpace("s_", numSensors)) .setThreads(threads) - .setPeriod(new Period(periodMs, TimeUnit.MILLISECONDS)) + .setPeriod(Duration.of(periodMs, ChronoUnit.MILLIS)) .setDuration(Duration.of(MAX_DURATION_IN_DAYS, ChronoUnit.DAYS)) .setGeneratorFunction( sensor -> new ActivePowerRecord(sensor, System.currentTimeMillis(), value)) diff --git a/uc4-workload-generator/src/main/java/theodolite/uc4/workloadgenerator/LoadGenerator.java b/uc4-workload-generator/src/main/java/theodolite/uc4/workloadgenerator/LoadGenerator.java index 89a3db55aca7305ed7677f11950dcc056814c5b3..3ad36e21a543851833db234eb47e7b699e521a22 100644 --- a/uc4-workload-generator/src/main/java/theodolite/uc4/workloadgenerator/LoadGenerator.java +++ b/uc4-workload-generator/src/main/java/theodolite/uc4/workloadgenerator/LoadGenerator.java @@ -5,13 +5,11 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Objects; import java.util.Properties; -import java.util.concurrent.TimeUnit; import org.apache.kafka.clients.producer.ProducerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGenerator; import theodolite.commons.workloadgeneration.generators.KafkaWorkloadGeneratorBuilder; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -61,7 +59,7 @@ public class LoadGenerator { KafkaWorkloadGeneratorBuilder.<ActivePowerRecord>builder() .setKeySpace(new KeySpace("s_", numSensors)) .setThreads(threads) - .setPeriod(new Period(periodMs, TimeUnit.MILLISECONDS)) + .setPeriod(Duration.of(periodMs, ChronoUnit.MILLIS)) .setDuration(Duration.of(MAX_DURATION_IN_DAYS, ChronoUnit.DAYS)) .setGeneratorFunction( sensor -> new ActivePowerRecord(sensor, System.currentTimeMillis(), value)) diff --git a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/dimensions/Period.java b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/dimensions/Period.java deleted file mode 100644 index 62d3a216c5d0eeee1f86624db84bbcf2dd4ee80c..0000000000000000000000000000000000000000 --- a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/dimensions/Period.java +++ /dev/null @@ -1,34 +0,0 @@ -package theodolite.commons.workloadgeneration.dimensions; - -import java.util.concurrent.TimeUnit; -import theodolite.commons.workloadgeneration.generators.AbstractWorkloadGenerator; - -/** - * Wrapper class for the definition of period to use for the {@link AbstractWorkloadGenerator}. - */ -public class Period { - - private final int period; - private final TimeUnit timeUnit; - - /** - * Define a new period. - * - * @param period the period - * @param timeUnit the time unit that applies to the specified {@code period} - */ - public Period(final int period, final TimeUnit timeUnit) { - super(); - this.period = period; - this.timeUnit = timeUnit; - } - - public int getPeriod() { - return this.period; - } - - public TimeUnit getTimeUnit() { - return this.timeUnit; - } - -} diff --git a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/AbstractWorkloadGenerator.java b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/AbstractWorkloadGenerator.java index a53717dc2f1e708ccc589c119caab91bc61a81be..244fdc55572f55227b3bc18492eedf7b1e1b51e2 100644 --- a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/AbstractWorkloadGenerator.java +++ b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/AbstractWorkloadGenerator.java @@ -14,7 +14,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import theodolite.commons.workloadgeneration.communication.zookeeper.WorkloadDistributor; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.functions.BeforeAction; import theodolite.commons.workloadgeneration.functions.MessageGenerator; import theodolite.commons.workloadgeneration.functions.Transport; @@ -34,7 +33,7 @@ public abstract class AbstractWorkloadGenerator<T extends IMonitoringRecord> private final int threads; - private final Period period; + private final Duration period; private final Duration duration; @@ -68,7 +67,7 @@ public abstract class AbstractWorkloadGenerator<T extends IMonitoringRecord> final ZooKeeper zooKeeper, final KeySpace keySpace, final int threads, - final Period period, + final Duration period, final Duration duration, final BeforeAction beforeAction, final MessageGenerator<T> generatorFunction, @@ -97,7 +96,7 @@ public abstract class AbstractWorkloadGenerator<T extends IMonitoringRecord> this.executor = Executors.newScheduledThreadPool(threads); final Random random = new Random(); - final int periodMs = period.getPeriod(); + final int periodMs = period.getNano() / 1_000_000; final BiConsumer<WorkloadDefinition, Worker> workerAction = (declaration, worker) -> { @@ -110,7 +109,7 @@ public abstract class AbstractWorkloadGenerator<T extends IMonitoringRecord> final T message = entity.generateMessage(); final long initialDelay = random.nextInt(periodMs); this.executor.scheduleAtFixedRate(() -> this.transport.transport(message), initialDelay, - periodMs, period.getTimeUnit()); + periodMs, TimeUnit.MILLISECONDS); }); diff --git a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGenerator.java b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGenerator.java index 3e16755746b43921d79d5092047bb996a19564c5..010ce837a1b72155b52e96350dbdd65354f365fb 100644 --- a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGenerator.java +++ b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGenerator.java @@ -4,7 +4,6 @@ import java.time.Duration; import kieker.common.record.IMonitoringRecord; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.functions.BeforeAction; import theodolite.commons.workloadgeneration.functions.MessageGenerator; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -36,7 +35,7 @@ public class KafkaWorkloadGenerator<T extends IMonitoringRecord> final ZooKeeper zooKeeper, final KeySpace keySpace, final int threads, - final Period period, + final Duration period, final Duration duration, final BeforeAction beforeAction, final MessageGenerator<T> generatorFunction, diff --git a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGeneratorBuilder.java b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGeneratorBuilder.java index 1cd71b5bb0f38cd14eb5f147daa5c7dae6af4732..1609808a3178fb6607c95c924d35a6cc4d8ab153 100644 --- a/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGeneratorBuilder.java +++ b/workload-generator-commons/src/main/java/theodolite/commons/workloadgeneration/generators/KafkaWorkloadGeneratorBuilder.java @@ -5,7 +5,6 @@ import java.util.Objects; import kieker.common.record.IMonitoringRecord; import theodolite.commons.workloadgeneration.communication.kafka.KafkaRecordSender; import theodolite.commons.workloadgeneration.dimensions.KeySpace; -import theodolite.commons.workloadgeneration.dimensions.Period; import theodolite.commons.workloadgeneration.functions.BeforeAction; import theodolite.commons.workloadgeneration.functions.MessageGenerator; import theodolite.commons.workloadgeneration.misc.ZooKeeper; @@ -18,7 +17,7 @@ public class KafkaWorkloadGeneratorBuilder<T extends IMonitoringRecord> { private int threads; - private Period period; + private Duration period; private Duration duration; @@ -91,7 +90,7 @@ public class KafkaWorkloadGeneratorBuilder<T extends IMonitoringRecord> { * @param period the {@link Period} * @return the builder. */ - public KafkaWorkloadGeneratorBuilder<T> setPeriod(final Period period) { + public KafkaWorkloadGeneratorBuilder<T> setPeriod(final Duration period) { this.period = period; return this; }