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;
 
 
 public class DynamicWorkflowClientImpl implements DynamicWorkflowClient {
 
     protected WorkflowType workflowType;
 
     protected GenericWorkflowClient genericClient;
 
 
     protected DataConverter dataConverter;
 
     protected WorkflowExecution workflowExecution;
     
 
     protected Settable<StringrunId = new Settable<String>();
 
     public DynamicWorkflowClientImpl() {
         this(nullnullnullnullnull);
     }
 
     public DynamicWorkflowClientImpl(WorkflowExecution workflowExecution) {
         this(workflowExecutionnullnullnullnull);
     }
 
     public DynamicWorkflowClientImpl(WorkflowExecution workflowExecutionWorkflowType workflowType) {
         this(workflowExecutionworkflowTypenullnullnull);
     }
 
     public DynamicWorkflowClientImpl(WorkflowExecution workflowExecutionWorkflowType workflowTypeStartWorkflowOptions options) {
         this(workflowExecutionworkflowTypeoptionsnullnull);
     }
 
     public DynamicWorkflowClientImpl(WorkflowExecution workflowExecutionWorkflowType workflowType,
             StartWorkflowOptions optionsDataConverter dataConverter) {
         this(workflowExecutionworkflowTypeoptionsdataConverternull);
     }
 
     public DynamicWorkflowClientImpl(WorkflowExecution workflowExecutionWorkflowType workflowType,
             StartWorkflowOptions optionsDataConverter dataConverterGenericWorkflowClient genericClient) {
         this. = workflowType;
         this. = workflowExecution;
         if (dataConverter == null) {
             this. = new JsonDataConverter();
         }
         else {
             this. = dataConverter;
         }
         this. = options;
         this. = genericClient;
         if (workflowExecution.getRunId() != null) {
             this..set(workflowExecution.getRunId());
         }
     }
 
     @Override
     public DataConverter getDataConverter() {
         return ;
     }
 
     @Override
         return ;
     }
 
     @Override
         return ;
     }
 
     @Override
     public Promise<StringgetRunId() {
        return ;
    }
    @Override
        return ;
    }
    @Override
    public WorkflowType getWorkflowType() {
        return ;
    }
    public void setWorkflowType(WorkflowType workflowType) {
        this. = workflowType;
    }
    public void setGenericClient(GenericWorkflowClient genericClient) {
        this. = genericClient;
    }
    public void setSchedulingOptions(StartWorkflowOptions schedulingOptions) {
        this. = schedulingOptions;
    }
    public void setDataConverter(DataConverter dataConverter) {
        this. = dataConverter;
    }
    @Override
    public void requestCancelWorkflowExecution(Promise<?>... waitFor) {
        checkWorkflowExecution();
        new Task(waitFor) {
            @Override
            protected void doExecute() throws Throwable {
                GenericWorkflowClient client = getGenericClientToUse();
                client.requestCancelWorkflowExecution();
            }
        };
    }
    private void checkWorkflowExecution() {
        if ( == null) {
            throw new IllegalStateException("required property workflowExecution is null");
        }
    }
    public <T> Promise<T> startWorkflowExecution(final Promise<Object>[] arguments,
            final StartWorkflowOptions startOptionsOverridefinal Class<T> returnTypefinal Promise<?>... waitFor) {
        checkState();
        if (.isReady()) {
             = new Settable<String>();
        }
        return new Functor<T>(arguments) {
            @Override
            protected Promise<T> doExecute() throws Throwable {
                Object[] input = new Object[arguments.length];
                for (int i = 0; i < arguments.lengthi++) {
                    Promise<Objectargument = arguments[i];
                    input[i] = argument.get();
                }
                return startWorkflowExecution(inputstartOptionsOverridereturnTypewaitFor);
            }
        };
    }
    public <T> Promise<T> startWorkflowExecution(final Object[] argumentsfinal StartWorkflowOptions startOptionsOverride,
            final Class<T> returnTypePromise<?>... waitFor) {
        checkState();
        final Settable<T> result = new Settable<T>();
        if (.isReady()) {
             = new Settable<String>();
        }
        new TryFinally(waitFor) {
            Promise<StartChildWorkflowReplyreply;
            @Override
            protected void doTry() throws Throwable {
                StartChildWorkflowExecutionParameters parameters = new StartChildWorkflowExecutionParameters();
                parameters.setWorkflowType();
                String convertedArguments = .toData(arguments);
                parameters.setInput(convertedArguments);
                parameters.setWorkflowId(.getWorkflowId());
                final StartChildWorkflowExecutionParameters startParameters = parameters.createStartChildWorkflowExecutionParametersFromOptions(
                        startOptionsOverride);
                GenericWorkflowClient client = getGenericClientToUse();
                 = client.startChildWorkflow(startParameters);
                .setDescription("runId of " + .getDescription());
                result.setDescription(.getDescription());
                new Task() {
                    @Override
                    protected void doExecute() throws Throwable {
                        if (!.isReady()) {
                            .set(.get().getRunId());
                            .setRunId(.get());
                        }
                    }
                };
            }
            @Override
            protected void doCatch(Throwable ethrows Throwable {
                if (e instanceof ChildWorkflowFailedException) {
                    ChildWorkflowFailedException taskFailedException = (ChildWorkflowFailedExceptione;
                    try {
                        String details = taskFailedException.getDetails();
                        if (details != null) {
                            Throwable cause = .fromData(detailsThrowable.class);
                            if (cause != null && taskFailedException.getCause() == null) {
                                taskFailedException.initCause(cause);
                            }
                        }
                    }
                    catch (DataConverterException dataConverterException) {
                        if (dataConverterException.getCause() == null) {
                            dataConverterException.initCause(taskFailedException);
                        }
                        throw dataConverterException;
                    }
                }
                throw e;
            }
            @Override
            protected void doFinally() throws Throwable {
                if ( != null && .isReady() && .get().getResult().isReady()) {
                    if (returnType.equals(Void.class)) {
                        result.set(null);
                    }
                    else {
                        T output = .fromData(.get().getResult().get(), returnType);
                        result.set(output);
                    }
                }
            }
        };
        return result;
    }
    @Override
    public void signalWorkflowExecution(final String signalNamefinal Object[] argumentsPromise<?>... waitFor) {
        checkWorkflowExecution();
        new Task(waitFor) {
            @Override
            protected void doExecute() throws Throwable {
                SignalExternalWorkflowParameters parameters = new SignalExternalWorkflowParameters();
                parameters.setSignalName(signalName);
                String input = .toData(arguments);
                parameters.setInput(input);
                parameters.setWorkflowId(.getWorkflowId());
                parameters.setRunId(.getRunId());
                GenericWorkflowClient client = getGenericClientToUse();
                client.signalWorkflowExecution(parameters);
            }
        };
    }
    private void checkState() {
        if ( == null) {
            throw new IllegalStateException("required property workflowType is null");
        }
        checkWorkflowExecution();
    }
        GenericWorkflowClient client;
        if ( == null) {
            client = .getDecisionContext().getWorkflowClient(); 
        } else {
            client = ;
        }
        return client;
    }
New to GrepCode? Check out our FAQ X