Skip to content

Commit

Permalink
fix: importing System.Logger
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Aug 22, 2024
1 parent ebf333a commit 5add1a0
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.hedera.block.server.Constants.SINGLE_BLOCK_METHOD_NAME;
import static com.hedera.block.server.Translator.toProtocSingleBlockResponse;
import static com.hedera.block.server.Translator.toProtocSubscribeStreamResponse;
import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;

Expand Down Expand Up @@ -58,7 +59,7 @@
*/
public class BlockStreamService implements GrpcService {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>> streamMediator;
private final ServiceStatus serviceStatus;
Expand Down Expand Up @@ -131,9 +132,7 @@ StreamObserver<com.hedera.hapi.block.protoc.PublishStreamRequest> protocPublishB
@NonNull
final StreamObserver<com.hedera.hapi.block.protoc.PublishStreamResponse>
publishStreamResponseObserver) {
LOGGER.log(
DEBUG,
"Executing bidirectional publishBlockStream gRPC method");
LOGGER.log(DEBUG, "Executing bidirectional publishBlockStream gRPC method");

return new ProducerBlockItemObserver(
streamMediator, publishStreamResponseObserver, serviceStatus);
Expand All @@ -146,9 +145,7 @@ void protocSubscribeBlockStream(
@NonNull
final StreamObserver<com.hedera.hapi.block.protoc.SubscribeStreamResponse>
subscribeStreamResponseObserver) {
LOGGER.log(
DEBUG,
"Executing Server Streaming subscribeBlockStream gRPC method");
LOGGER.log(DEBUG, "Executing Server Streaming subscribeBlockStream gRPC method");

// Return a custom StreamObserver to handle streaming blocks from the producer.
if (serviceStatus.isRunning()) {
Expand Down Expand Up @@ -181,10 +178,7 @@ void protocSingleBlock(
toPbjSingleBlockRequest(singleBlockRequest);
singleBlock(pbjSingleBlockRequest, singleBlockResponseStreamObserver);
} catch (ParseException e) {
LOGGER.log(
ERROR,
"Error parsing protoc SingleBlockRequest: {0}",
singleBlockRequest);
LOGGER.log(ERROR, "Error parsing protoc SingleBlockRequest: {0}", singleBlockRequest);
singleBlockResponseStreamObserver.onNext(buildSingleBlockNotAvailableResponse());
}
}
Expand All @@ -202,29 +196,22 @@ private void singleBlock(
try {
final Optional<Block> blockOpt = blockReader.read(blockNumber);
if (blockOpt.isPresent()) {
LOGGER.log(
DEBUG,
"Successfully returning block number: {0}",
blockNumber);
LOGGER.log(DEBUG, "Successfully returning block number: {0}", blockNumber);
singleBlockResponseStreamObserver.onNext(
toProtocSingleBlockResponse(blockOpt.get()));

final MetricsService metricsService = blockNodeContext.metricsService();
metricsService.singleBlocksRetrieved.increment();
} else {
LOGGER.log(
DEBUG, "Block number {0} not found", blockNumber);
LOGGER.log(DEBUG, "Block number {0} not found", blockNumber);
singleBlockResponseStreamObserver.onNext(buildSingleBlockNotFoundResponse());
}
} catch (IOException e) {
LOGGER.log(
ERROR, "Error reading block number: {0}", blockNumber);
LOGGER.log(ERROR, "Error reading block number: {0}", blockNumber);
singleBlockResponseStreamObserver.onNext(buildSingleBlockNotAvailableResponse());
}
} else {
LOGGER.log(
ERROR,
"Unary singleBlock gRPC method is not currently running");
LOGGER.log(ERROR, "Unary singleBlock gRPC method is not currently running");
singleBlockResponseStreamObserver.onNext(buildSingleBlockNotAvailableResponse());
}

Expand Down
11 changes: 5 additions & 6 deletions server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.hedera.block.server;

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;
Expand All @@ -37,12 +40,10 @@
import io.helidon.webserver.http.HttpRouting;
import java.io.IOException;

import static java.lang.System.Logger.Level.INFO;

/** Main class for the block node server */
public class Server {

private static final System.Logger LOGGER = System.getLogger(Server.class.getName());
private static final Logger LOGGER = System.getLogger(Server.class.getName());

private Server() {}

Expand Down Expand Up @@ -104,9 +105,7 @@ public static void main(final String[] args) {
webServer.start();

// Log the server status
LOGGER.log(
INFO,
"Block Node Server started at port: " + webServer.port());
LOGGER.log(INFO, "Block Node Server started at port: " + webServer.port());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.block.server.consumer;

import static com.hedera.block.server.Translator.toProtocSubscribeStreamResponse;
import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;

Expand All @@ -42,7 +43,7 @@
public class ConsumerStreamResponseObserver
implements EventHandler<ObjectEvent<SubscribeStreamResponse>> {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final StreamObserver<com.hedera.hapi.block.protoc.SubscribeStreamResponse>
subscribeStreamResponseObserver;
Expand Down Expand Up @@ -109,9 +110,7 @@ public ConsumerStreamResponseObserver(
// Do not allow additional responses to be sent.
isResponsePermitted.set(false);
subscriptionHandler.unsubscribe(this);
LOGGER.log(
DEBUG,
"Consumer cancelled stream. Observer unsubscribed.");
LOGGER.log(DEBUG, "Consumer cancelled stream. Observer unsubscribed.");
};
serverCallStreamObserver.setOnCancelHandler(onCancel);

Expand All @@ -121,9 +120,7 @@ public ConsumerStreamResponseObserver(
// Do not allow additional responses to be sent.
isResponsePermitted.set(false);
subscriptionHandler.unsubscribe(this);
LOGGER.log(
DEBUG,
"Consumer completed stream. Observer unsubscribed.");
LOGGER.log(DEBUG, "Consumer completed stream. Observer unsubscribed.");
};
serverCallStreamObserver.setOnCloseHandler(onClose);
}
Expand Down Expand Up @@ -156,9 +153,7 @@ public void onEvent(
final long currentMillis = producerLivenessClock.millis();
if (currentMillis - producerLivenessMillis > timeoutThresholdMillis) {
subscriptionHandler.unsubscribe(this);
LOGGER.log(
DEBUG,
"Unsubscribed ConsumerBlockItemObserver due to producer timeout");
LOGGER.log(DEBUG, "Unsubscribed ConsumerBlockItemObserver due to producer timeout");
} else {
// Refresh the producer liveness and pass the BlockItem to the downstream observer.
producerLivenessMillis = currentMillis;
Expand Down Expand Up @@ -210,10 +205,7 @@ public void send(@NonNull final SubscribeStreamResponse subscribeStreamResponse)
}

if (streamStarted) {
LOGGER.log(
DEBUG,
"Send BlockItem downstream: {0} ",
blockItem);
LOGGER.log(DEBUG, "Send BlockItem downstream: {0} ", blockItem);
subscribeStreamResponseObserver.onNext(
toProtocSubscribeStreamResponse(subscribeStreamResponse));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.hedera.block.server.mediator;

import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;

import com.hedera.block.server.ServiceStatus;
import com.hedera.block.server.config.BlockNodeContext;
import com.hedera.block.server.data.ObjectEvent;
Expand All @@ -37,9 +41,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;

/**
* LiveStreamMediatorImpl is an implementation of the StreamMediator interface. It is responsible
* for managing the subscribe and unsubscribe operations of downstream consumers. It also proxies
Expand All @@ -49,7 +50,7 @@
class LiveStreamMediatorImpl
implements StreamMediator<BlockItem, ObjectEvent<SubscribeStreamResponse>> {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final RingBuffer<ObjectEvent<SubscribeStreamResponse>> ringBuffer;
private final ExecutorService executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.hedera.block.server.persistence.storage;

import static java.lang.System.Logger;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -28,7 +30,7 @@
/** FileUtils methods provide common functionality for the storage package. */
public final class FileUtils {

private static final System.Logger LOGGER = System.getLogger(FileUtils.class.getName());
private static final Logger LOGGER = System.getLogger(FileUtils.class.getName());

private FileUtils() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.hedera.block.server.persistence.storage;

import static java.lang.System.Logger.Level.ERROR;

import com.swirlds.config.api.ConfigData;
import com.swirlds.config.api.ConfigProperty;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static java.lang.System.Logger.Level.ERROR;

/**
* Use this configuration across the persistent storage package
*
Expand All @@ -51,8 +51,7 @@ public record PersistenceStorageConfig(@ConfigProperty(defaultValue = "") String
// Create Directory if it does not exist
if (Files.notExists(path)) {
try {
FileUtils.createPathIfNotExists(
path, ERROR, FileUtils.defaultPerms);
FileUtils.createPathIfNotExists(path, ERROR, FileUtils.defaultPerms);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.block.server.persistence.storage.read;

import static com.hedera.block.server.Constants.BLOCK_FILE_EXTENSION;
import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.INFO;
Expand Down Expand Up @@ -46,7 +47,7 @@
*/
class BlockAsDirReader implements BlockReader<Block> {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final Path blockNodeRootPath;
private final FileAttribute<Set<PosixFilePermission>> filePerms;
Expand Down Expand Up @@ -171,10 +172,7 @@ private boolean isPathDisqualified(@NonNull final Path path) {

if (!path.toFile().canRead()) {
LOGGER.log(ERROR, "Path not readable: {0}", path);
LOGGER.log(
ERROR,
"Attempting to repair the path permissions: {0}",
path);
LOGGER.log(ERROR, "Attempting to repair the path permissions: {0}", path);

try {
// If resetting the permissions fails or
Expand All @@ -184,8 +182,7 @@ private boolean isPathDisqualified(@NonNull final Path path) {
return true;
}
} catch (IOException e) {
LOGGER.log(
ERROR, "Error setting permissions on: {0}" + path, e);
LOGGER.log(ERROR, "Error setting permissions on: {0}" + path, e);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.hedera.block.server.persistence.storage.remove;

import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.ERROR;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.File;
import java.io.IOException;
Expand All @@ -25,15 +28,13 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

import static java.lang.System.Logger.Level.ERROR;

/**
* The BlockAsDirRemover class removes a block from the file system. The block is stored as a
* directory containing block items. The block items are stored as files within the block directory.
*/
public class BlockAsDirRemover implements BlockRemover {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final Path blockNodeRootPath;
private final FileAttribute<Set<PosixFilePermission>> filePerms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.block.server.persistence.storage.write;

import static com.hedera.block.server.Constants.BLOCK_FILE_EXTENSION;
import static java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.INFO;
Expand Down Expand Up @@ -47,7 +48,7 @@
*/
class BlockAsDirWriter implements BlockWriter<BlockItem> {

private final System.Logger LOGGER = System.getLogger(getClass().getName());
private final Logger LOGGER = System.getLogger(getClass().getName());

private final Path blockNodeRootPath;
private long blockNodeFileNameIndex;
Expand Down Expand Up @@ -108,10 +109,7 @@ public void write(@NonNull final BlockItem blockItem) throws IOException {
break;
} catch (IOException e) {

LOGGER.log(
ERROR,
"Error writing the BlockItem protobuf to a file: ",
e);
LOGGER.log(ERROR, "Error writing the BlockItem protobuf to a file: ", e);

// Remove the block if repairing the permissions fails
if (retries > 0) {
Expand All @@ -123,9 +121,7 @@ public void write(@NonNull final BlockItem blockItem) throws IOException {
// and the blockItem path
repairPermissions(blockNodeRootPath);
repairPermissions(calculateBlockPath());
LOGGER.log(
INFO,
"Retrying to write the BlockItem protobuf to a file");
LOGGER.log(INFO, "Retrying to write the BlockItem protobuf to a file");
}
}
}
Expand All @@ -143,15 +139,9 @@ protected void write(@NonNull final Path blockItemFilePath, @NonNull final Block
try (final FileOutputStream fos = new FileOutputStream(blockItemFilePath.toString())) {

BlockItem.PROTOBUF.toBytes(blockItem).writeTo(fos);
LOGGER.log(
DEBUG,
"Successfully wrote the block item file: {0}",
blockItemFilePath);
LOGGER.log(DEBUG, "Successfully wrote the block item file: {0}", blockItemFilePath);
} catch (IOException e) {
LOGGER.log(
ERROR,
"Error writing the BlockItem protobuf to a file: ",
e);
LOGGER.log(ERROR, "Error writing the BlockItem protobuf to a file: ", e);
throw e;
}
}
Expand Down Expand Up @@ -188,10 +178,7 @@ private void repairPermissions(@NonNull final Path path) throws IOException {
// Attempt to restore the permissions on the block node root directory
Files.setPosixFilePermissions(path, filePerms.value());
} catch (IOException e) {
LOGGER.log(
ERROR,
"Error setting permissions on the path: " + path,
e);
LOGGER.log(ERROR, "Error setting permissions on the path: " + path, e);
throw e;
}
}
Expand Down
Loading

0 comments on commit 5add1a0

Please sign in to comment.