All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.simpleworkflow.flow.WorkflowClientFactoryBase Maven / Gradle / Ivy

Go to download

The Amazon Web Services SDK for Java provides Java APIs for building software on AWS' cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).

The newest version!
/*
 * Copyright 2012-2014 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;

import com.amazonaws.services.simpleworkflow.flow.generic.GenericWorkflowClient;
import com.amazonaws.services.simpleworkflow.model.WorkflowExecution;

public abstract class WorkflowClientFactoryBase implements WorkflowClientFactory {

    private GenericWorkflowClient genericClient;

    private DataConverter dataConverter;

    private StartWorkflowOptions startWorkflowOptions = new StartWorkflowOptions();

    private final DecisionContextProvider decisionContextProvider = new DecisionContextProviderImpl();

    public WorkflowClientFactoryBase() {
        this(null, null, null);
    }

    public WorkflowClientFactoryBase(StartWorkflowOptions startWorkflowOptions) {
        this(startWorkflowOptions, null, null);
    }

    public WorkflowClientFactoryBase(StartWorkflowOptions startWorkflowOptions, DataConverter dataConverter) {
        this(startWorkflowOptions, dataConverter, null);
    }

    public WorkflowClientFactoryBase(StartWorkflowOptions startWorkflowOptions, DataConverter dataConverter,
            GenericWorkflowClient genericClient) {
        this.startWorkflowOptions = startWorkflowOptions;
        if (dataConverter == null) {
            this.dataConverter = new JsonDataConverter();
        }
        else {
            this.dataConverter = dataConverter;
        }
        this.genericClient = genericClient;
    }

    @Override
    public GenericWorkflowClient getGenericClient() {
        return genericClient;
    }

    @Override
    public void setGenericClient(GenericWorkflowClient genericClient) {
        this.genericClient = genericClient;
    }

    @Override
    public DataConverter getDataConverter() {
        return dataConverter;
    }

    @Override
    public void setDataConverter(DataConverter dataConverter) {
        this.dataConverter = dataConverter;
    }

    @Override
    public StartWorkflowOptions getStartWorkflowOptions() {
        return startWorkflowOptions;
    }

    @Override
    public void setStartWorkflowOptions(StartWorkflowOptions startWorkflowOptions) {
        this.startWorkflowOptions = startWorkflowOptions;
    }

    @Override
    public T getClient() {
    	GenericWorkflowClient client = getGenericClientToUse();
        String workflowId = client.generateUniqueId();
        WorkflowExecution execution = new WorkflowExecution().withWorkflowId(workflowId);
        return getClient(execution, startWorkflowOptions, dataConverter);
    }

    @Override
    public T getClient(String workflowId) {
        if (workflowId == null || workflowId.isEmpty()) {
            throw new IllegalArgumentException("workflowId");
        }
        WorkflowExecution execution = new WorkflowExecution().withWorkflowId(workflowId);
        return getClient(execution, startWorkflowOptions, dataConverter);
    }

    @Override
    public T getClient(WorkflowExecution execution) {
        return getClient(execution, startWorkflowOptions, dataConverter);
    }

    @Override
    public T getClient(WorkflowExecution execution, StartWorkflowOptions options) {
        return getClient(execution, options, dataConverter);
    }

    @Override
    public T getClient(WorkflowExecution execution, StartWorkflowOptions options, DataConverter dataConverter) {
        GenericWorkflowClient client = getGenericClientToUse();
		return createClientInstance(execution, options, dataConverter, client);
    }

	private GenericWorkflowClient getGenericClientToUse() {
		GenericWorkflowClient result;
        if (genericClient == null) {
            result = decisionContextProvider.getDecisionContext().getWorkflowClient();
        } else {
        	result = genericClient;
        }
        return result;
	}

    protected abstract T createClientInstance(WorkflowExecution execution, StartWorkflowOptions options,
            DataConverter dataConverter, GenericWorkflowClient genericClient);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy