Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.worker;
 
 import java.util.List;
 
 
 
 public class AsyncDecisionTaskHandler extends DecisionTaskHandler {
 
     private static final Log log = LogFactory.getLog(AsyncDecisionTaskHandler.class);
 
     private static final Log asyncThreadDumpLog = LogFactory.getLog(AsyncDecisionTaskHandler.class.getName()
             + ".waitingTasksStacks");
 
 
     public AsyncDecisionTaskHandler(WorkflowDefinitionFactoryFactory definitionFactoryFactory) {
         this. = definitionFactoryFactory;
     }
 
     @Override
     public RespondDecisionTaskCompletedRequest handleDecisionTask(Iterator<DecisionTaskdecisionTaskIteratorthrows Exception {
         HistoryHelper historyHelper = new HistoryHelper(decisionTaskIterator);
         AsyncDecider decider = createDecider(historyHelper);
         decider.decide();
         DecisionsHelper decisionsHelper = decider.getDecisionsHelper();
         Collection<Decisiondecisions = decisionsHelper.getDecisions();
         String context = decisionsHelper.getWorkflowContextDataToReturn();
         DecisionTask decisionTask = historyHelper.getDecisionTask();
         if (.isDebugEnabled()) {
             .debug("WorkflowTask taskId=" + decisionTask.getStartedEventId() + ", taskToken=" + decisionTask.getTaskToken()
                     + " completed with " + decisions.size() + " new decisions");
         }
         if (decisions.size() == 0 && .isTraceEnabled()) {
             .trace("Empty decision list with the following waiting tasks:\n"
                     + decider.getAsynchronousThreadDumpAsString());
         }
         RespondDecisionTaskCompletedRequest completedRequest = new RespondDecisionTaskCompletedRequest();
         completedRequest.setTaskToken(decisionTask.getTaskToken());
         completedRequest.setDecisions(decisions);
         completedRequest.setExecutionContext(context);
         return completedRequest;
     }
 
     @Override
     public WorkflowDefinition loadWorkflowThroughReplay(Iterator<DecisionTaskdecisionTaskIteratorthrows Exception {
         HistoryHelper historyHelper = new HistoryHelper(decisionTaskIterator);
         AsyncDecider decider = createDecider(historyHelper);
         decider.decide();
         DecisionsHelper decisionsHelper = decider.getDecisionsHelper();
         if (decisionsHelper.isWorkflowFailed()) {
             throw new IllegalStateException("Cannot load failed workflow"decisionsHelper.getWorkflowFailureCause());
         }
         return decider.getWorkflowDefinition();
     }
 
     @Override
     public List<AsyncTaskInfogetAsynchronousThreadDump(Iterator<DecisionTaskdecisionTaskIteratorthrows Exception {
         HistoryHelper historyHelper = new HistoryHelper(decisionTaskIterator);
         AsyncDecider decider = createDecider(historyHelper);
         decider.decide();
         return decider.getAsynchronousThreadDump();
     }
 
     @Override
     public String getAsynchronousThreadDumpAsString(Iterator<DecisionTaskdecisionTaskIteratorthrows Exception {
         HistoryHelper historyHelper = new HistoryHelper(decisionTaskIterator);
         AsyncDecider decider = createDecider(historyHelper);
         decider.decide();
         return decider.getAsynchronousThreadDumpAsString();
     }
 
     private AsyncDecider createDecider(HistoryHelper historyHelperthrows Exception {
         DecisionTask decisionTask = historyHelper.getDecisionTask();
        WorkflowType workflowType = decisionTask.getWorkflowType();
        if (.isDebugEnabled()) {
            .debug("WorkflowTask received: taskId=" + decisionTask.getStartedEventId() + ", taskToken="
                    + decisionTask.getTaskToken() + ", workflowExecution=" + decisionTask.getWorkflowExecution());
        }
        WorkflowDefinitionFactory workflowDefinitionFactory = .getWorkflowDefinitionFactory(workflowType);
        if (workflowDefinitionFactory == null) {
            .error("Received decision task for workflow type not configured with a worker: workflowType="
                    + decisionTask.getWorkflowType() + ", taskToken=" + decisionTask.getTaskToken() + ", workflowExecution="
                    + decisionTask.getWorkflowExecution());
            if (workflowDefinitionFactory == null) {
                throw new IllegalArgumentException("No implementation was found for " + decisionTask.getWorkflowType());
            }
        }
        DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask);
        AsyncDecider decider = new AsyncDecider(workflowDefinitionFactoryhistoryHelperdecisionsHelper);
        return decider;
    }
New to GrepCode? Check out our FAQ X