Skip to content

Commit

Permalink
clarify assumptions about processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmitch committed Mar 15, 2022
1 parent 2864c52 commit 456c059
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.grpc.health;

import io.servicetalk.concurrent.PublisherSource;
import io.servicetalk.concurrent.PublisherSource.Processor;
import io.servicetalk.concurrent.api.Publisher;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.grpc.api.GrpcServiceContext;
Expand Down Expand Up @@ -148,7 +149,7 @@ public boolean setStatus(String service, ServingStatus status) {
public boolean clearStatus(String service) {
final HealthValue healthValue = serviceToStatusMap.remove(service);
if (healthValue != null) {
healthValue.complete(SERVICE_UNKNOWN);
healthValue.completeMultipleTerminalSafe(SERVICE_UNKNOWN);
return true;
}
return false;
Expand All @@ -172,13 +173,13 @@ public boolean terminate() {
lock.unlock();
}
for (final HealthValue healthValue : serviceToStatusMap.values()) {
healthValue.complete(NOT_SERVING);
healthValue.completeMultipleTerminalSafe(NOT_SERVING);
}
return true;
}

private static final class HealthValue {
private final PublisherSource.Processor<HealthCheckResponse, HealthCheckResponse> processor;
private final Processor<HealthCheckResponse, HealthCheckResponse> processor;
private final Publisher<HealthCheckResponse> publisher;
private volatile HealthCheckResponse last;

Expand All @@ -201,7 +202,12 @@ void next(HealthCheckResponse response) {
processor.onNext(response);
}

void complete(ServingStatus status) {
/**
* This method is safe to invoke multiple times. Safety is currently provided by default {@link Processor}
* implementations.
* @param status The last status to set.
*/
void completeMultipleTerminalSafe(ServingStatus status) {
next(newBuilder().setStatus(status).build());
processor.onComplete();
}
Expand Down

0 comments on commit 456c059

Please sign in to comment.