Example usage for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflowClient AmazonSimpleWorkflowClient

List of usage examples for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflowClient AmazonSimpleWorkflowClient

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleworkflow AmazonSimpleWorkflowClient AmazonSimpleWorkflowClient.

Prototype

AmazonSimpleWorkflowClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled) 

Source Link

Document

Constructs a new client to invoke service methods on Amazon SWF using the specified parameters.

Usage

From source file:clojusc.aws.examples.swf.javaapp.GreeterMain.java

License:Open Source License

public static void main() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withSocketTimeout(GreeterConstants.clientTimeout);

    AWSCredentials creds = new BasicAWSCredentials(System.getenv(GreeterConstants.accessKey),
            System.getenv(GreeterConstants.secretKey));

    AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(creds, config);
    service.setEndpoint(GreeterConstants.endpoint);

    GreeterWorkflowClientExternalFactory factory = new GreeterWorkflowClientExternalFactoryImpl(service,
            GreeterConstants.domain);// w  w w. j a  v  a  2  s. co m
    GreeterWorkflowClientExternal greeter = factory.getClient(GreeterConstants.clientId);
    greeter.greet();
}

From source file:clojusc.aws.examples.swf.javaapp.GreeterWorker.java

License:Open Source License

public static void main() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withSocketTimeout(GreeterConstants.clientTimeout);

    AWSCredentials creds = new BasicAWSCredentials(System.getenv(GreeterConstants.accessKey),
            System.getenv(GreeterConstants.secretKey));

    AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(creds, config);
    service.setEndpoint(GreeterConstants.endpoint);

    ActivityWorker aw = new ActivityWorker(service, GreeterConstants.domain, GreeterConstants.taskListToPoll);
    aw.addActivitiesImplementation(new GreeterActivitiesImpl());
    aw.start();/*from   w w  w  . j a v  a  2 s  .  c  o  m*/

    WorkflowWorker wfw = new WorkflowWorker(service, GreeterConstants.domain, GreeterConstants.taskListToPoll);
    wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class);
    wfw.start();
}

From source file:com.eucalyptus.simpleworkflow.common.client.Config.java

License:Open Source License

public static AmazonSimpleWorkflow buildClient(final Supplier<User> user, final String text)
        throws AuthException {
    final AWSCredentialsProvider credentialsProvider = new SecurityTokenAWSCredentialsProvider(user);
    final AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(credentialsProvider,
            buildConfiguration(text));//from  w w w .  jav a  2s  . c o  m
    client.setEndpoint(ServiceUris.remote(Topology.lookup(SimpleWorkflow.class)).toString());
    client.addRequestHandler(new RequestHandler2() {
        @Override
        public void beforeRequest(final Request<?> request) {
            // Add nonce to ensure unique request signature
            request.addHeader("Euca-Nonce", UUID.randomUUID().toString());
        }

        @Override
        public void afterResponse(final Request<?> request, final Response<?> response) {
        }

        @Override
        public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
            final String errorMessage = Strings.nullToEmpty(e.getMessage());
            boolean resetEndpoint = false;
            if (Exceptions.isCausedBy(e, JSONException.class) && (errorMessage.contains("Response Code: 404")
                    || errorMessage.contains("Response Code: 503"))) {
                resetEndpoint = true;
            } else if (Exceptions.isCausedBy(e, ConnectException.class)) {
                resetEndpoint = true;
            } else if (Exceptions.isCausedBy(e, NoHttpResponseException.class)) {
                resetEndpoint = true;
            }
            if (resetEndpoint) {
                try {
                    client.setEndpoint(ServiceUris.remote(Topology.lookup(SimpleWorkflow.class)).toString());
                } catch (final Exception e2) {
                    // retry on next failure
                }
            }

            if (e instanceof AmazonServiceException) {
                final int status = ((AmazonServiceException) e).getStatusCode();
                if (status == 403) {
                    credentialsProvider.refresh();
                }
            }
        }
    });
    return client;
}

From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java

License:Open Source License

private AmazonSimpleWorkflow getAWSClient() {
    final AWSCredentialsProvider provider = this.getCredentialsProvider();
    final ClientConfiguration configuration = this.buildClientConfig();
    final AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(provider, configuration);
    client.setEndpoint(this.swfEndpoint);
    return client;
}

From source file:org.apache.camel.component.aws.swf.SWFEndpoint.java

License:Apache License

private AmazonSimpleWorkflowClient createSWClient() throws Exception {
    AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
            configuration.getSecretKey());

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    if (!configuration.getClientConfigurationParameters().isEmpty()) {
        setProperties(clientConfiguration, configuration.getClientConfigurationParameters());
    }//from  www .  ja v  a 2s.  c o  m

    AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(credentials, clientConfiguration);
    if (!configuration.getsWClientParameters().isEmpty()) {
        setProperties(client, configuration.getsWClientParameters());
    }
    return client;
}

From source file:org.diksha.common.dyutils.SchedulerUDE.java

License:Apache License

public static SchedulerWorkflowClientExternal getScheduler(String clientId, SchedulerConfig schedulerConfig) {
    AWSCredentials awsCredentials = DyDBUtils.getAwsCredentials();

    ClientConfiguration config = new ClientConfiguration()
            .withSocketTimeout(Integer.parseInt(schedulerConfig.getSocketTimeout()));
    AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(awsCredentials, config);

    service.setEndpoint(schedulerConfig.getEndPoint());
    String domain = schedulerConfig.getDomain();

    SchedulerWorkflowClientExternalFactory factory = new SchedulerWorkflowClientExternalFactoryImpl(service,
            domain);/*from   w w  w  .  ja va 2s  .  c om*/

    SchedulerWorkflowClientExternal scheduler = factory.getClient(clientId);

    return scheduler;
}

From source file:org.diksha.engine.SchedulerWorker.java

License:Apache License

public static void main(String[] args) throws Exception {

    ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70 * 1000);

    String swfAccessId = System.getenv("AWS_ACCESS_KEY_ID");
    String swfSecretKey = System.getenv("AWS_SECRET_ACCESS_KEY");
    AWSCredentials awsCredentials = new BasicAWSCredentials(swfAccessId, swfSecretKey);

    AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(awsCredentials, config);

    String configParam;//from   w ww .j  a va2 s.c  o  m

    if (args.length == 0) {
        configParam = "cf1";
    } else {
        configParam = args[0];
    }

    SchedulerConfig schedulerConfig = DyDBUtils.getSchedulerConfig(configParam);

    service.setEndpoint(schedulerConfig.getEndPoint());

    String domain = schedulerConfig.getDomain();
    String taskListToPoll = schedulerConfig.getTaskList();

    try {
        ActivityWorker aw = new ActivityWorker(service, domain, taskListToPoll);
        aw.addActivitiesImplementation(new SchedulerActivitiesImpl());
        aw.start();

        WorkflowWorker wfw = new WorkflowWorker(service, domain, taskListToPoll);
        wfw.addWorkflowImplementationType(SchedulerWorkflowImpl.class);
        wfw.start();

    } catch (Exception e) {
        System.out.println("should have caught it");
    }

}

From source file:org.systemsbiology.common.ConfigHelper.java

License:Open Source License

public AmazonSimpleWorkflow createSWFClient() {
    ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70 * 1000);
    AWSCredentials awsCredentials = new BasicAWSCredentials(this.swfAccessId, this.swfSecretKey);
    AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(awsCredentials, config);
    client.setEndpoint(this.swfServiceUrl);
    return client;
}