17
17
18
18
package com .uber .cadence .internal .worker ;
19
19
20
- import com .uber .cadence .InternalServiceError ;
21
- import com .uber .cadence .PollForActivityTaskRequest ;
22
20
import com .uber .cadence .PollForActivityTaskResponse ;
23
21
import com .uber .cadence .RespondActivityTaskCanceledRequest ;
24
22
import com .uber .cadence .RespondActivityTaskCompletedRequest ;
25
23
import com .uber .cadence .RespondActivityTaskFailedRequest ;
26
- import com .uber .cadence .ServiceBusyError ;
27
- import com .uber .cadence .TaskList ;
28
24
import com .uber .cadence .WorkflowExecution ;
29
25
import com .uber .cadence .common .RetryOptions ;
30
26
import com .uber .cadence .internal .common .Retryer ;
@@ -88,10 +84,13 @@ public void start() {
88
84
+ "\" , type=\" activity\" " )
89
85
.build ();
90
86
}
91
- Poller .ThrowingRunnable pollTask =
92
- new PollTask <>(service , domain , taskList , options , new TaskHandlerImpl (handler ));
93
87
poller =
94
- new Poller (pollerOptions , options .getIdentity (), pollTask , options .getMetricsScope ());
88
+ new Poller <>(
89
+ options .getIdentity (),
90
+ new ActivityPollTask (service , domain , taskList , options ),
91
+ new PollTaskExecutor <>(domain , taskList , options , new TaskHandlerImpl (handler )),
92
+ pollerOptions ,
93
+ options .getMetricsScope ());
95
94
poller .start ();
96
95
options .getMetricsScope ().counter (MetricsType .WORKER_START_COUNTER ).inc (1 );
97
96
}
@@ -150,7 +149,7 @@ public void resumePolling() {
150
149
}
151
150
}
152
151
153
- private static class MeasurableActivityTask {
152
+ static class MeasurableActivityTask {
154
153
PollForActivityTaskResponse task ;
155
154
Stopwatch sw ;
156
155
@@ -164,7 +163,7 @@ void markDone() {
164
163
}
165
164
}
166
165
167
- private class TaskHandlerImpl implements PollTask .TaskHandler <MeasurableActivityTask > {
166
+ private class TaskHandlerImpl implements PollTaskExecutor .TaskHandler <MeasurableActivityTask > {
168
167
169
168
final ActivityTaskHandler handler ;
170
169
@@ -173,9 +172,7 @@ private TaskHandlerImpl(ActivityTaskHandler handler) {
173
172
}
174
173
175
174
@ Override
176
- public void handle (
177
- IWorkflowService service , String domain , String taskList , MeasurableActivityTask task )
178
- throws Exception {
175
+ public void handle (MeasurableActivityTask task ) throws Exception {
179
176
options
180
177
.getMetricsScope ()
181
178
.timer (MetricsType .TASK_LIST_QUEUE_LATENCY )
@@ -215,51 +212,6 @@ public void handle(
215
212
}
216
213
}
217
214
218
- @ Override
219
- public MeasurableActivityTask poll (IWorkflowService service , String domain , String taskList )
220
- throws TException {
221
- options .getMetricsScope ().counter (MetricsType .ACTIVITY_POLL_COUNTER ).inc (1 );
222
- Stopwatch sw = options .getMetricsScope ().timer (MetricsType .ACTIVITY_POLL_LATENCY ).start ();
223
- Stopwatch e2eSW = options .getMetricsScope ().timer (MetricsType .ACTIVITY_E2E_LATENCY ).start ();
224
-
225
- PollForActivityTaskRequest pollRequest = new PollForActivityTaskRequest ();
226
- pollRequest .setDomain (domain );
227
- pollRequest .setIdentity (options .getIdentity ());
228
- pollRequest .setTaskList (new TaskList ().setName (taskList ));
229
- if (log .isDebugEnabled ()) {
230
- log .debug ("poll request begin: " + pollRequest );
231
- }
232
- PollForActivityTaskResponse result ;
233
- try {
234
- result = service .PollForActivityTask (pollRequest );
235
- } catch (InternalServiceError | ServiceBusyError e ) {
236
- options
237
- .getMetricsScope ()
238
- .counter (MetricsType .ACTIVITY_POLL_TRANSIENT_FAILED_COUNTER )
239
- .inc (1 );
240
- throw e ;
241
- } catch (TException e ) {
242
- options .getMetricsScope ().counter (MetricsType .ACTIVITY_POLL_FAILED_COUNTER ).inc (1 );
243
- throw e ;
244
- }
245
-
246
- if (result == null || result .getTaskToken () == null ) {
247
- if (log .isDebugEnabled ()) {
248
- log .debug ("poll request returned no task" );
249
- }
250
- options .getMetricsScope ().counter (MetricsType .ACTIVITY_POLL_NO_TASK_COUNTER ).inc (1 );
251
- return null ;
252
- }
253
-
254
- if (log .isTraceEnabled ()) {
255
- log .trace ("poll request returned " + result );
256
- }
257
-
258
- options .getMetricsScope ().counter (MetricsType .ACTIVITY_POLL_SUCCEED_COUNTER ).inc (1 );
259
- sw .stop ();
260
- return new MeasurableActivityTask (result , e2eSW );
261
- }
262
-
263
215
@ Override
264
216
public Throwable wrapFailure (MeasurableActivityTask task , Throwable failure ) {
265
217
WorkflowExecution execution = task .task .getWorkflowExecution ();
0 commit comments