Skip to content

Commit

Permalink
Adding missing javadocs and little cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Sep 3, 2024
1 parent 9a96435 commit 5384ffe
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@
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());

Configuration configuration;
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) {
this.configuration = configuration;
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");
Expand All @@ -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
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions simulator/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 5384ffe

Please sign in to comment.