Skip to content
Merged
Changes from all commits
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
Expand Up @@ -87,6 +87,7 @@ public class FlagdProvider implements FeatureProvider, EventStreamCallback {
private int maxEventStreamRetries = DEFAULT_MAX_EVENT_STREAM_RETRIES;

private ReadWriteLock lock = new ReentrantReadWriteLock();
private Object eventStreamAliveSync;

/**
* Create a new FlagdProvider instance.
Expand Down Expand Up @@ -183,6 +184,7 @@ public FlagdProvider() {
this.eventStreamAlive = false;
this.cache = new FlagdCache(cache, maxCacheSize);
this.maxEventStreamRetries = maxEventStreamRetries;
this.eventStreamAliveSync = new Object();
this.handleEvents();
}

Expand Down Expand Up @@ -603,6 +605,9 @@ public void setEventStreamAlive(Boolean alive) {
l.lock();
this.eventStreamAlive = alive;
if (alive) {
synchronized (this.eventStreamAliveSync) {
this.eventStreamAliveSync.notify(); // notify any waiters that the event stream is alive
}
// reset attempts on successful connection
this.eventStreamAttempt = 1;
this.eventStreamRetryBackoff = BASE_EVENT_STREAM_RETRY_BACKOFF_MS;
Expand Down Expand Up @@ -630,4 +635,15 @@ public void restartEventStream() throws Exception {

this.handleEvents();
}

/**
* Call .wait() on this to block until the event stream is alive.
* Can be used in instances where the provider being connected to the event stream is a prerequisite
* to execution (e.g. testing). Not necessary for standard usage.
*
* @return eventStreamAliveSync
*/
public Object getEventStreamAliveSync() {
return this.eventStreamAliveSync;
}
}