1717
1818package com .uber .cadence .internal .worker ;
1919
20- import com .uber .cadence .InternalServiceError ;
21- import com .uber .cadence .PollForActivityTaskRequest ;
2220import com .uber .cadence .PollForActivityTaskResponse ;
2321import com .uber .cadence .RespondActivityTaskCanceledRequest ;
2422import com .uber .cadence .RespondActivityTaskCompletedRequest ;
2523import com .uber .cadence .RespondActivityTaskFailedRequest ;
26- import com .uber .cadence .ServiceBusyError ;
27- import com .uber .cadence .TaskList ;
2824import com .uber .cadence .WorkflowExecution ;
2925import com .uber .cadence .common .RetryOptions ;
3026import com .uber .cadence .internal .common .Retryer ;
@@ -88,10 +84,13 @@ public void start() {
8884 + "\" , type=\" activity\" " )
8985 .build ();
9086 }
91- Poller .ThrowingRunnable pollTask =
92- new PollTask <>(service , domain , taskList , options , new TaskHandlerImpl (handler ));
9387 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 ());
9594 poller .start ();
9695 options .getMetricsScope ().counter (MetricsType .WORKER_START_COUNTER ).inc (1 );
9796 }
@@ -150,7 +149,7 @@ public void resumePolling() {
150149 }
151150 }
152151
153- private static class MeasurableActivityTask {
152+ static class MeasurableActivityTask {
154153 PollForActivityTaskResponse task ;
155154 Stopwatch sw ;
156155
@@ -164,7 +163,7 @@ void markDone() {
164163 }
165164 }
166165
167- private class TaskHandlerImpl implements PollTask .TaskHandler <MeasurableActivityTask > {
166+ private class TaskHandlerImpl implements PollTaskExecutor .TaskHandler <MeasurableActivityTask > {
168167
169168 final ActivityTaskHandler handler ;
170169
@@ -173,9 +172,7 @@ private TaskHandlerImpl(ActivityTaskHandler handler) {
173172 }
174173
175174 @ 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 {
179176 options
180177 .getMetricsScope ()
181178 .timer (MetricsType .TASK_LIST_QUEUE_LATENCY )
@@ -215,51 +212,6 @@ public void handle(
215212 }
216213 }
217214
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-
263215 @ Override
264216 public Throwable wrapFailure (MeasurableActivityTask task , Throwable failure ) {
265217 WorkflowExecution execution = task .task .getWorkflowExecution ();
0 commit comments