Skip to content

Commit cd7ad67

Browse files
fix: added final keyword per code review requests
Signed-off-by: Matt Peterson <[email protected]>
1 parent 07df87d commit cd7ad67

15 files changed

+69
-65
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class BlockStreamService implements GrpcService {
5252
* @param timeoutThresholdMillis the timeout threshold in milliseconds
5353
* @param streamMediator the stream mediator
5454
*/
55-
public BlockStreamService(long timeoutThresholdMillis,
56-
StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator) {
55+
public BlockStreamService(final long timeoutThresholdMillis,
56+
final StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamMediator) {
5757

5858
this.timeoutThresholdMillis = timeoutThresholdMillis;
5959
this.streamMediator = streamMediator;
@@ -85,7 +85,7 @@ public String serviceName() {
8585
* @param routing the routing for the BlockStreamService
8686
*/
8787
@Override
88-
public void update(Routing routing) {
88+
public void update(final Routing routing) {
8989
routing.bidi(CLIENT_STREAMING_METHOD_NAME, this::streamSink);
9090
routing.bidi(SERVER_STREAMING_METHOD_NAME, this::streamSource);
9191
}
@@ -98,7 +98,8 @@ public void update(Routing routing) {
9898
* @return a custom StreamObserver to handle streaming blocks from the producer to all subscribed consumers
9999
* via the streamMediator as well as sending responses back to the producer.
100100
*/
101-
private StreamObserver<BlockStreamServiceGrpcProto.Block> streamSink(StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver) {
101+
private StreamObserver<BlockStreamServiceGrpcProto.Block> streamSink(
102+
final StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> responseStreamObserver) {
102103
LOGGER.finer("Executing bidirectional streamSink method");
103104

104105
return new ProducerBlockStreamObserver(streamMediator, responseStreamObserver);
@@ -113,14 +114,16 @@ private StreamObserver<BlockStreamServiceGrpcProto.Block> streamSink(StreamObser
113114
* @return a custom StreamObserver to handle streaming blocks from the producer to the consumer as well as
114115
* handling responses from the consumer.
115116
*/
116-
private StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> streamSource(StreamObserver<BlockStreamServiceGrpcProto.Block> responseStreamObserver) {
117+
private StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> streamSource(final StreamObserver<BlockStreamServiceGrpcProto.Block> responseStreamObserver) {
117118
LOGGER.finer("Executing bidirectional streamSource method");
118119

119120
// Return a custom StreamObserver to handle streaming blocks from the producer.
120-
LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamObserver = new LiveStreamObserverImpl(
121+
final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> streamObserver = new LiveStreamObserverImpl(
121122
timeoutThresholdMillis,
122123
streamMediator,
123124
responseStreamObserver);
125+
126+
// Subscribe the observer to the mediator
124127
streamMediator.subscribe(streamObserver);
125128

126129
return streamObserver;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public final class Constants {
2222
private Constants() {}
2323

2424
// Config Constants
25-
public static String BLOCKNODE_STORAGE_ROOT_PATH_KEY = "blocknode.storage.root.path";
25+
public static final String BLOCKNODE_STORAGE_ROOT_PATH_KEY = "blocknode.storage.root.path";
2626

2727
// Constants specified in the service definition of the .proto file
28-
public static String SERVICE_NAME = "BlockStreamGrpc";
29-
public static String CLIENT_STREAMING_METHOD_NAME = "StreamSink";
30-
public static String SERVER_STREAMING_METHOD_NAME = "StreamSource";
28+
public static final String SERVICE_NAME = "BlockStreamGrpc";
29+
public static final String CLIENT_STREAMING_METHOD_NAME = "StreamSink";
30+
public static final String SERVER_STREAMING_METHOD_NAME = "StreamSource";
3131
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ private Server() {}
5656
*
5757
* @param args Command line arguments. Not used at present,
5858
*/
59-
public static void main(String[] args) {
59+
public static void main(final String[] args) {
6060

6161
try {
6262

6363
// Set the global configuration
64-
Config config = Config.create();
64+
final Config config = Config.create();
6565
Config.global(config);
6666

6767
// Initialize the block storage, cache, and service
68-
BlockStorage<BlockStreamServiceGrpcProto.Block> blockStorage = new FileSystemBlockStorage(BLOCKNODE_STORAGE_ROOT_PATH_KEY, config);
69-
BlockCache<BlockStreamServiceGrpcProto.Block> blockCache = new LRUCache(1000);
70-
BlockStreamService blockStreamService = new BlockStreamService(1500,
68+
final BlockStorage<BlockStreamServiceGrpcProto.Block> blockStorage = new FileSystemBlockStorage(BLOCKNODE_STORAGE_ROOT_PATH_KEY, config);
69+
final BlockCache<BlockStreamServiceGrpcProto.Block> blockCache = new LRUCache(1000);
70+
final BlockStreamService blockStreamService = new BlockStreamService(1500,
7171
new LiveStreamMediatorImpl(new WriteThroughCacheHandler(blockStorage, blockCache)));
7272

7373
// Start the web server

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ public interface LiveStreamObserver<U, V> extends StreamObserver<V> {
3636
*
3737
* @param block - the block to be passed to the observer
3838
*/
39-
void notify(U block);
39+
void notify(final U block);
4040
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamSer
4747
* @param responseStreamObserver the response stream observer
4848
*
4949
*/
50-
public LiveStreamObserverImpl(long timeoutThresholdMillis,
50+
public LiveStreamObserverImpl(final long timeoutThresholdMillis,
5151
StreamMediator<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> mediator,
5252
StreamObserver<BlockStreamServiceGrpcProto.Block> responseStreamObserver) {
5353

@@ -65,7 +65,7 @@ public LiveStreamObserverImpl(long timeoutThresholdMillis,
6565
* @param block - the block to be passed to the observer
6666
*/
6767
@Override
68-
public void notify(BlockStreamServiceGrpcProto.Block block) {
68+
public void notify(final BlockStreamServiceGrpcProto.Block block) {
6969

7070
if (System.currentTimeMillis() - this.consumerLivenessMillis > timeoutThresholdMillis) {
7171
if (mediator.isSubscribed(this)) {
@@ -84,7 +84,7 @@ public void notify(BlockStreamServiceGrpcProto.Block block) {
8484
* @param blockResponse - the BlockResponse passed to the server via the bidirectional stream to the downstream consumer
8585
*/
8686
@Override
87-
public void onNext(BlockStreamServiceGrpcProto.BlockResponse blockResponse) {
87+
public void onNext(final BlockStreamServiceGrpcProto.BlockResponse blockResponse) {
8888

8989
if (System.currentTimeMillis() - this.producerLivenessMillis > timeoutThresholdMillis) {
9090
if (mediator.isSubscribed(this)) {
@@ -104,7 +104,7 @@ public void onNext(BlockStreamServiceGrpcProto.BlockResponse blockResponse) {
104104
* @param t the error occurred on the stream
105105
*/
106106
@Override
107-
public void onError(Throwable t) {
107+
public void onError(final Throwable t) {
108108
LOGGER.severe("onError: " + t.getMessage());
109109
mediator.unsubscribe(this);
110110
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class LiveStreamMediatorImpl implements StreamMediator<BlockStreamService
4747
* @param blockPersistenceHandler the block persistence handler
4848
*
4949
*/
50-
public LiveStreamMediatorImpl(BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler) {
50+
public LiveStreamMediatorImpl(final BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler) {
5151
this.blockPersistenceHandler = blockPersistenceHandler;
5252
}
5353

@@ -57,7 +57,7 @@ public LiveStreamMediatorImpl(BlockPersistenceHandler<BlockStreamServiceGrpcProt
5757
* @param liveStreamObserver - the observer to be subscribed
5858
*/
5959
@Override
60-
public void subscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver) {
60+
public void subscribe(final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver) {
6161
this.subscribers.add(liveStreamObserver);
6262
}
6363

@@ -67,7 +67,7 @@ public void subscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, Bloc
6767
* @param liveStreamObserver - the observer to be unsubscribed
6868
*/
6969
@Override
70-
public void unsubscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver) {
70+
public void unsubscribe(final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver) {
7171
if (this.subscribers.remove(liveStreamObserver)) {
7272
LOGGER.finer("Successfully removed observer from subscription list");
7373
} else {
@@ -82,7 +82,7 @@ public void unsubscribe(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, Bl
8282
* @return true if the observer is subscribed, false otherwise
8383
*/
8484
@Override
85-
public boolean isSubscribed(LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> observer) {
85+
public boolean isSubscribed(final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> observer) {
8686
return this.subscribers.contains(observer);
8787
}
8888

@@ -100,10 +100,10 @@ public void unsubscribeAll() {
100100
* @param block - the block to be notified to all observers
101101
*/
102102
@Override
103-
public void notifyAll(BlockStreamServiceGrpcProto.Block block) {
103+
public void notifyAll(final BlockStreamServiceGrpcProto.Block block) {
104104

105105
// Proxy the block to all live stream subscribers
106-
for (LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> subscriber : subscribers) {
106+
for (final LiveStreamObserver<BlockStreamServiceGrpcProto.Block, BlockStreamServiceGrpcProto.BlockResponse> subscriber : subscribers) {
107107
subscriber.notify(block);
108108
}
109109

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ public interface StreamMediator<U, V> {
3838
*
3939
* @param observer - the LiveStreamObserver to subscribe
4040
*/
41-
void subscribe(LiveStreamObserver<U, V> observer);
41+
void subscribe(final LiveStreamObserver<U, V> observer);
4242

4343
/**
4444
* Unsubscribes a LiveStreamObserver from the producer
4545
*
4646
* @param observer - the LiveStreamObserver to unsubscribe
4747
*/
48-
void unsubscribe(LiveStreamObserver<U, V> observer);
48+
void unsubscribe(final LiveStreamObserver<U, V> observer);
4949

5050
/**
5151
* Checks if the observer is subscribed to the producer
5252
*
5353
* @param observer - the LiveStreamObserver to check
5454
* @return true if the observer is subscribed, false otherwise
5555
*/
56-
boolean isSubscribed(LiveStreamObserver<U, V> observer);
56+
boolean isSubscribed(final LiveStreamObserver<U, V> observer);
5757

5858
/**
5959
* Unsubscribes all LiveStreamObservers from the producer
@@ -65,5 +65,5 @@ public interface StreamMediator<U, V> {
6565
*
6666
* @param block - the block to pass to the subscribers
6767
*/
68-
void notifyAll(U block);
68+
void notifyAll(final U block);
6969
}

server/src/main/java/com/hedera/block/server/persistence/BlockPersistenceHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public interface BlockPersistenceHandler<V> {
3535
* @param block the block to persist
3636
* @return the id of the block
3737
*/
38-
Long persist(V block);
38+
Long persist(final V block);
3939

4040
/**
4141
* Reads a block.
4242
*
4343
* @param id the id of the block to read
4444
* @return the block
4545
*/
46-
Optional<V> read(long id);
46+
Optional<V> read(final long id);
4747

4848
/**
4949
* Reads a range of blocks.
@@ -52,5 +52,5 @@ public interface BlockPersistenceHandler<V> {
5252
* @param endBlockId the id of the last block to read
5353
* @return a queue of blocks
5454
*/
55-
Queue<V> readRange(long startBlockId, long endBlockId);
55+
Queue<V> readRange(final long startBlockId, final long endBlockId);
5656
}

server/src/main/java/com/hedera/block/server/persistence/WriteThroughCacheHandler.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class WriteThroughCacheHandler implements BlockPersistenceHandler<BlockSt
4343
* @param blockStorage the block storage
4444
* @param blockCache the block cache
4545
*/
46-
public WriteThroughCacheHandler(BlockStorage<BlockStreamServiceGrpcProto.Block> blockStorage,
47-
BlockCache<BlockStreamServiceGrpcProto.Block> blockCache) {
46+
public WriteThroughCacheHandler(final BlockStorage<BlockStreamServiceGrpcProto.Block> blockStorage,
47+
final BlockCache<BlockStreamServiceGrpcProto.Block> blockCache) {
4848
this.blockStorage = blockStorage;
4949
this.blockCache = blockCache;
5050
}
@@ -56,7 +56,7 @@ public WriteThroughCacheHandler(BlockStorage<BlockStreamServiceGrpcProto.Block>
5656
* @return the block id
5757
*/
5858
@Override
59-
public Long persist(BlockStreamServiceGrpcProto.Block block) {
59+
public Long persist(final BlockStreamServiceGrpcProto.Block block) {
6060

6161
// Write-Through cache
6262
blockStorage.write(block);
@@ -71,13 +71,13 @@ public Long persist(BlockStreamServiceGrpcProto.Block block) {
7171
* @return the blocks
7272
*/
7373
@Override
74-
public Queue<BlockStreamServiceGrpcProto.Block> readRange(long startBlockId, long endBlockId) {
75-
Queue<BlockStreamServiceGrpcProto.Block> blocks = new ArrayDeque<>();
74+
public Queue<BlockStreamServiceGrpcProto.Block> readRange(final long startBlockId, final long endBlockId) {
75+
final Queue<BlockStreamServiceGrpcProto.Block> blocks = new ArrayDeque<>();
7676

7777
long count = startBlockId;
7878
Optional<BlockStreamServiceGrpcProto.Block> blockOpt = read(count);
7979
while (count <= endBlockId && blockOpt.isPresent()) {
80-
BlockStreamServiceGrpcProto.Block block = blockOpt.get();
80+
final BlockStreamServiceGrpcProto.Block block = blockOpt.get();
8181
blocks.offer(block);
8282
blockOpt = read(++count);
8383
}
@@ -92,7 +92,7 @@ public Queue<BlockStreamServiceGrpcProto.Block> readRange(long startBlockId, lon
9292
* @return the block
9393
*/
9494
@Override
95-
public Optional<BlockStreamServiceGrpcProto.Block> read(long id) {
95+
public Optional<BlockStreamServiceGrpcProto.Block> read(final long id) {
9696

9797
if (blockCache.contains(id)) {
9898
return Optional.of(blockCache.get(id));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class BNLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
3737
*
3838
* @param maxEntries the maximum number of entries in the map
3939
*/
40-
BNLinkedHashMap(long maxEntries) {
40+
BNLinkedHashMap(final long maxEntries) {
4141
this.maxEntries = maxEntries;
4242
}
4343

@@ -48,7 +48,7 @@ public class BNLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
4848
* @return true if the eldest entry should be removed, false otherwise
4949
*/
5050
@Override
51-
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
51+
protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
5252

5353
if (size() > maxEntries) {
5454
return true;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ public interface BlockCache<V> {
3131
* @param block the block to insert
3232
* @return the id of the block
3333
*/
34-
Long insert(V block);
34+
Long insert(final V block);
3535

3636
/**
3737
* Retrieves a block from the cache.
3838
*
3939
* @param id the id of the block to retrieve
4040
* @return the block
4141
*/
42-
V get(Long id);
42+
V get(final Long id);
4343

4444
/**
4545
* Checks if the cache contains a block with the given id.
4646
*/
47-
boolean contains(Long id);
47+
boolean contains(final Long id);
4848
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
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());
3736

3837
/**
3938
* Constructor for the LRUCache class.
4039
*
4140
* @param maxEntries the maximum number of entries in the cache
4241
*/
43-
public LRUCache(long maxEntries) {
42+
public LRUCache(final long maxEntries) {
43+
final Logger LOGGER = Logger.getLogger(getClass().getName());
4444
LOGGER.finer("Creating LRUCache with maxEntries: " + maxEntries);
45+
4546
m = Collections.synchronizedMap(new BNLinkedHashMap<>(maxEntries));
4647
}
4748

@@ -52,8 +53,8 @@ public LRUCache(long maxEntries) {
5253
* @return the id of the block
5354
*/
5455
@Override
55-
public Long insert(BlockStreamServiceGrpcProto.Block block) {
56-
long id = block.getId();
56+
public Long insert(final BlockStreamServiceGrpcProto.Block block) {
57+
final long id = block.getId();
5758
m.putIfAbsent(id, block);
5859
return id;
5960
}
@@ -65,7 +66,7 @@ public Long insert(BlockStreamServiceGrpcProto.Block block) {
6566
* @return the block
6667
*/
6768
@Override
68-
public BlockStreamServiceGrpcProto.Block get(Long id) {
69+
public BlockStreamServiceGrpcProto.Block get(final Long id) {
6970
return m.get(id);
7071
}
7172

@@ -75,7 +76,7 @@ public BlockStreamServiceGrpcProto.Block get(Long id) {
7576
* @param id the id of the block to query
7677
*/
7778
@Override
78-
public boolean contains(Long id) {
79+
public boolean contains(final Long id) {
7980
return m.containsKey(id);
8081
}
8182
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public interface BlockStorage<V> {
3333
* @param block the block to write
3434
* @return the id of the block
3535
*/
36-
Optional<Long> write(V block);
36+
Optional<Long> write(final V block);
3737

3838
/**
3939
* Reads a block from storage.
4040
*
4141
* @param blockId the id of the block to read
4242
* @return the block
4343
*/
44-
Optional<V> read(Long blockId);
44+
Optional<V> read(final Long blockId);
4545
}

0 commit comments

Comments
 (0)