Skip to content

Commit

Permalink
WIP address some pr comments, local file and noop writers now created…
Browse files Browse the repository at this point in the history
… via static methods

Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Nov 27, 2024
1 parent 699dfa8 commit edc6c93
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.hedera.block.server.persistence.storage.remove.BlockRemover;
import com.hedera.block.server.persistence.storage.remove.NoOpRemover;
import com.hedera.block.server.persistence.storage.write.BlockAsDirWriterBuilder;
import com.hedera.block.server.persistence.storage.write.BlockAsFileWriterBuilder;
import com.hedera.block.server.persistence.storage.write.BlockAsLocalFileWriter;
import com.hedera.block.server.persistence.storage.write.BlockWriter;
import com.hedera.block.server.persistence.storage.write.NoOpBlockWriter;
import com.hedera.hapi.block.BlockItemUnparsed;
Expand Down Expand Up @@ -76,13 +76,12 @@ static BlockWriter<List<BlockItemUnparsed>> providesBlockWriter(
.type();
try {
return switch (persistenceType) {
case BLOCK_AS_LOCAL_FILE -> BlockAsFileWriterBuilder.newBuilder(
blockNodeContext, blockRemover, blockPathResolver)
.build();
case BLOCK_AS_LOCAL_FILE -> BlockAsLocalFileWriter.of(
blockNodeContext, blockRemover, blockPathResolver);
case BLOCK_AS_LOCAL_DIRECTORY -> BlockAsDirWriterBuilder.newBuilder(
blockNodeContext, blockRemover, blockPathResolver)
.build();
case NO_OP -> new NoOpBlockWriter();
case NO_OP -> NoOpBlockWriter.newInstance();
};
} catch (final IOException e) {
// we cannot have checked exceptions with dagger @Provides
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* A Block writer that handles writing of block-as-file.
*/
class BlockAsFileWriter implements LocalBlockWriter<List<BlockItemUnparsed>> {
public final class BlockAsLocalFileWriter implements LocalBlockWriter<List<BlockItemUnparsed>> {
private final MetricsService metricsService;
private final BlockRemover blockRemover; // todo do I need here?
private final BlockPathResolver blockPathResolver;
Expand All @@ -56,7 +56,7 @@ class BlockAsFileWriter implements LocalBlockWriter<List<BlockItemUnparsed>> {
* @param blockPathResolver valid, {@code non-null} instance of {@link BlockPathResolver} used
* to resolve paths to Blocks
*/
BlockAsFileWriter(
private BlockAsLocalFileWriter(
@NonNull final BlockNodeContext blockNodeContext,
@NonNull final BlockRemover blockRemover,
@NonNull final BlockPathResolver blockPathResolver) {
Expand All @@ -65,6 +65,24 @@ class BlockAsFileWriter implements LocalBlockWriter<List<BlockItemUnparsed>> {
this.blockPathResolver = Objects.requireNonNull(blockPathResolver);
}

/**
* This method creates and returns a new instance of {@link BlockAsLocalFileWriter}.
*
* @param blockNodeContext valid, {@code non-null} instance of
* {@link BlockNodeContext} used to get the {@link MetricsService}
* @param blockRemover valid, {@code non-null} instance of
* {@link BlockRemover} used to remove blocks in case of cleanup
* @param blockPathResolver valid, {@code non-null} instance of
* {@link BlockPathResolver} used to resolve paths to Blocks
* @return a new, fully initialized instance of {@link BlockAsLocalFileWriter}
*/
public static BlockAsLocalFileWriter of(
@NonNull final BlockNodeContext blockNodeContext,
@NonNull final BlockRemover blockRemover,
@NonNull final BlockPathResolver blockPathResolver) {
return new BlockAsLocalFileWriter(blockNodeContext, blockRemover, blockPathResolver);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@
* designed to isolate the Producer and Mediator components from storage implementation during testing while still
* providing metrics and logging for troubleshooting.
*/
public class NoOpBlockWriter implements LocalBlockWriter<List<BlockItemUnparsed>> {
public final class NoOpBlockWriter implements BlockWriter<List<BlockItemUnparsed>> {
/**
* Constructor.
*/
private NoOpBlockWriter() {}

/**
* This method creates and returns a new instance of
* {@link NoOpBlockWriter}.
*
* @return a new, fully initialized instance of {@link NoOpBlockWriter}
*/
public static NoOpBlockWriter newInstance() {
return new NoOpBlockWriter();
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit edc6c93

Please sign in to comment.