-
Notifications
You must be signed in to change notification settings - Fork 177
Code cleanup around Pollers #1070
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 all commits
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 |
---|---|---|
|
@@ -168,15 +168,18 @@ public void awaitTermination(long timeout, TimeUnit unit) { | |
|
||
@Override | ||
public void suspendPolling() { | ||
log.info("suspendPolling: {}", this); | ||
suspendLatch.set(new CountDownLatch(1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absense of CAS here may replace and lose the latch which is already used by Pollers to block on. This way they will never be unblocked if suspentPolling was called twice. |
||
if (suspendLatch.compareAndSet(null, new CountDownLatch(1))) { | ||
log.info("Suspend Polling: {}", this); | ||
} else { | ||
log.info("Polling is already suspended: {}", this); | ||
} | ||
} | ||
|
||
@Override | ||
public void resumePolling() { | ||
log.info("resumePolling {}", this); | ||
CountDownLatch existing = suspendLatch.getAndSet(null); | ||
if (existing != null) { | ||
log.info("Resume Polling {}", this); | ||
existing.countDown(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,35 +126,33 @@ public Builder setDefaultHeartbeatThrottleInterval(Duration defaultHeartbeatThro | |
} | ||
|
||
public SingleWorkerOptions build() { | ||
PollerOptions pollerOptions = this.pollerOptions; | ||
if (pollerOptions == null) { | ||
pollerOptions = | ||
PollerOptions.newBuilder() | ||
.setPollBackoffInitialInterval(Duration.ofMillis(200)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path is dead. We come here only in some tests where we do
and these options and not important for these tests. As a result, these magic values 200 and 20 here are never used and better be removed from the production code paths to don't mislead the reader. |
||
.setPollBackoffMaximumInterval(Duration.ofSeconds(20)) | ||
.setPollThreadCount(1) | ||
.build(); | ||
pollerOptions = PollerOptions.newBuilder().build(); | ||
} | ||
|
||
DataConverter dataConverter = this.dataConverter; | ||
if (dataConverter == null) { | ||
dataConverter = DataConverter.getDefaultInstance(); | ||
} | ||
|
||
Scope metricsScope = this.metricsScope; | ||
if (metricsScope == null) { | ||
metricsScope = new NoopScope(); | ||
} | ||
|
||
return new SingleWorkerOptions( | ||
identity, | ||
binaryChecksum, | ||
this.identity, | ||
this.binaryChecksum, | ||
dataConverter, | ||
taskExecutorThreadPoolSize, | ||
this.taskExecutorThreadPoolSize, | ||
pollerOptions, | ||
metricsScope, | ||
enableLoggingInReplay, | ||
contextPropagators, | ||
defaultDeadlockDetectionTimeout, | ||
maxHeartbeatThrottleInterval, | ||
defaultHeartbeatThrottleInterval); | ||
this.enableLoggingInReplay, | ||
this.contextPropagators, | ||
this.defaultDeadlockDetectionTimeout, | ||
this.maxHeartbeatThrottleInterval, | ||
this.defaultHeartbeatThrottleInterval); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ private static SingleWorkerOptions toLocalActivityOptions( | |
List<ContextPropagator> contextPropagators, | ||
Scope metricsScope) { | ||
return toSingleWorkerOptions(factoryOptions, options, clientOptions, contextPropagators) | ||
.setPollerOptions(PollerOptions.newBuilder().build()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ActivityWorker and WorkflowWorker PollerOptions specify this parameter explicitly. |
||
.setPollerOptions(PollerOptions.newBuilder().setPollThreadCount(1).build()) | ||
.setTaskExecutorThreadPoolSize(options.getMaxConcurrentLocalActivityExecutionSize()) | ||
.setMetricsScope(metricsScope) | ||
.build(); | ||
|
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.
Paired with
in finally, this location of
return
is cleaner for the reader.