From 50d5e3c133fd46b8590df5c35f5ee538aee5d6d3 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Fri, 30 Aug 2024 16:19:44 -0600 Subject: [PATCH] Adding missing javadocs and little cleanup Signed-off-by: Alfredo Gutierrez --- .../block/simulator/BlockStreamSimulator.java | 24 ++++++++++++++++++- ...lockStreamSimulatorInjectionComponent.java | 13 ++++++++++ .../config/ConfigInjectionModule.java | 13 ++++++++++ .../simulator/config/ConfigProvider.java | 8 +++++++ .../simulator/config/ConfigProviderImpl.java | 12 ++++++---- .../config/data/BlockStreamConfig.java | 6 ++++- .../simulator/config/data/GrpcConfig.java | 6 +++++ .../config/types/GenerationMode.java | 3 +++ .../generator/BlockStreamManager.java | 6 +++++ .../generator/GeneratorInjectionModule.java | 7 ++++++ .../generator/MockBlockStreamManagerImpl.java | 7 ++++++ simulator/src/main/java/module-info.java | 5 ++-- 12 files changed, 101 insertions(+), 9 deletions(-) diff --git a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java index 05f433eab..d7dd10d81 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java +++ b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java @@ -24,6 +24,7 @@ import java.lang.System.Logger; import javax.inject.Inject; +/** The BlockStreamSimulator class defines the simulator for the block stream. */ public class BlockStreamSimulator { private static final Logger LOGGER = System.getLogger(BlockStreamSimulator.class.getName()); @@ -31,6 +32,12 @@ public class BlockStreamSimulator { BlockStreamManager blockStreamManager; boolean isRunning = false; + /** + * Creates a new BlockStreamSimulator instance. + * + * @param configuration the configuration to be used by the block stream simulator + * @param blockStreamManager the block stream manager to be used by the block stream simulator + */ @Inject public BlockStreamSimulator( @NonNull Configuration configuration, @NonNull BlockStreamManager blockStreamManager) { @@ -38,6 +45,11 @@ public BlockStreamSimulator( this.blockStreamManager = blockStreamManager; } + /** + * The main entry point for the block stream simulator. + * + * @param args the arguments to be passed to the block stream simulator + */ public static void main(String[] args) { LOGGER.log(Logger.Level.INFO, "Starting Block Stream Simulator"); @@ -51,6 +63,7 @@ public static void main(String[] args) { blockStreamSimulator.start(); } + /** Starts the block stream simulator. */ public void start() { // use blockStreamManager to get block stream @@ -60,9 +73,18 @@ public void start() { LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has started"); } + /** + * Returns whether the block stream simulator is running. + * + * @return true if the block stream simulator is running, false otherwise + */ public boolean isRunning() { return isRunning; } - public void stop() {} + /** Stops the block stream simulator. */ + public void stop() { + isRunning = false; + LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has stopped"); + } } diff --git a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorInjectionComponent.java b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorInjectionComponent.java index 80fef1ffd..ef8e4fe8f 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorInjectionComponent.java +++ b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulatorInjectionComponent.java @@ -23,6 +23,7 @@ import dagger.Component; import javax.inject.Singleton; +/** The component used to inject the block stream simulator into the application. */ @Singleton @Component( modules = { @@ -31,10 +32,22 @@ }) public interface BlockStreamSimulatorInjectionComponent { + /** + * Gets the block stream simulator. + * + * @return the block stream simulator + */ BlockStreamSimulator getBlockStreamSimulator(); + /** The factory used to create the block stream simulator injection component. */ @Component.Factory interface Factory { + /** + * Creates the block stream simulator injection component. + * + * @param configuration the configuration to be used by the block stream simulator + * @return the block stream simulator injection component + */ BlockStreamSimulatorInjectionComponent create(@BindsInstance Configuration configuration); } } diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java index 71091302a..ff2d4efb3 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigInjectionModule.java @@ -23,15 +23,28 @@ import dagger.Provides; import javax.inject.Singleton; +/** The module used to inject the configuration data into the application. */ @Module public interface ConfigInjectionModule { + /** + * Provides the block stream configuration. + * + * @param configuration the configuration to be used by the block stream + * @return the block stream configuration + */ @Singleton @Provides static BlockStreamConfig provideBlockStreamConfig(Configuration configuration) { return configuration.getConfigData(BlockStreamConfig.class); } + /** + * Provides the gRPC configuration. + * + * @param configuration the configuration to be used by the gRPC + * @return the gRPC configuration + */ @Singleton @Provides static GrpcConfig provideGrpcConfig(Configuration configuration) { diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProvider.java b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProvider.java index b7f471993..5a22e44c7 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProvider.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProvider.java @@ -19,7 +19,15 @@ import com.swirlds.config.api.Configuration; import edu.umd.cs.findbugs.annotations.NonNull; +/** The provider used to get the configuration for the simulator. */ public interface ConfigProvider { + + /** + * Gets the configuration for the simulator, specifies the mode of generation, the mode of + * simulator and every configurable detail. + * + * @return the configuration + */ @NonNull Configuration getConfiguration(); } diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java index 2577e58db..ddd89ce7a 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/ConfigProviderImpl.java @@ -25,20 +25,23 @@ import java.io.IOException; import java.nio.file.Path; +/** The ConfigProviderImpl class provides the implementation for the configuration provider. */ public class ConfigProviderImpl implements ConfigProvider { private static final System.Logger LOGGER = System.getLogger(ConfigProviderImpl.class.getName()); private final Configuration configuration; + /** Creates a new ConfigProviderImpl instance. */ public ConfigProviderImpl() { final var builder = createConfigurationBuilder(); - // addFileSources(builder, useGenesisSource); - // if (overrideValues != null) { - // overrideValues.forEach(builder::withValue); - // } configuration = builder.build(); } + /** + * Returns the configuration. + * + * @return the configuration + */ @NonNull @Override public Configuration getConfiguration() { @@ -54,6 +57,7 @@ private ConfigurationBuilder createConfigurationBuilder() { .autoDiscoverExtensions(); } catch (IOException e) { + LOGGER.log(System.Logger.Level.ERROR, "Failed to create configuration builder", e); throw new RuntimeException(e); } } diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java b/simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java index 89b4f049d..302c5a00f 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/data/BlockStreamConfig.java @@ -20,7 +20,11 @@ import com.swirlds.config.api.ConfigData; import com.swirlds.config.api.ConfigProperty; -// TODO add block dir option to generate from directory +/** + * The BlockStreamConfig class defines the configuration data for the block stream. + * + * @param generationMode the mode of generation for the block stream + */ @ConfigData("blockStream") public record BlockStreamConfig( @ConfigProperty(defaultValue = "SELF") GenerationMode generationMode) {} diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java b/simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java index cf8d4b3ef..abfbd4a61 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/data/GrpcConfig.java @@ -21,6 +21,12 @@ import com.swirlds.config.api.validation.annotation.Max; import com.swirlds.config.api.validation.annotation.Min; +/** + * The GrpcConfig class defines the configuration data for the gRPC client. + * + * @param serverAddress the address of the gRPC server + * @param port the port of the gRPC server + */ @ConfigData("grpc") public record GrpcConfig( @ConfigProperty(defaultValue = "localhost") @Min(0) @Max(65535) String serverAddress, diff --git a/simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java b/simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java index 9666b5274..5b637dcb1 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java +++ b/simulator/src/main/java/com/hedera/block/simulator/config/types/GenerationMode.java @@ -16,7 +16,10 @@ package com.hedera.block.simulator.config.types; +/** The GenerationMode enum defines the modes of generation for the block stream. */ public enum GenerationMode { + /** Reads Blocks from a Folder. */ FOLDER, + /** Generates Blocks from rules */ SELF } diff --git a/simulator/src/main/java/com/hedera/block/simulator/generator/BlockStreamManager.java b/simulator/src/main/java/com/hedera/block/simulator/generator/BlockStreamManager.java index 7818e58ff..74e744a4c 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/generator/BlockStreamManager.java +++ b/simulator/src/main/java/com/hedera/block/simulator/generator/BlockStreamManager.java @@ -18,7 +18,13 @@ import com.hedera.hapi.block.stream.Block; +/** this interface defines the contract for managing the block stream. */ public interface BlockStreamManager { + /** + * Gets the next block in the block stream. + * + * @return the next block in the block stream + */ Block getNextBlock(); } diff --git a/simulator/src/main/java/com/hedera/block/simulator/generator/GeneratorInjectionModule.java b/simulator/src/main/java/com/hedera/block/simulator/generator/GeneratorInjectionModule.java index 4764e9fdc..95266dfc8 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/generator/GeneratorInjectionModule.java +++ b/simulator/src/main/java/com/hedera/block/simulator/generator/GeneratorInjectionModule.java @@ -20,9 +20,16 @@ import dagger.Module; import javax.inject.Singleton; +/** The module used to inject the block stream manager. */ @Module public interface GeneratorInjectionModule { + /** + * Provides the block stream manager. + * + * @param blockStreamManager the block stream manager to be used + * @return the block stream manager + */ @Singleton @Binds BlockStreamManager bindBlockStreamManager(MockBlockStreamManagerImpl blockStreamManager); diff --git a/simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java b/simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java index 57ccd8afc..7f4ae0d3a 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java +++ b/simulator/src/main/java/com/hedera/block/simulator/generator/MockBlockStreamManagerImpl.java @@ -19,11 +19,18 @@ import com.hedera.hapi.block.stream.Block; import javax.inject.Inject; +/** A mock implementation of the BlockStreamManager interface. */ public class MockBlockStreamManagerImpl implements BlockStreamManager { + /** Constructs a new MockBlockStreamManagerImpl. */ @Inject public MockBlockStreamManagerImpl() {} + /** + * Gets the next block in the block stream. + * + * @return the next block in the block stream + */ @Override public Block getNextBlock() { return Block.newBuilder().build(); diff --git a/simulator/src/main/java/module-info.java b/simulator/src/main/java/module-info.java index ece9c9b46..9051122a0 100644 --- a/simulator/src/main/java/module-info.java +++ b/simulator/src/main/java/module-info.java @@ -1,9 +1,8 @@ import com.hedera.block.simulator.config.SimulatorConfigExtension; +/** Runtime module of the simulator. */ module com.hedera.block.simulator { - exports com.hedera.block.simulator.config.data to - com.swirlds.config.impl, - com.swirlds.config.extensions; + exports com.hedera.block.simulator.config.data; requires static com.github.spotbugs.annotations; requires static com.google.auto.service;