Skip to content
Snippets Groups Projects
Commit 254bfe4b authored by Simon Ehrenstein's avatar Simon Ehrenstein
Browse files

Cleanup code

parent 28e9636b
No related branches found
No related tags found
1 merge request!6Add Distributed Workload Generator
Showing
with 355 additions and 244 deletions
......@@ -32,7 +32,7 @@ cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_modifiers=false
cleanup.remove_redundant_semicolons=false
cleanup.remove_redundant_semicolons=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
......@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style
formatter_settings_version=15
formatter_settings_version=16
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99
......
......@@ -32,7 +32,7 @@ cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_modifiers=false
cleanup.remove_redundant_semicolons=false
cleanup.remove_redundant_semicolons=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
......@@ -61,7 +61,7 @@ cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style
formatter_settings_version=15
formatter_settings_version=16
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=;
org.eclipse.jdt.ui.ondemandthreshold=99
......
......@@ -15,16 +15,21 @@ public class Main {
final KafkaWorkloadGenerator generator =
KafkaWorkloadGeneratorBuilder.builder()
.setBeforeHook(() -> {
.setBeforeAction(() -> {
System.out.println("Before Hook");
})
.setKeySpace(new KeySpace(5))
.setPeriod(new Period(1000, TimeUnit.MILLISECONDS))
.setDuration(new Duration(60, TimeUnit.SECONDS))
.setGeneratorFunction(
key -> new OutputMessage(key, new ActivePowerRecord(key, 0L, 100d)))
key -> new OutputMessage<>(key,
new ActivePowerRecord(key, 0L, 100d)))
.build();
// dwhedhwedherbfherf ferufer e u uebvhebzvbjkr fjkebhr erfberf rt gtr grt gtr
// gebuwbfuzerfuzerzgfer fe rf er fe rferhfveurfgerzfgzuerf erf erf ethvrif
generator.start();
}
......
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true
cleanup.always_use_this_for_non_static_method_access=true
cleanup.convert_functional_interfaces=false
cleanup.convert_to_enhanced_for_loop=true
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_modifiers=false
cleanup.remove_redundant_semicolons=false
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=false
cleanup_profile=_CAU-SE-Style
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
......
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true
cleanup.always_use_this_for_non_static_method_access=true
cleanup.convert_functional_interfaces=false
cleanup.convert_to_enhanced_for_loop=true
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_modifiers=false
cleanup.remove_redundant_semicolons=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=false
cleanup_profile=_CAU-SE-Style
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_CAU-SE-Style
formatter_settings_version=16
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=java;javax;org;com;
org.eclipse.jdt.ui.ondemandthreshold=99
org.eclipse.jdt.ui.staticondemandthreshold=99
org.eclipse.jdt.ui.text.custom_code_templates=
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=true
sp_cleanup.always_use_this_for_non_static_method_access=true
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=true
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=true
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_modifiers=true
sp_cleanup.remove_redundant_semicolons=true
sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=true
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=true
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=false
configFilePath=../config/checkstyle.xml
customModulesJarPaths=
eclipse.preferences.version=1
enabled=true
customRulesJars=
eclipse.preferences.version=1
enabled=true
ruleSetFilePath=../config/pmd.xml
package common;
public interface IWorkloadGenerator {
public void start();
public void stop();
}
package common;
import common.dimensions.Duration;
import common.dimensions.KeySpace;
import common.dimensions.Period;
import common.functions.BeforeAction;
import common.functions.MessageGenerator;
import communication.kafka.KafkaRecordSender;
import titan.ccp.models.records.ActivePowerRecord;
public class KafkaWorkloadGenerator extends WorkloadGenerator {
private final KafkaRecordSender<ActivePowerRecord> recordSender;
public KafkaWorkloadGenerator(
final KeySpace keySpace,
final Period period,
final Duration duration,
final BeforeAction beforeHook,
final MessageGenerator generatorFunction,
final KafkaRecordSender<ActivePowerRecord> recordSender
) {
super(keySpace, period, duration, beforeHook, generatorFunction, outputMessage -> {
//recordSender.write(outputMessage.getValue()); removed for dev
System.out.println(outputMessage.getKey());
});
this.recordSender = recordSender;
}
@Override
public void stop() {
System.out.println("subclass terminated");
// this.recordSender.terminate();
super.stop();
}
}
package common;
import java.util.Objects;
import common.dimensions.Duration;
import common.dimensions.KeySpace;
import common.dimensions.Period;
import common.functions.BeforeAction;
import common.functions.MessageGenerator;
import communication.kafka.KafkaRecordSender;
import titan.ccp.models.records.ActivePowerRecord;
public class KafkaWorkloadGeneratorBuilder {
private KeySpace keySpace;
private Period period;
private Duration duration;
private BeforeAction beforeAction;
private MessageGenerator generatorFunction;
private KafkaRecordSender<ActivePowerRecord> kafkaRecordSender;
private KafkaWorkloadGeneratorBuilder() {
}
public static KafkaWorkloadGeneratorBuilder builder() {
return new KafkaWorkloadGeneratorBuilder();
}
public KafkaWorkloadGeneratorBuilder setBeforeHook(final BeforeAction beforeAction) {
this.beforeAction = beforeAction;
return this;
}
public KafkaWorkloadGeneratorBuilder setKeySpace(final KeySpace keySpace) {
this.keySpace = keySpace;
return this;
}
public KafkaWorkloadGeneratorBuilder setPeriod(final Period period) {
this.period = period;
return this;
}
public KafkaWorkloadGeneratorBuilder setDuration(final Duration duration) {
this.duration = duration;
return this;
}
public KafkaWorkloadGeneratorBuilder setGeneratorFunction(final MessageGenerator generatorFunction) {
this.generatorFunction = generatorFunction;
return this;
}
public KafkaWorkloadGeneratorBuilder setKafkaRecordSender(final KafkaRecordSender<ActivePowerRecord> kafkaRecordSender) {
this.kafkaRecordSender = kafkaRecordSender;
return this;
}
public KafkaWorkloadGenerator build() {
Objects.requireNonNull(this.keySpace, "Please specify the key space.");
Objects.requireNonNull(this.period, "Please specify the period.");
Objects.requireNonNull(this.duration, "Please specify the duration.");
final BeforeAction beforeAction = Objects.requireNonNullElse(this.beforeAction, () -> {});
Objects.requireNonNull(this.generatorFunction, "Please specify the generator function.");
//Objects.requireNonNull(this.kafkaRecordSender, "Please specify the kafka record sender.");
return new KafkaWorkloadGenerator(this.keySpace, this.period, this.duration, beforeAction, this.generatorFunction, this.kafkaRecordSender);
}
}
package common;
import common.dimensions.KeySpace;
public class WorkloadDeclaration {
private final KeySpace keySpace;
private final int numberOfWorkers;
public WorkloadDeclaration(final KeySpace keySpace, final int numberOfWorkers) {
this.keySpace = keySpace;
this.numberOfWorkers = numberOfWorkers;
}
public KeySpace getKeySpace() {
return this.keySpace;
}
public int getNumberOfWorkers() {
return this.numberOfWorkers;
}
/*
* Replace by json format serialization/deserialization
*/
@Override
public String toString() {
return this.getKeySpace().getPrefix() + ";" + this.getKeySpace().getMin() + ";" + this.getKeySpace().getMax() + ";" + this.getNumberOfWorkers();
}
public static WorkloadDeclaration fromString(String declarationString) {
final String[] deserialized = declarationString.split(";");
return new WorkloadDeclaration(new KeySpace(deserialized[0], Integer.valueOf(deserialized[1]), Integer.valueOf(deserialized[2])), Integer.valueOf(deserialized[3]));
}
}
package common.dimensions;
/*
* Base class for workload dimensions.
*/
public abstract class Dimension {
}
package common.dimensions;
import java.util.concurrent.TimeUnit;
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of the duration for the {@link WorkloadGenerator}.
*/
public class Duration extends Dimension {
public class Duration {
private final int duration;
private final TimeUnit timeUnit;
/**
* Define a new duration.
*
* @param duration the duration
* @param timeUnit the time unit that applies to the specified {@code duration}
*/
public Duration(final int duration, final TimeUnit timeUnit) {
super();
this.duration = duration;
......@@ -13,11 +24,11 @@ public class Duration {
}
public int getDuration() {
return duration;
return this.duration;
}
public TimeUnit getTimeUnit() {
return timeUnit;
return this.timeUnit;
}
}
package common.dimensions;
public class KeySpace {
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of the Keys that should be used by the
* {@link WorkloadGenerator}.
*/
public class KeySpace extends Dimension {
private final String prefix;
private final int min;
private final int max;
/**
* Create a new key space. All keys will have the prefix {@code prefix}. The remaining part of
* each key will be determined by a number of the interval ({@code min}, {@code max}-1).
*
* @param prefix the prefix to use for all keys
* @param min the lower bound (inclusive) to start counting from
* @param max the upper bound (exclusive) to count to
*/
public KeySpace(final String prefix, final int min, final int max) {
super();
if (prefix == null || prefix.contains(";")) {
throw new IllegalArgumentException(
"The prefix must not be null and must not contain the ';' character.");
}
this.prefix = prefix;
this.min = min;
this.max = max;
}
public KeySpace(final String prefix, final int numberOfKeys) {
this(prefix, 0, numberOfKeys-1);
this(prefix, 0, numberOfKeys - 1);
}
public KeySpace(final int numberOfKeys) {
this("sensor_", 0, numberOfKeys-1);
this("sensor_", 0, numberOfKeys - 1);
}
public String getPrefix() {
return prefix;
return this.prefix;
}
public int getMin() {
return min;
return this.min;
}
public int getMax() {
return max;
return this.max;
}
}
package common.dimensions;
import java.util.concurrent.TimeUnit;
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of period to use for the {@link WorkloadGenerator}.
*/
public class Period extends Dimension {
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;
......@@ -14,11 +24,11 @@ public class Period {
}
public int getDuration() {
return period;
return this.period;
}
public TimeUnit getTimeUnit() {
return timeUnit;
return this.timeUnit;
}
}
package common.dimensions.copy;
/*
* Base class for workload dimensions.
*/
public abstract class Dimension {
}
package common.dimensions.copy;
import java.util.concurrent.TimeUnit;
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of the duration for the {@link WorkloadGenerator}.
*/
public class Duration extends Dimension {
private final int duration;
private final TimeUnit timeUnit;
/**
* Define a new duration.
*
* @param duration the duration
* @param timeUnit the time unit that applies to the specified {@code duration}
*/
public Duration(final int duration, final TimeUnit timeUnit) {
super();
this.duration = duration;
this.timeUnit = timeUnit;
}
public int getDuration() {
return this.duration;
}
public TimeUnit getTimeUnit() {
return this.timeUnit;
}
}
package common.dimensions.copy;
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of the Keys that should be used by the
* {@link WorkloadGenerator}.
*/
public class KeySpace extends Dimension {
private final String prefix;
private final int min;
private final int max;
/**
* Create a new key space. All keys will have the prefix {@code prefix}. The remaining part of
* each key will be determined by a number of the interval ({@code min}, {@code max}-1).
*
* @param prefix the prefix to use for all keys
* @param min the lower bound (inclusive) to start counting from
* @param max the upper bound (exclusive) to count to
*/
public KeySpace(final String prefix, final int min, final int max) {
if (prefix == null || prefix.contains(";")) {
throw new IllegalArgumentException(
"The prefix must not be null and must not contain the ';' character.");
}
this.prefix = prefix;
this.min = min;
this.max = max;
}
public KeySpace(final String prefix, final int numberOfKeys) {
this(prefix, 0, numberOfKeys - 1);
}
public KeySpace(final int numberOfKeys) {
this("sensor_", 0, numberOfKeys - 1);
}
public String getPrefix() {
return this.prefix;
}
public int getMin() {
return this.min;
}
public int getMax() {
return this.max;
}
}
package common.dimensions.copy;
import java.util.concurrent.TimeUnit;
import common.generators.WorkloadGenerator;
/**
* Wrapper class for the definition of period to use for the {@link WorkloadGenerator}.
*/
public class Period extends Dimension {
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 getDuration() {
return this.period;
}
public TimeUnit getTimeUnit() {
return this.timeUnit;
}
}
package common.dimensions.copy2;
/*
* Base class for workload dimensions.
*/
public abstract class Dimension {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment