io.quarkus.grpc.runtime.devmode.DevModeStreamsCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-grpc Show documentation
Show all versions of quarkus-grpc Show documentation
Serve and consume gRPC services
package io.quarkus.grpc.runtime.devmode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import io.grpc.stub.StreamObserver;
import io.quarkus.grpc.stubs.StreamCollector;
public class DevModeStreamsCollector implements StreamCollector {
private final Set> streamObservers = new HashSet<>();
@Override
public void add(StreamObserver observer) {
synchronized (this) {
streamObservers.add(observer);
}
}
@Override
public void remove(StreamObserver observer) {
synchronized (this) {
streamObservers.remove(observer);
}
}
public void shutdown() {
List> observers;
synchronized (this) {
observers = new ArrayList<>(streamObservers);
}
observers.forEach(this::complete);
}
private void complete(StreamObserver> streamObserver) {
try {
streamObserver.onCompleted();
} catch (Exception ignored) {
}
}
}