diff --git a/buildSrc/src/main/kotlin/com.hedera.block.jpms-modules.gradle.kts b/buildSrc/src/main/kotlin/com.hedera.block.jpms-modules.gradle.kts index 568b13afc..964d27a85 100644 --- a/buildSrc/src/main/kotlin/com.hedera.block.jpms-modules.gradle.kts +++ b/buildSrc/src/main/kotlin/com.hedera.block.jpms-modules.gradle.kts @@ -49,6 +49,13 @@ jvmDependencyConflicts.patch { module("io.grpc:grpc-stub") { annotationLibraries.forEach { removeDependency(it) } } module("io.grpc:grpc-testing") { annotationLibraries.forEach { removeDependency(it) } } module("io.grpc:grpc-util") { annotationLibraries.forEach { removeDependency(it) } } + module("com.google.dagger:dagger-compiler") { + annotationLibraries.forEach { removeDependency(it) } + } + module("com.google.dagger:dagger-producers") { + annotationLibraries.forEach { removeDependency(it) } + } + module("com.google.dagger:dagger-spi") { annotationLibraries.forEach { removeDependency(it) } } module("com.google.guava:guava") { (annotationLibraries - "com.google.code.findbugs:jsr305" - @@ -63,6 +70,9 @@ jvmDependencyConflicts.patch { removeDependency("io.prometheus:simpleclient_tracer_otel") removeDependency("io.prometheus:simpleclient_tracer_otel_agent") } + module("org.jetbrains.kotlin:kotlin-stdlib") { + removeDependency("org.jetbrains.kotlin:kotlin-stdlib-common") + } module("junit:junit") { removeDependency("org.hamcrest:hamcrest-core") } module("org.hyperledger.besu:secp256k1") { addApiDependency("net.java.dev.jna:jna") } } @@ -110,7 +120,7 @@ extraJavaModuleInfo { } module("com.google.guava:failureaccess", "com.google.common.util.concurrent.internal") module("com.google.api.grpc:proto-google-common-protos", "com.google.api.grpc.common") - + module("com.google.dagger:dagger", "dagger") module("io.perfmark:perfmark-api", "io.perfmark") module("javax.inject:javax.inject", "javax.inject") @@ -121,6 +131,7 @@ extraJavaModuleInfo { module("org.checkerframework:checker-qual", "org.checkerframework.checker.qual") module("net.i2p.crypto:eddsa", "net.i2p.crypto.eddsa") + module("org.jetbrains:annotations", "org.jetbrains.annotations") module("org.antlr:antlr4-runtime", "org.antlr.antlr4.runtime") // needed for metrics and logging, but also several platform classes @@ -143,9 +154,24 @@ extraJavaModuleInfo { module("com.google.auto.service:auto-service-annotations", "com.google.auto.service") module("com.google.auto.service:auto-service", "com.google.auto.service.processor") module("com.google.auto:auto-common", "com.google.auto.common") + module("com.google.dagger:dagger-compiler", "dagger.compiler") + module("com.google.dagger:dagger-producers", "dagger.producers") + module("com.google.dagger:dagger-spi", "dagger.spi") + module( + "com.google.devtools.ksp:symbol-processing-api", + "com.google.devtools.ksp.symbolprocessingapi" + ) + module("com.google.errorprone:javac-shaded", "com.google.errorprone.javac.shaded") + module("com.google.googlejavaformat:google-java-format", "com.google.googlejavaformat") + module("net.ltgt.gradle.incap:incap", "net.ltgt.gradle.incap") + module("org.jetbrains.kotlinx:kotlinx-metadata-jvm", "kotlinx.metadata.jvm") // Test clients only module("com.google.protobuf:protobuf-java-util", "com.google.protobuf.util") + module("com.squareup:javapoet", "com.squareup.javapoet") { + exportAllPackages() + requires("java.compiler") + } module("junit:junit", "junit") module("org.hamcrest:hamcrest", "org.hamcrest") module("org.json:json", "org.json") diff --git a/server/src/main/java/com/hedera/block/server/BlockNodeApp.java b/server/src/main/java/com/hedera/block/server/BlockNodeApp.java index 269d2875f..58b668eda 100644 --- a/server/src/main/java/com/hedera/block/server/BlockNodeApp.java +++ b/server/src/main/java/com/hedera/block/server/BlockNodeApp.java @@ -16,9 +16,9 @@ package com.hedera.block.server; -import com.hedera.block.protos.BlockStreamService.Block; -import com.hedera.block.protos.BlockStreamService.BlockItem; -import com.hedera.block.protos.BlockStreamService.SubscribeStreamResponse; +import static java.lang.System.Logger; +import static java.lang.System.Logger.Level.INFO; + import com.hedera.block.server.config.BlockNodeContext; import com.hedera.block.server.data.ObjectEvent; import com.hedera.block.server.health.HealthService; @@ -29,14 +29,14 @@ import com.hedera.block.server.persistence.storage.read.BlockReader; import com.hedera.block.server.persistence.storage.write.BlockAsDirWriterBuilder; import com.hedera.block.server.persistence.storage.write.BlockWriter; -import com.hedera.block.server.producer.ItemAckBuilder; +import com.hedera.hapi.block.SubscribeStreamResponse; +import com.hedera.hapi.block.stream.Block; +import com.hedera.hapi.block.stream.BlockItem; import edu.umd.cs.findbugs.annotations.NonNull; import io.helidon.webserver.WebServer; import io.helidon.webserver.grpc.GrpcRouting; import io.helidon.webserver.http.HttpRouting; import java.io.IOException; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; import javax.inject.Inject; import javax.inject.Singleton; @@ -48,6 +48,7 @@ public class BlockNodeApp { private static final Logger LOGGER = System.getLogger(BlockNodeApp.class.getName()); + private final ServiceStatus serviceStatus; private final HealthService healthService; private final BlockNodeContext blockNodeContext; @@ -74,7 +75,8 @@ public BlockNodeApp( * * @throws IOException if the server cannot be started */ - public void startServer() throws IOException { + public void start() throws IOException { + final BlockWriter blockWriter = BlockAsDirWriterBuilder.newBuilder(blockNodeContext).build(); final StreamMediator> streamMediator = @@ -113,9 +115,7 @@ public void startServer() throws IOException { webServer.start(); // Log the server status - LOGGER.log( - Level.INFO, - String.format("Block Node Server started at port: %d", webServer.port())); + LOGGER.log(INFO, String.format("Block Node Server started at port: %d", webServer.port())); } @NonNull @@ -127,7 +127,6 @@ private static BlockStreamService buildBlockStreamService( @NonNull final ServiceStatus serviceStatus, @NonNull final BlockNodeContext blockNodeContext) { - return new BlockStreamService( - new ItemAckBuilder(), streamMediator, blockReader, serviceStatus, blockNodeContext); + return new BlockStreamService(streamMediator, blockReader, serviceStatus, blockNodeContext); } } diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index 7fc021bc6..77d5e68cc 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -19,25 +19,6 @@ import static java.lang.System.Logger; import static java.lang.System.Logger.Level.INFO; -import com.hedera.block.server.config.BlockNodeContext; -import com.hedera.block.server.config.BlockNodeContextFactory; -import com.hedera.block.server.data.ObjectEvent; -import com.hedera.block.server.health.HealthService; -import com.hedera.block.server.health.HealthServiceImpl; -import com.hedera.block.server.mediator.LiveStreamMediatorBuilder; -import com.hedera.block.server.mediator.StreamMediator; -import com.hedera.block.server.persistence.storage.PersistenceStorageConfig; -import com.hedera.block.server.persistence.storage.read.BlockAsDirReaderBuilder; -import com.hedera.block.server.persistence.storage.read.BlockReader; -import com.hedera.block.server.persistence.storage.write.BlockAsDirWriterBuilder; -import com.hedera.block.server.persistence.storage.write.BlockWriter; -import com.hedera.hapi.block.SubscribeStreamResponse; -import com.hedera.hapi.block.stream.Block; -import com.hedera.hapi.block.stream.BlockItem; -import edu.umd.cs.findbugs.annotations.NonNull; -import io.helidon.webserver.WebServer; -import io.helidon.webserver.grpc.GrpcRouting; -import io.helidon.webserver.http.HttpRouting; import java.io.IOException; /** Main class for the block node server */ @@ -51,75 +32,13 @@ private Server() {} * Main entrypoint for the block node server * * @param args Command line arguments. Not used at present. + * @throws IOException if there is an error starting the server */ - public static void main(final String[] args) { - + public static void main(final String[] args) throws IOException { LOGGER.log(INFO, "Starting BlockNode Server"); - - try { - // init context, metrics, and configuration. - final BlockNodeContext blockNodeContext = BlockNodeContextFactory.create(); - final ServiceStatus serviceStatus = new ServiceStatusImpl(); - - final BlockWriter blockWriter = - BlockAsDirWriterBuilder.newBuilder(blockNodeContext).build(); - - final StreamMediator> streamMediator = - LiveStreamMediatorBuilder.newBuilder( - blockWriter, blockNodeContext, serviceStatus) - .build(); - - final BlockReader blockReader = - BlockAsDirReaderBuilder.newBuilder( - blockNodeContext - .configuration() - .getConfigData(PersistenceStorageConfig.class)) - .build(); - - final BlockStreamService blockStreamService = - buildBlockStreamService( - streamMediator, blockReader, serviceStatus, blockNodeContext); - - final GrpcRouting.Builder grpcRouting = - GrpcRouting.builder().service(blockStreamService); - - final HealthService healthService = new HealthServiceImpl(serviceStatus); - - final HttpRouting.Builder httpRouting = - HttpRouting.builder() - .register(healthService.getHealthRootPath(), healthService); - - // Build the web server - // TODO: make port server a configurable value. - final WebServer webServer = - WebServer.builder() - .port(8080) - .addRouting(grpcRouting) - .addRouting(httpRouting) - .build(); - - // Update the serviceStatus with the web server - serviceStatus.setWebServer(webServer); - - // Start the web server - webServer.start(); - - // Log the server status - LOGGER.log(INFO, "Block Node Server started at port: " + webServer.port()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @NonNull - private static BlockStreamService buildBlockStreamService( - @NonNull - final StreamMediator> - streamMediator, - @NonNull final BlockReader blockReader, - @NonNull final ServiceStatus serviceStatus, - @NonNull final BlockNodeContext blockNodeContext) { - - return new BlockStreamService(streamMediator, blockReader, serviceStatus, blockNodeContext); + final BlockNodeAppInjectionComponent daggerComponent = + DaggerBlockNodeAppInjectionComponent.create(); + final BlockNodeApp blockNodeApp = daggerComponent.getBlockNodeApp(); + blockNodeApp.start(); } } diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index badccd128..4ad339a6f 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -11,6 +11,7 @@ exports com.hedera.block.server.config; exports com.hedera.block.server.mediator; exports com.hedera.block.server.data; + exports com.hedera.block.server.health; requires com.hedera.block.stream; requires com.google.protobuf;