-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add means of awaiting event emission, fix flaky build #1463
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
Changes from 2 commits
306b74f
5bd4586
caae39d
5909f33
43c06f3
9e2cbd8
694526e
95d2271
0738f9f
3a1ce09
5ab1f68
1feacdd
6a4fa3d
c22da3e
14d8c12
596fe22
0228a70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
@Slf4j | ||
public abstract class EventProvider implements FeatureProvider { | ||
private EventProviderListener eventProviderListener; | ||
private final ExecutorService emitterExecutor = Executors.newCachedThreadPool(); | ||
|
||
void setEventProviderListener(EventProviderListener eventProviderListener) { | ||
this.eventProviderListener = eventProviderListener; | ||
|
@@ -58,16 +57,6 @@ void detach() { | |
*/ | ||
@Override | ||
public void shutdown() { | ||
emitterExecutor.shutdown(); | ||
try { | ||
if (!emitterExecutor.awaitTermination(EventSupport.SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { | ||
log.warn("Emitter executor did not terminate before the timeout period had elapsed"); | ||
emitterExecutor.shutdownNow(); | ||
} | ||
} catch (InterruptedException e) { | ||
emitterExecutor.shutdownNow(); | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -76,14 +65,21 @@ public void shutdown() { | |
* @param event The event type | ||
* @param details The details of the event | ||
*/ | ||
public void emit(ProviderEvent event, ProviderEventDetails details) { | ||
if (eventProviderListener != null) { | ||
eventProviderListener.onEmit(event, details); | ||
public void emit(final ProviderEvent event, final ProviderEventDetails details) { | ||
final var localEventProviderListener = this.eventProviderListener; | ||
final var localOnEmit = this.onEmit; | ||
|
||
if (localEventProviderListener == null && localOnEmit == null) { | ||
return; | ||
} | ||
|
||
final TriConsumer<EventProvider, ProviderEvent, ProviderEventDetails> localOnEmit = this.onEmit; | ||
if (localOnEmit != null) { | ||
emitterExecutor.submit(() -> localOnEmit.accept(this, event, details)); | ||
try (var ignored = OpenFeatureAPI.lock.readLockAutoCloseable()) { | ||
|
||
if (localEventProviderListener != null) { | ||
localEventProviderListener.onEmit(event, details); | ||
} | ||
if (localOnEmit != null) { | ||
localOnEmit.accept(this, event, details); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong, we do need it