Skip to content

Commit 7744a13

Browse files
removed import
Signed-off-by: Matt Peterson <[email protected]>
1 parent 6df6c45 commit 7744a13

File tree

6 files changed

+22
-27
lines changed

6 files changed

+22
-27
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import com.google.protobuf.Descriptors;
2020
import com.hedera.block.protos.BlockStreamServiceGrpcProto;
21-
import com.hedera.block.server.consumer.LiveStreamObserver;
22-
import com.hedera.block.server.consumer.LiveStreamObserverImpl;
21+
import com.hedera.block.server.consumer.ConsumerBlockStreamObserver;
22+
import com.hedera.block.server.consumer.ConsumerBlockStreamObserverImpl;
2323
import com.hedera.block.server.persistence.BlockPersistenceHandler;
2424
import com.hedera.block.server.producer.ProducerBlockStreamObserver;
2525
import io.grpc.stub.StreamObserver;
@@ -116,14 +116,14 @@ private StreamObserver<BlockStreamServiceGrpcProto.BlockResponse> streamSource(f
116116
LOGGER.log(System.Logger.Level.DEBUG, "Executing bidirectional streamSource method");
117117

118118
// Return a custom StreamObserver to handle streaming blocks from the producer.
119-
LiveStreamObserver<BlockStreamServiceGrpcProto.BlockResponse> liveStreamObserver = new LiveStreamObserverImpl(
119+
final ConsumerBlockStreamObserver<BlockStreamServiceGrpcProto.BlockResponse> consumerBlockStreamObserver = new ConsumerBlockStreamObserverImpl(
120120
timeoutThresholdMillis,
121121
Clock.systemDefaultZone(),
122122
blockPersistenceHandler,
123123
responseStreamObserver);
124124

125-
liveStreamObserver.emitBlocks();
126-
return liveStreamObserver;
125+
consumerBlockStreamObserver.emitBlocks();
126+
return consumerBlockStreamObserver;
127127
}
128128
}
129129

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.helidon.config.Config;
2626
import io.helidon.webserver.WebServer;
2727
import io.helidon.webserver.grpc.GrpcRouting;
28-
import io.helidon.webserver.http.HttpRouting;
2928

3029
import java.io.IOException;
3130
import java.util.stream.Stream;
@@ -38,7 +37,7 @@
3837
public class Server {
3938

4039
// Function stubs to satisfy the bidi routing param signatures. The implementations are in the service class.
41-
private static ServerCalls.BidiStreamingMethod<Stream<BlockStreamServiceGrpcProto.Block>, StreamObserver<BlockStreamServiceGrpcProto.Block>> clientBidiStreamingMethod;
40+
private static ServerCalls.BidiStreamingMethod<Stream<BlockStreamServiceGrpcProto.Block>, StreamObserver<BlockStreamServiceGrpcProto.BlockResponse>> clientBidiStreamingMethod;
4241
private static ServerCalls.BidiStreamingMethod<Stream<BlockStreamServiceGrpcProto.BlockResponse>, StreamObserver<BlockStreamServiceGrpcProto.Block>> serverBidiStreamingMethod;
4342

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

server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserver.java renamed to server/src/main/java/com/hedera/block/server/consumer/ConsumerBlockStreamObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @param <V> the type of the StreamObserver
2828
*/
29-
public interface LiveStreamObserver<V> extends StreamObserver<V> {
29+
public interface ConsumerBlockStreamObserver<V> extends StreamObserver<V> {
3030

3131
/**
3232
*/

server/src/main/java/com/hedera/block/server/consumer/LiveStreamObserverImpl.java renamed to server/src/main/java/com/hedera/block/server/consumer/ConsumerBlockStreamObserverImpl.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* The LiveStreamObserverImpl class implements the LiveStreamObserver interface to pass blocks to the downstream consumer
2929
* via the notify method and manage the bidirectional stream to the consumer via the onNext, onError, and onCompleted methods.
3030
*/
31-
public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamServiceGrpcProto.BlockResponse> {
31+
public class ConsumerBlockStreamObserverImpl implements ConsumerBlockStreamObserver<BlockStreamServiceGrpcProto.BlockResponse> {
3232

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

@@ -37,14 +37,14 @@ public class LiveStreamObserverImpl implements LiveStreamObserver<BlockStreamSer
3737

3838
private final long timeoutThresholdMillis;
3939
private final AtomicLong consumerLivenessMillis;
40-
private final AtomicLong counter;
40+
private long counter;
4141

4242
/**
4343
* Constructor for the LiveStreamObserverImpl class.
4444
*
4545
* @param responseStreamObserver the response stream observer
4646
*/
47-
public LiveStreamObserverImpl(
47+
public ConsumerBlockStreamObserverImpl(
4848
final long timeoutThresholdMillis,
4949
final InstantSource consumerLivenessClock,
5050
final BlockPersistenceHandler<BlockStreamServiceGrpcProto.Block> blockPersistenceHandler,
@@ -55,8 +55,7 @@ public LiveStreamObserverImpl(
5555
this.responseStreamObserver = responseStreamObserver;
5656

5757
this.consumerLivenessMillis = new AtomicLong(consumerLivenessClock.millis());
58-
// this.counter = new AtomicLong(blockPersistenceHandler.getLastBlockId());
59-
this.counter = new AtomicLong(1);
58+
this.counter = blockPersistenceHandler.getLastBlockId();
6059
}
6160

6261
/**
@@ -77,11 +76,13 @@ public void onNext(final BlockStreamServiceGrpcProto.BlockResponse blockResponse
7776

7877
@Override
7978
public void emitBlocks() {
80-
final long latestBlockId = counter.get();
81-
for (BlockStreamServiceGrpcProto.Block block : blockPersistenceHandler.readRange(latestBlockId, latestBlockId + 1)) {
82-
LOGGER.log(System.Logger.Level.INFO, "Thread: {0}-{1}, Emitting block: {2}", Thread.currentThread().threadId(), Thread.currentThread().getName(), block.getId());
83-
responseStreamObserver.onNext(block);
84-
counter.incrementAndGet();
79+
long latestBlockId = blockPersistenceHandler.getLastBlockId();
80+
if (counter <= latestBlockId) {
81+
for (BlockStreamServiceGrpcProto.Block block : blockPersistenceHandler.readRange(counter, latestBlockId)) {
82+
LOGGER.log(System.Logger.Level.INFO, "Thread: {0}-{1}, Emitting block: {2}", Thread.currentThread().threadId(), Thread.currentThread().getName(), block.getId());
83+
responseStreamObserver.onNext(block);
84+
counter += 1;
85+
}
8586
}
8687
}
8788

@@ -108,7 +109,7 @@ public void onCompleted() {
108109
private boolean isThresholdExceeded() {
109110
final long currentTimeMillis = Clock.systemDefaultZone().millis();
110111
final long elapsedMillis = currentTimeMillis - consumerLivenessMillis.get();
111-
if (elapsedMillis> timeoutThresholdMillis) {
112+
if (elapsedMillis > timeoutThresholdMillis) {
112113
LOGGER.log(System.Logger.Level.INFO, "Elapsed milliseconds: " + elapsedMillis + ", timeout threshold: " + timeoutThresholdMillis);
113114
return true;
114115
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,9 @@ public Long getLastBlockId() {
6868
@Override
6969
public Queue<BlockStreamServiceGrpcProto.Block> readRange(final long startBlockId, final long endBlockId) {
7070
final Queue<BlockStreamServiceGrpcProto.Block> blocks = new LinkedList<>();
71-
72-
long count = startBlockId;
73-
Optional<BlockStreamServiceGrpcProto.Block> blockOpt = read(count);
74-
while (count <= endBlockId && blockOpt.isPresent()) {
75-
final BlockStreamServiceGrpcProto.Block block = blockOpt.get();
76-
blocks.add(block);
77-
blockOpt = read(++count);
71+
for (long count = startBlockId; count <= endBlockId; count++) {
72+
final Optional<BlockStreamServiceGrpcProto.Block> blockOpt = read(count);
73+
blockOpt.ifPresent(blocks::add);
7874
}
7975

8076
return blocks;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.IOException;
2626
import java.nio.file.Files;
2727
import java.nio.file.Path;
28-
import java.nio.file.StandardOpenOption;
2928
import java.util.Optional;
3029
import java.util.concurrent.atomic.AtomicLong;
3130

0 commit comments

Comments
 (0)