Skip to content

server: Refactor stream observer #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.envoyproxy.controlplane.cache;

import io.envoyproxy.envoy.api.v2.DiscoveryRequest;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import java.util.concurrent.Executor;
import java.util.function.Supplier;

/**
* {@code AdsDiscoveryRequestStreamObserver} is an implementation of {@link DiscoveryRequestStreamObserver} tailored for
* ADS streams, which handle multiple watches for all TYPE_URLS.
*/
public class AdsDiscoveryRequestStreamObserver extends DiscoveryRequestStreamObserver {
private final ConcurrentMap<String, Watch> watches;
private final ConcurrentMap<String, DiscoveryResponse> latestResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* {@code DiscoveryRequestStreamObserver} is provides the base implementation for XDS stream handling.
*/
public abstract class DiscoveryRequestStreamObserver implements StreamObserver<DiscoveryRequest> {
private static final AtomicLongFieldUpdater<DiscoveryRequestStreamObserver> streamNonceUpdater =
AtomicLongFieldUpdater.newUpdater(DiscoveryRequestStreamObserver.class, "streamNonce");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
import java.util.concurrent.Executor;
import java.util.function.Supplier;

/**
* {@code XdsDiscoveryRequestStreamObserver} is a lightweight implementation of {@link DiscoveryRequestStreamObserver}
* tailored for non-ADS streams which handle a single watch.
*/
public class XdsDiscoveryRequestStreamObserver extends DiscoveryRequestStreamObserver {
private volatile Watch watch;
private volatile DiscoveryResponse latestResponse;
// ackedResources is only used in the same thread so it need not be volatile
private Set<String> ackedResources;

XdsDiscoveryRequestStreamObserver(String defaultTypeUrl,
Expand Down