Skip to content

Commit 1916732

Browse files
fix: logger to LOGGER per code review
Signed-off-by: Matt Peterson <[email protected]>
1 parent 0608e65 commit 1916732

File tree

8 files changed

+33
-35
lines changed

8 files changed

+33
-35
lines changed

server/src/main/java/com/hedera/block/server/BlockStreamService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public class BlockStreamService implements GrpcService {
4444

45-
private final Logger logger = Logger.getLogger(getClass().getName());
45+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
4646

4747
private final long timeoutThresholdMillis;
4848
private final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator;
@@ -100,7 +100,7 @@ public void update(Routing routing) {
100100
* via the streamMediator as well as sending responses back to the producer.
101101
*/
102102
private StreamObserver<BlockStreamServiceGrpcProto.Block> streamSink(StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver) {
103-
logger.finer("Executing bidirectional streamSink method");
103+
LOGGER.finer("Executing bidirectional streamSink method");
104104

105105
return new ProducerBlockStreamObserver(streamMediator, responseStreamObserver);
106106
}
@@ -115,7 +115,7 @@ private StreamObserver<BlockStreamServiceGrpcProto.Block> streamSink(StreamObser
115115
* handling responses from the consumer.
116116
*/
117117
private StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> streamSource(StreamObserver<BlockStreamServiceGrpcProto.Block> responseStreamObserver) {
118-
logger.finer("Executing bidirectional streamSource method");
118+
LOGGER.finer("Executing bidirectional streamSource method");
119119

120120
// Return a custom StreamObserver to handle streaming blocks from the producer.
121121
LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamObserver = new LiveStreamObserverImpl(

server/src/main/java/com/hedera/block/server/Server.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class Server {
4747
private static ServerCalls.BidiStreamingMethod<Stream<BlockStreamServiceGrpcProto.Block>, StreamObserver<BlockStreamServiceGrpcProto.Block>> clientBidiStreamingMethod;
4848
private static ServerCalls.BidiStreamingMethod<Stream<BlockStreamServiceGrpcProto.BlockResponse>, StreamObserver<BlockStreamServiceGrpcProto.Block>> serverBidiStreamingMethod;
4949

50-
private static final Logger logger = Logger.getLogger(Server.class.getName());
50+
private static final Logger LOGGER = Logger.getLogger(Server.class.getName());
5151

5252
private Server() {}
5353

@@ -89,7 +89,7 @@ public static void main(String[] args) {
8989
.start();
9090

9191
} catch (IOException e) {
92-
logger.severe("There was an exception starting the server: " + e.getMessage());
92+
LOGGER.severe("There was an exception starting the server: " + e.getMessage());
9393
throw new RuntimeException(e);
9494
}
9595
}

server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> {
3333

34-
private final Logger logger = Logger.getLogger(getClass().getName());
34+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
3535

3636
private final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> mediator;
3737
private final StreamObserver<BlockStreamServiceGrpcProto.Block> responseStreamObserver;
@@ -69,7 +69,7 @@ public void notify(BlockStreamServiceGrpcProto.Block block) {
6969

7070
if (System.currentTimeMillis() - this.consumerLivenessMillis > timeoutThresholdMillis) {
7171
if (mediator.isSubscribed(this)) {
72-
logger.info("Consumer timeout threshold exceeded. Unsubscribing observer.");
72+
LOGGER.info("Consumer timeout threshold exceeded. Unsubscribing observer.");
7373
mediator.unsubscribe(this);
7474
}
7575
} else {
@@ -88,11 +88,11 @@ public void onNext(BlockStreamServiceGrpcProto.BlockResponse blockResponse) {
8888

8989
if (System.currentTimeMillis() - this.producerLivenessMillis > timeoutThresholdMillis) {
9090
if (mediator.isSubscribed(this)) {
91-
logger.info("Producer timeout threshold exceeded. Unsubscribing observer.");
91+
LOGGER.info("Producer timeout threshold exceeded. Unsubscribing observer.");
9292
mediator.unsubscribe(this);
9393
}
9494
} else {
95-
logger.finer("Received response block " + blockResponse);
95+
LOGGER.finer("Received response block " + blockResponse);
9696
this.consumerLivenessMillis = System.currentTimeMillis();
9797
}
9898
}
@@ -105,7 +105,7 @@ public void onNext(BlockStreamServiceGrpcProto.BlockResponse blockResponse) {
105105
*/
106106
@Override
107107
public void onError(Throwable t) {
108-
logger.severe("onError: " + t.getMessage());
108+
LOGGER.severe("onError: " + t.getMessage());
109109
mediator.unsubscribe(this);
110110
}
111111

@@ -116,8 +116,8 @@ public void onError(Throwable t) {
116116
*/
117117
@Override
118118
public void onCompleted() {
119-
logger.finer("gRPC connection completed. Unsubscribing observer.");
119+
LOGGER.finer("gRPC connection completed. Unsubscribing observer.");
120120
mediator.unsubscribe(this);
121-
logger.finer("Unsubscribed observer.");
121+
LOGGER.finer("Unsubscribed observer.");
122122
}
123123
}

server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public class LiveStreamMediatorImpl implements StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> {
3838

39-
private final Logger logger = Logger.getLogger(getClass().getName());
39+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
4040
private final Set<LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse>> subscribers = Collections.synchronizedSet(new LinkedHashSet<>());
4141

4242
private final BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler;
@@ -69,9 +69,9 @@ public void subscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, Bloc
6969
@Override
7070
public void unsubscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver) {
7171
if (this.subscribers.remove(liveStreamObserver)) {
72-
logger.finer("Successfully removed observer from subscription list");
72+
LOGGER.finer("Successfully removed observer from subscription list");
7373
} else {
74-
logger.finer("Failed to remove observer from subscription list");
74+
LOGGER.finer("Failed to remove observer from subscription list");
7575
}
7676
}
7777

server/src/main/java/com/hedera/block/server/persistence/cache/LRUCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
public class LRUCache implements BlockCache<BlockStreamServiceGrpcProto.Block> {
3434

3535
private final Map<Long, BlockStreamServiceGrpcProto.Block> m;
36-
private final Logger logger = Logger.getLogger(getClass().getName());
36+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
3737

3838
/**
3939
* Constructor for the LRUCache class.
4040
*
4141
* @param maxEntries the maximum number of entries in the cache
4242
*/
4343
public LRUCache(long maxEntries) {
44-
logger.finer("Creating LRUCache with maxEntries: " + maxEntries);
44+
LOGGER.finer("Creating LRUCache with maxEntries: " + maxEntries);
4545
m = Collections.synchronizedMap(new BNLinkedHashMap<>(maxEntries));
4646
}
4747

server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class FileSystemBlockStorage implements BlockStorage<BlockStreamServiceGr
4040
public static final String BLOCK_FILE_EXTENSION = ".blk";
4141

4242
private final Path blockNodeRootPath;
43-
private final Logger logger = Logger.getLogger(getClass().getName());
43+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
4444

4545
/**
4646
* Constructs a FileSystemBlockStorage object.
@@ -51,15 +51,15 @@ public class FileSystemBlockStorage implements BlockStorage<BlockStreamServiceGr
5151
*/
5252
public FileSystemBlockStorage(String key, Config config) throws IOException {
5353

54-
logger.info("Initializing FileSystemBlockStorage");
55-
logger.info(config.toString());
54+
LOGGER.info("Initializing FileSystemBlockStorage");
55+
LOGGER.info(config.toString());
5656

5757
blockNodeRootPath = Path.of(config
5858
.get(key)
5959
.asString()
6060
.get());
6161

62-
logger.info("Block Node Root Path: " + blockNodeRootPath);
62+
LOGGER.info("Block Node Root Path: " + blockNodeRootPath);
6363

6464
if (!blockNodeRootPath.isAbsolute()) {
6565
throw new IllegalArgumentException(BLOCKNODE_STORAGE_ROOT_PATH_KEY+ " must be an absolute path");
@@ -68,9 +68,9 @@ public FileSystemBlockStorage(String key, Config config) throws IOException {
6868
// Initialize the block node root directory if it does not exist
6969
if (Files.notExists(blockNodeRootPath)) {
7070
Files.createDirectory(blockNodeRootPath);
71-
logger.info("Created block node root directory: " + blockNodeRootPath);
71+
LOGGER.info("Created block node root directory: " + blockNodeRootPath);
7272
} else {
73-
logger.info("Block node root directory exists: " + blockNodeRootPath);
73+
LOGGER.info("Block node root directory exists: " + blockNodeRootPath);
7474
}
7575
}
7676

@@ -84,14 +84,14 @@ public FileSystemBlockStorage(String key, Config config) throws IOException {
8484
public Optional<Long> write(BlockStreamServiceGrpcProto.Block block) {
8585
Long id = block.getId();
8686
String fullPath = resolvePath(id);
87-
logger.finer("Wrote the file: " + fullPath);
87+
Logger.finer("Wrote the file: " + fullPath);
8888

8989
try (FileOutputStream fos = new FileOutputStream(fullPath)) {
9090
block.writeTo(fos);
9191
return Optional.of(id);
9292
}
9393
catch (IOException e) {
94-
logger.severe("Error writing string to file: " + e.getMessage());
94+
LOGGER.severe("Error writing string to file: " + e.getMessage());
9595
return Optional.empty();
9696
}
9797
}
@@ -112,7 +112,7 @@ private Optional<BlockStreamServiceGrpcProto.Block> read(String filePath) {
112112
try (FileInputStream fis = new FileInputStream(filePath)) {
113113
return Optional.of(BlockStreamServiceGrpcProto.Block.parseFrom(fis));
114114
} catch (FileNotFoundException io) {
115-
logger.severe("Error reading file: " + filePath);
115+
LOGGER.severe("Error reading file: " + filePath);
116116
return Optional.empty();
117117
} catch (IOException io) {
118118
throw new RuntimeException("Error reading file: " + filePath, io);
@@ -123,7 +123,7 @@ private String resolvePath(Long id) {
123123

124124
String fileName = id + BLOCK_FILE_EXTENSION;
125125
Path fullPath = blockNodeRootPath.resolve(fileName);
126-
logger.finer("Resolved fullPath: " + fullPath);
126+
LOGGER.finer("Resolved fullPath: " + fullPath);
127127

128128
return fullPath.toString();
129129
}

server/src/main/java/com/hedera/block/server/producer/ProducerBlockStreamObserver.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ProducerBlockStreamObserver implements StreamObserver<BlockStreamSe
3535

3636
private final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator;
3737
private final StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver;
38-
private final Logger logger = Logger.getLogger(getClass().getName());
38+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
3939

4040
/**
4141
* Constructor for the ProducerBlockStreamObserver class. It is responsible for calling the mediator with blocks
@@ -60,8 +60,6 @@ public ProducerBlockStreamObserver(StreamMediator<BlockStreamServiceGrpcProto.Bl
6060
*/
6161
@Override
6262
public void onNext(BlockStreamServiceGrpcProto.Block block) {
63-
logger.finer("onNext called");
64-
6563
streamMediator.notifyAll(block);
6664

6765
BlockStreamServiceGrpcProto.BlockResponse blockResponse = BlockStreamServiceGrpcProto.BlockResponse.newBuilder().setId(block.getId()).build();
@@ -75,7 +73,7 @@ public void onNext(BlockStreamServiceGrpcProto.Block block) {
7573
*/
7674
@Override
7775
public void onError(Throwable t) {
78-
logger.severe("onError called with the exception: " + t.getMessage());
76+
LOGGER.severe("onError called with the exception: " + t.getMessage());
7977
}
8078

8179
/**
@@ -85,8 +83,8 @@ public void onError(Throwable t) {
8583
*/
8684
@Override
8785
public void onCompleted() {
88-
logger.finer("StreamObserver completed");
86+
LOGGER.finer("ProducerBlockStreamObserver completed");
8987
this.streamMediator.unsubscribeAll();
90-
logger.finer("Unsubscribed all downstream consumers");
88+
LOGGER.finer("Unsubscribed all downstream consumers");
9189
}
9290
}

server/src/test/java/com/hedera/block/server/persistence/WriteThroughCacheHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
public class WriteThroughCacheHandlerTest {
5252

53-
private final Logger logger = Logger.getLogger(getClass().getName());
53+
private final Logger LOGGER = Logger.getLogger(getClass().getName());
5454

5555
private static final String TEMP_DIR = "block-node-unit-test-dir";
5656
private static final String JUNIT = "my-junit-test";
@@ -61,7 +61,7 @@ public class WriteThroughCacheHandlerTest {
6161
@BeforeEach
6262
public void setUp() throws IOException {
6363
testPath = Files.createTempDirectory(TEMP_DIR);
64-
logger.info("Created temp directory: " + testPath.toString());
64+
LOGGER.info("Created temp directory: " + testPath.toString());
6565

6666
Map<String, String> testProperties = Map.of(JUNIT, testPath.toString());
6767
ConfigSource testConfigSource = MapConfigSource.builder().map(testProperties).build();

0 commit comments

Comments
 (0)