use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.
the class ReplayWorkflowRunTaskHandler method executeQueries.
private void executeQueries(Map<String, WorkflowQuery> queries) {
for (Map.Entry<String, WorkflowQuery> entry : queries.entrySet()) {
WorkflowQuery query = entry.getValue();
try {
Optional<Payloads> queryResult = replayWorkflowExecutor.query(query);
WorkflowQueryResult.Builder result = WorkflowQueryResult.newBuilder().setResultType(QueryResultType.QUERY_RESULT_TYPE_ANSWERED);
if (queryResult.isPresent()) {
result.setAnswer(queryResult.get());
}
queryResults.put(entry.getKey(), result.build());
} catch (Exception e) {
String stackTrace = Throwables.getStackTraceAsString(e);
queryResults.put(entry.getKey(), WorkflowQueryResult.newBuilder().setResultType(QueryResultType.QUERY_RESULT_TYPE_FAILED).setErrorMessage(e.toString() + "\n" + stackTrace).build());
}
}
}
use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.
the class ActivityStateMachine method notifyCompleted.
private void notifyCompleted() {
ActivityTaskCompletedEventAttributes completedAttr = currentEvent.getActivityTaskCompletedEventAttributes();
Optional<Payloads> result = completedAttr.hasResult() ? Optional.of(completedAttr.getResult()) : Optional.empty();
completionCallback.apply(result, null);
}
use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.
the class ChildWorkflowStateMachine method notifyCompleted.
private void notifyCompleted() {
ChildWorkflowExecutionCompletedEventAttributes attributes = currentEvent.getChildWorkflowExecutionCompletedEventAttributes();
Optional<Payloads> result = attributes.hasResult() ? Optional.of(attributes.getResult()) : Optional.empty();
completionCallback.apply(result, null);
}
use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.
the class WorkflowExecutionUtils method getResultFromCloseEvent.
public static Optional<Payloads> getResultFromCloseEvent(WorkflowExecution workflowExecution, Optional<String> workflowType, HistoryEvent closeEvent, DataConverter converter) {
if (closeEvent == null) {
throw new IllegalStateException("Workflow is still running");
}
switch(closeEvent.getEventType()) {
case EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED:
WorkflowExecutionCompletedEventAttributes completedEventAttributes = closeEvent.getWorkflowExecutionCompletedEventAttributes();
if (completedEventAttributes.hasResult()) {
return Optional.of(completedEventAttributes.getResult());
}
return Optional.empty();
case EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED:
String message = null;
WorkflowExecutionCanceledEventAttributes attributes = closeEvent.getWorkflowExecutionCanceledEventAttributes();
Optional<Payloads> details = attributes.hasDetails() ? Optional.of(attributes.getDetails()) : Optional.empty();
throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new CanceledFailure("Workflow canceled", new EncodedValues(details, converter), null));
case EVENT_TYPE_WORKFLOW_EXECUTION_FAILED:
WorkflowExecutionFailedEventAttributes failed = closeEvent.getWorkflowExecutionFailedEventAttributes();
throw new WorkflowExecutionFailedException(failed.getFailure(), failed.getWorkflowTaskCompletedEventId(), failed.getRetryState());
case EVENT_TYPE_WORKFLOW_EXECUTION_TERMINATED:
WorkflowExecutionTerminatedEventAttributes terminated = closeEvent.getWorkflowExecutionTerminatedEventAttributes();
throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE, new TerminatedFailure(terminated.getReason(), null));
case EVENT_TYPE_WORKFLOW_EXECUTION_TIMED_OUT:
WorkflowExecutionTimedOutEventAttributes timedOut = closeEvent.getWorkflowExecutionTimedOutEventAttributes();
throw new WorkflowFailedException(workflowExecution, workflowType.orElse(null), 0, timedOut.getRetryState(), new TimeoutFailure(null, null, TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE));
default:
throw new RuntimeException("Workflow end state is not completed: " + WorkflowExecutionUtils.prettyPrintObject(closeEvent));
}
}
use of io.temporal.api.common.v1.Payloads in project sdk-java by temporalio.
the class ReplayWorkflowExecutor method handleWorkflowExecutionSignaled.
public void handleWorkflowExecutionSignaled(HistoryEvent event) {
WorkflowExecutionSignaledEventAttributes signalAttributes = event.getWorkflowExecutionSignaledEventAttributes();
if (completed) {
throw new IllegalStateException("Signal received after workflow is closed.");
}
Optional<Payloads> input = signalAttributes.hasInput() ? Optional.of(signalAttributes.getInput()) : Optional.empty();
this.workflow.handleSignal(signalAttributes.getSignalName(), input, event.getEventId());
}
Aggregations