|
31 | 31 | * the downstream consumer via the notify method and manage the bidirectional stream to the consumer
|
32 | 32 | * via the onNext, onError, and onCompleted methods.
|
33 | 33 | */
|
34 |
| -public class ConsumerBlockItemObserver |
35 |
| - implements BlockItemEventHandler<ObjectEvent<BlockItem>, SubscribeStreamRequest> { |
| 34 | +public class ConsumerBlockItemObserver implements BlockItemEventHandler<ObjectEvent<BlockItem>> { |
36 | 35 |
|
37 | 36 | private final System.Logger LOGGER = System.getLogger(getClass().getName());
|
38 | 37 |
|
@@ -89,55 +88,19 @@ public ConsumerBlockItemObserver(
|
89 | 88 | @Override
|
90 | 89 | public void onEvent(final ObjectEvent<BlockItem> event, final long l, final boolean b) {
|
91 | 90 |
|
92 |
| - // Refresh the producer liveness and pass the block to the observer. |
93 |
| - producerLivenessMillis = producerLivenessClock.millis(); |
94 |
| - |
95 |
| - final BlockItem blockItem = event.get(); |
96 |
| - final SubscribeStreamResponse subscribeStreamResponse = |
97 |
| - SubscribeStreamResponse.newBuilder().setBlockItem(blockItem).build(); |
98 |
| - |
99 |
| - subscribeStreamResponseObserver.onNext(subscribeStreamResponse); |
100 |
| - } |
101 |
| - |
102 |
| - /** |
103 |
| - * The onNext() method is triggered by Helidon when a consumer sends a blockResponse via the |
104 |
| - * bidirectional stream. |
105 |
| - */ |
106 |
| - @Override |
107 |
| - public void onNext(final SubscribeStreamRequest subscribeStreamRequest) { |
108 |
| - |
109 |
| - // Check if the producer has timed out. If so, unsubscribe the observer from the mediator. |
110 | 91 | if (isThresholdExceeded(producerLivenessMillis)) {
|
111 |
| - LOGGER.log( |
112 |
| - System.Logger.Level.DEBUG, |
113 |
| - "Producer timeout threshold exceeded. Unsubscribing observer."); |
114 | 92 | streamMediator.unsubscribe(this);
|
115 |
| - } |
116 |
| - } |
| 93 | + } else { |
117 | 94 |
|
118 |
| - /** |
119 |
| - * The onError() method is triggered by Helidon when an error occurs on the bidirectional stream |
120 |
| - * to the downstream consumer. Unsubscribe the observer from the mediator. |
121 |
| - * |
122 |
| - * @param t the error occurred on the stream |
123 |
| - */ |
124 |
| - @Override |
125 |
| - public void onError(final Throwable t) { |
126 |
| - LOGGER.log( |
127 |
| - System.Logger.Level.ERROR, |
128 |
| - "Unexpected consumer stream communication failure: %s".formatted(t), |
129 |
| - t); |
130 |
| - } |
| 95 | + // Refresh the producer liveness and pass the block to the observer. |
| 96 | + producerLivenessMillis = producerLivenessClock.millis(); |
131 | 97 |
|
132 |
| - /** |
133 |
| - * The onCompleted() method is triggered by Helidon when the bidirectional stream to the |
134 |
| - * downstream consumer is completed. This implementation will then unsubscribe the observer from |
135 |
| - * the mediator. |
136 |
| - */ |
137 |
| - @Override |
138 |
| - public void onCompleted() { |
139 |
| - LOGGER.log(System.Logger.Level.DEBUG, "gRPC connection completed."); |
140 |
| - streamMediator.unsubscribe(this); |
| 98 | + final BlockItem blockItem = event.get(); |
| 99 | + final SubscribeStreamResponse subscribeStreamResponse = |
| 100 | + SubscribeStreamResponse.newBuilder().setBlockItem(blockItem).build(); |
| 101 | + |
| 102 | + subscribeStreamResponseObserver.onNext(subscribeStreamResponse); |
| 103 | + } |
141 | 104 | }
|
142 | 105 |
|
143 | 106 | private boolean isThresholdExceeded(long livenessMillis) {
|
|
0 commit comments