All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.grpc.runtime.devmode.DevModeStreamsCollector Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
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) {
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy