use of com.uber.cadence.PollForActivityTaskRequest in project cadence-client by uber-java.
the class ActivityPollTask method pollTask.
@Override
protected PollForActivityTaskResponse pollTask() throws TException {
options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_COUNTER).inc(1);
Stopwatch sw = options.getMetricsScope().timer(MetricsType.ACTIVITY_POLL_LATENCY).start();
PollForActivityTaskRequest pollRequest = new PollForActivityTaskRequest();
pollRequest.setDomain(domain);
pollRequest.setIdentity(options.getIdentity());
pollRequest.setTaskList(new TaskList().setName(taskList));
if (options.getTaskListActivitiesPerSecond() > 0) {
TaskListMetadata metadata = new TaskListMetadata();
metadata.setMaxTasksPerSecond(options.getTaskListActivitiesPerSecond());
pollRequest.setTaskListMetadata(metadata);
}
if (log.isDebugEnabled()) {
log.debug("poll request begin: " + pollRequest);
}
PollForActivityTaskResponse result;
try {
result = service.PollForActivityTask(pollRequest);
} catch (InternalServiceError | ServiceBusyError e) {
options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_TRANSIENT_FAILED_COUNTER).inc(1);
throw e;
} catch (TException e) {
options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_FAILED_COUNTER).inc(1);
throw e;
}
if (result == null || result.getTaskToken() == null) {
if (log.isDebugEnabled()) {
log.debug("poll request returned no task");
}
options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_NO_TASK_COUNTER).inc(1);
return null;
}
if (log.isTraceEnabled()) {
log.trace("poll request returned " + result);
}
sw.stop();
return result;
}
Aggregations