-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring everything at BlockNodeApp to use Dagger singletons inste…
…ad injected at the constructor by DaggerComponent, instead of initializing them on the startup sequence. Also, adding a BlockNodeApp Test now that everything is being injected. Signed-off-by: Alfredo Gutierrez <[email protected]>
- Loading branch information
1 parent
cedb64d
commit 31eddb9
Showing
8 changed files
with
264 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
server/src/main/java/com/hedera/block/server/config/ConfigInjectionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.server.config; | ||
|
||
import com.hedera.block.server.consumer.ConsumerConfig; | ||
import com.hedera.block.server.persistence.storage.PersistenceStorageConfig; | ||
import com.swirlds.common.config.BasicCommonConfig; | ||
import com.swirlds.common.metrics.config.MetricsConfig; | ||
import com.swirlds.common.metrics.platform.prometheus.PrometheusConfig; | ||
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 dagger.Module; | ||
import dagger.Provides; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import javax.inject.Singleton; | ||
|
||
@Module | ||
public interface ConfigInjectionModule { | ||
|
||
static final String APPLICATION_PROPERTIES = "app.properties"; | ||
|
||
@Singleton | ||
@Provides | ||
static Configuration provideConfiguration() { | ||
try { | ||
return ConfigurationBuilder.create() | ||
.withSource(SystemEnvironmentConfigSource.getInstance()) | ||
.withSource(SystemPropertiesConfigSource.getInstance()) | ||
.withSource(new ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES))) | ||
.autoDiscoverExtensions() | ||
.build(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to create configuration", e); | ||
} | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
static PersistenceStorageConfig providePersistenceStorageConfig( | ||
@NonNull Configuration configuration) { | ||
return configuration.getConfigData(PersistenceStorageConfig.class); | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
static MetricsConfig provideMetricsConfig(@NonNull Configuration configuration) { | ||
return configuration.getConfigData(MetricsConfig.class); | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
static PrometheusConfig providePrometheusConfig(@NonNull Configuration configuration) { | ||
return configuration.getConfigData(PrometheusConfig.class); | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
static ConsumerConfig provideConsumerConfig(@NonNull Configuration configuration) { | ||
return configuration.getConfigData(ConsumerConfig.class); | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
static BasicCommonConfig provideBasicCommonConfig(@NonNull Configuration configuration) { | ||
return configuration.getConfigData(BasicCommonConfig.class); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
server/src/main/java/com/hedera/block/server/mediator/MediatorInjectionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.server.mediator; | ||
|
||
import com.hedera.block.server.ServiceStatus; | ||
import com.hedera.block.server.config.BlockNodeContext; | ||
import com.hedera.block.server.data.ObjectEvent; | ||
import com.hedera.block.server.persistence.storage.write.BlockWriter; | ||
import com.hedera.hapi.block.SubscribeStreamResponse; | ||
import com.hedera.hapi.block.stream.BlockItem; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import javax.inject.Singleton; | ||
|
||
/** A Dagger module for providing dependencies for Mediator Module.` */ | ||
@Module | ||
public interface MediatorInjectionModule { | ||
|
||
/** | ||
* Provides the stream mediator. | ||
* | ||
* @param blockWriter the block writer | ||
* @param blockNodeContext the block node context | ||
* @param serviceStatus the service status | ||
* @return the stream mediator | ||
*/ | ||
@Provides | ||
@Singleton | ||
static StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>> providesStreamMediator( | ||
@NonNull BlockWriter<BlockItem> blockWriter, | ||
@NonNull BlockNodeContext blockNodeContext, | ||
@NonNull ServiceStatus serviceStatus) { | ||
return LiveStreamMediatorBuilder.newBuilder(blockWriter, blockNodeContext, serviceStatus) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.