Skip to content

Commit

Permalink
Add Dagger, Configuration and PBJ Types
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 30, 2024
1 parent d3cdc18 commit 37a95e8
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 19 deletions.
1 change: 1 addition & 0 deletions simulator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ application {
}

mainModuleInfo {
annotationProcessor("dagger.compiler")
annotationProcessor("com.google.auto.service.processor")
runtimeOnly("com.swirlds.config.impl")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,46 @@

import com.hedera.block.simulator.config.ConfigProvider;
import com.hedera.block.simulator.config.ConfigProviderImpl;
import com.hedera.block.simulator.config.data.GrpcConfig;
import com.hedera.block.simulator.generator.BlockStreamManager;
import com.swirlds.config.api.Configuration;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.lang.System.Logger;
import javax.inject.Inject;

public class BlockStreamSimulator {
private static final Logger LOGGER =
System.getLogger(BlockStreamSimulator.class.getName());
private static final Logger LOGGER = System.getLogger(BlockStreamSimulator.class.getName());

public BlockStreamSimulator() {}
Configuration configuration;
BlockStreamManager blockStreamManager;

@Inject
public BlockStreamSimulator(
@NonNull Configuration configuration, @NonNull BlockStreamManager blockStreamManager) {
this.configuration = configuration;
this.blockStreamManager = blockStreamManager;
}

public static void main(String[] args) {
BlockStreamSimulator blockStreamSimulator = new BlockStreamSimulator();

LOGGER.log(Logger.Level.INFO, "Starting Block Stream Simulator");

ConfigProvider configProvider = new ConfigProviderImpl();
Configuration configuration = configProvider.getConfiguration();
BlockStreamSimulatorInjectionComponent DIComponent =
DaggerBlockStreamSimulatorInjectionComponent.factory().create(configuration);

BlockStreamSimulator blockStreamSimulator = DIComponent.getBlockStreamSimulator();
blockStreamSimulator.start();
}

public void start() {
ConfigProvider configProvider = new ConfigProviderImpl();
LOGGER.log(Logger.Level.INFO, "Starting Block Stream Simulator");
}

public void stop() {
// use blockStreamManager to get block stream

// use PublishStreamGrpcClient to stream it to the block-node.

LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has started");
}

public void stop() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.block.simulator;

import com.hedera.block.simulator.config.ConfigInjectionModule;
import com.hedera.block.simulator.generator.GeneratorInjectionModule;
import com.swirlds.config.api.Configuration;
import dagger.BindsInstance;
import dagger.Component;
import javax.inject.Singleton;

@Singleton
@Component(
modules = {
ConfigInjectionModule.class,
GeneratorInjectionModule.class,
})
public interface BlockStreamSimulatorInjectionComponent {

BlockStreamSimulator getBlockStreamSimulator();

@Component.Factory
interface Factory {
BlockStreamSimulatorInjectionComponent create(@BindsInstance Configuration configuration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.block.simulator.config;

import com.hedera.block.simulator.config.data.BlockStreamConfig;
import com.hedera.block.simulator.config.data.GrpcConfig;
import com.swirlds.config.api.Configuration;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;

@Module
public interface ConfigInjectionModule {

@Singleton
@Provides
static BlockStreamConfig provideBlockStreamConfig(Configuration configuration) {
return configuration.getConfigData(BlockStreamConfig.class);
}

@Singleton
@Provides
static GrpcConfig provideGrpcConfig(Configuration configuration) {
return configuration.getConfigData(GrpcConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

import com.swirlds.config.api.Configuration;
import com.swirlds.config.api.ConfigurationBuilder;
import com.swirlds.config.extensions.sources.ClasspathFileConfigSource;
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource;
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.nio.file.Path;

public class ConfigProviderImpl implements ConfigProvider {
private static final System.Logger LOGGER =
Expand All @@ -43,14 +46,15 @@ public Configuration getConfiguration() {
}

private ConfigurationBuilder createConfigurationBuilder() {
final ConfigurationBuilder builder = ConfigurationBuilder.create();
try {
return ConfigurationBuilder.create()
.withSource(SystemEnvironmentConfigSource.getInstance())
.withSource(SystemPropertiesConfigSource.getInstance())
.withSource(new ClasspathFileConfigSource(Path.of("app.properties")))
.autoDiscoverExtensions();

builder
.withSource(SystemEnvironmentConfigSource.getInstance())
.withSource(SystemPropertiesConfigSource.getInstance())
// .withSource(new
// ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES)))
.autoDiscoverExtensions();
return builder;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@

package com.hedera.block.simulator.generator;

import com.hedera.hapi.block.stream.Block;

public interface BlockStreamManager {

Block getNextBlock();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.block.simulator.generator;

import dagger.Binds;
import dagger.Module;
import javax.inject.Singleton;

@Module
public interface GeneratorInjectionModule {

@Singleton
@Binds
BlockStreamManager bindBlockStreamManager(MockBlockStreamManagerImpl blockStreamManager);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.block.simulator.generator;

import com.hedera.hapi.block.stream.Block;
import javax.inject.Inject;

public class MockBlockStreamManagerImpl implements BlockStreamManager {

@Inject
public MockBlockStreamManagerImpl() {}

@Override
public Block getNextBlock() {
return Block.newBuilder().build();
}
}
8 changes: 6 additions & 2 deletions simulator/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

module com.hedera.block.simulator {
exports com.hedera.block.simulator.config.data to
com.swirlds.config.impl, com.swirlds.config.extensions;
com.swirlds.config.impl,
com.swirlds.config.extensions;

requires static com.github.spotbugs.annotations;
requires static com.google.auto.service;
requires com.hedera.block.stream;
// requires com.hedera.pbj.runtime; // leaving it here since it will be needed soon.
requires com.swirlds.config.api;
requires com.swirlds.config.extensions;
requires dagger;
requires javax.inject;

provides com.swirlds.config.api.ConfigurationExtension with
SimulatorConfigExtension;

}
1 change: 1 addition & 0 deletions simulator/src/main/resources/app.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blockStream.folderRootPath=/Users/user/Projects/hedera-block-node/simulator/src/main/resources/block-0.0.3/

0 comments on commit 37a95e8

Please sign in to comment.