use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class WorkflowExecutionUtils method getHistoryPage.
public static GetWorkflowExecutionHistoryResponse getHistoryPage(byte[] nextPageToken, IWorkflowService service, String domain, WorkflowExecution workflowExecution) {
GetWorkflowExecutionHistoryRequest getHistoryRequest = new GetWorkflowExecutionHistoryRequest();
getHistoryRequest.setDomain(domain);
getHistoryRequest.setExecution(workflowExecution);
getHistoryRequest.setNextPageToken(nextPageToken);
GetWorkflowExecutionHistoryResponse history;
try {
history = service.GetWorkflowExecutionHistory(getHistoryRequest);
} catch (TException e) {
throw new Error(e);
}
if (history == null) {
throw new IllegalArgumentException("unknown workflow execution: " + workflowExecution);
}
return history;
}
use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class TestWorkflowService method GetWorkflowExecutionHistory.
// Generator ignores that AsyncMethodCallback is generic
@SuppressWarnings("unchecked")
@Override
public void GetWorkflowExecutionHistory(GetWorkflowExecutionHistoryRequest getRequest, AsyncMethodCallback resultHandler) throws TException {
ForkJoinPool.commonPool().execute(() -> {
try {
GetWorkflowExecutionHistoryResponse result = GetWorkflowExecutionHistory(getRequest);
resultHandler.onComplete(result);
} catch (TException e) {
resultHandler.onError(e);
}
});
}
use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class TestWorkflowStoreImpl method getWorkflowExecutionHistory.
@Override
public GetWorkflowExecutionHistoryResponse getWorkflowExecutionHistory(ExecutionId executionId, GetWorkflowExecutionHistoryRequest getRequest) throws EntityNotExistsError {
HistoryStore history;
// Used to eliminate the race condition on waitForNewEvents
long expectedNextEventId;
lock.lock();
try {
history = getHistoryStore(executionId);
if (!getRequest.isWaitForNewEvent() && getRequest.getHistoryEventFilterType() != HistoryEventFilterType.CLOSE_EVENT) {
List<HistoryEvent> events = history.getEventsLocked();
// Copy the list as it is mutable. Individual events assumed immutable.
ArrayList<HistoryEvent> eventsCopy = new ArrayList<>(events);
return new GetWorkflowExecutionHistoryResponse().setHistory(new History().setEvents(eventsCopy));
}
expectedNextEventId = history.getNextEventIdLocked();
} finally {
lock.unlock();
}
List<HistoryEvent> events = history.waitForNewEvents(expectedNextEventId, getRequest.getHistoryEventFilterType());
GetWorkflowExecutionHistoryResponse result = new GetWorkflowExecutionHistoryResponse();
if (events != null) {
result.setHistory(new History().setEvents(events));
}
return result;
}
use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class WorkflowExecutionUtils method getHistory.
public static Iterator<HistoryEvent> getHistory(IWorkflowService service, String domain, WorkflowExecution workflowExecution) {
return new Iterator<HistoryEvent>() {
byte[] nextPageToken;
Iterator<HistoryEvent> current;
{
getNextPage();
}
@Override
public boolean hasNext() {
return current.hasNext() || nextPageToken != null;
}
@Override
public HistoryEvent next() {
if (current.hasNext()) {
return current.next();
}
getNextPage();
return current.next();
}
private void getNextPage() {
GetWorkflowExecutionHistoryResponse history = getHistoryPage(nextPageToken, service, domain, workflowExecution);
current = history.getHistory().getEvents().iterator();
nextPageToken = history.getNextPageToken();
}
};
}
use of com.uber.cadence.GetWorkflowExecutionHistoryResponse in project cadence-client by uber-java.
the class WorkflowExecutionUtils method getInstanceCloseEventAsync.
private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(IWorkflowService service, String domain, final WorkflowExecution workflowExecution, byte[] pageToken, long timeout, TimeUnit unit) {
// TODO: Interrupt service long poll call on timeout and on interrupt
long start = System.currentTimeMillis();
CompletableFuture<HistoryEvent> result = new CompletableFuture<>();
GetWorkflowExecutionHistoryRequest request = new GetWorkflowExecutionHistoryRequest();
request.setDomain(domain);
request.setExecution(workflowExecution);
request.setHistoryEventFilterType(HistoryEventFilterType.CLOSE_EVENT);
request.setNextPageToken(pageToken);
CompletableFuture<GetWorkflowExecutionHistoryResponse> response = getWorkflowExecutionHistoryAsync(service, request);
return response.thenComposeAsync((r) -> {
if (timeout != 0 && System.currentTimeMillis() - start > unit.toMillis(timeout)) {
throw CheckedExceptionWrapper.wrap(new TimeoutException("WorkflowId=" + workflowExecution.getWorkflowId() + ", runId=" + workflowExecution.getRunId() + ", timeout=" + timeout + ", unit=" + unit));
}
History history = r.getHistory();
if (history == null || history.getEvents().size() == 0) {
// Empty poll returned
return getInstanceCloseEventAsync(service, domain, workflowExecution, pageToken, timeout, unit);
}
HistoryEvent event = history.getEvents().get(0);
if (!isWorkflowExecutionCompletedEvent(event)) {
throw new RuntimeException("Last history event is not completion event: " + event);
}
// Workflow called continueAsNew. Start polling the new generation with new runId.
if (event.getEventType() == EventType.WorkflowExecutionContinuedAsNew) {
WorkflowExecution nextWorkflowExecution = new WorkflowExecution().setWorkflowId(workflowExecution.getWorkflowId()).setRunId(event.getWorkflowExecutionContinuedAsNewEventAttributes().getNewExecutionRunId());
return getInstanceCloseEventAsync(service, domain, nextWorkflowExecution, r.getNextPageToken(), timeout, unit);
}
return CompletableFuture.completedFuture(event);
});
}
Aggregations