Skip to content

Commit f497e5b

Browse files
author
Maxim Fateev
committed
Added src directory back to git
1 parent 25cb4e1 commit f497e5b

File tree

51 files changed

+3335
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3335
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/com
12
target
2-
com
33
.*.swp
44
.*.swo
55
*.iml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
public interface BookingActivities {
18+
19+
void reserveCar(int requestId);
20+
21+
void reserveAirline(int requestId);
22+
23+
void sendConfirmationActivity(int customerId);
24+
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
public class BookingActivitiesImpl implements BookingActivities {
18+
19+
@Override
20+
public void reserveCar(int requestId) {
21+
System.out.printf("Reserving car for Request ID: %d...\n", requestId);
22+
}
23+
24+
@Override
25+
public void reserveAirline(int requestId) {
26+
System.out.printf("Reserving airline for Request ID: %d...\n", requestId);
27+
}
28+
29+
@Override
30+
public void sendConfirmationActivity(int customerId){
31+
System.out.printf("Sending notification to Customer '%d'...\n", customerId);
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
public class BookingConfigKeys {
18+
public static final String ACTIVITY_WORKER_TASKLIST = "Booking.Activity.Worker.TaskList";
19+
public static final String WORKFLOW_WORKER_TASKLIST = "Booking.Workflow.Worker.TaskList";
20+
21+
public static final String WORKFLOW_INPUT_REQUESTID_KEY = "Booking.Input.RequestId";
22+
public static final String WORKFLOW_INPUT_CUSTOMERID_KEY = "Booking.Input.CustomerId";
23+
24+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
import com.uber.cadence.samples.common.ConfigHelper;
18+
import com.uber.cadence.WorkflowService;
19+
import com.uber.cadence.client.CadenceClient;
20+
import com.uber.cadence.internal.StartWorkflowOptions;
21+
22+
/**
23+
* Starts BookingWorkflow executions.
24+
*/
25+
public class BookingStarter {
26+
private static WorkflowService.Iface swfService;
27+
private static String domain;
28+
29+
public static void main(String[] args) throws Exception {
30+
31+
// Load configuration
32+
ConfigHelper configHelper = ConfigHelper.createConfig();
33+
34+
// Create the client for Simple Workflow Service
35+
swfService = configHelper.createWorkflowClient();
36+
domain = configHelper.getDomain();
37+
38+
// Start Workflow instance
39+
int requestId = Integer.parseInt(configHelper.getValueFromConfig(BookingConfigKeys.WORKFLOW_INPUT_REQUESTID_KEY));
40+
int customerId = Integer.parseInt(configHelper.getValueFromConfig(BookingConfigKeys.WORKFLOW_INPUT_CUSTOMERID_KEY));
41+
42+
// Start Wrokflow Execution
43+
CadenceClient client = CadenceClient.newClient(swfService, domain, null);
44+
45+
// Start Wrokflow Execution
46+
String taskList = configHelper.getValueFromConfig(BookingConfigKeys.WORKFLOW_WORKER_TASKLIST);
47+
StartWorkflowOptions options = new StartWorkflowOptions();
48+
options.setTaskList(taskList);
49+
options.setExecutionStartToCloseTimeoutSeconds(20);
50+
options.setTaskStartToCloseTimeoutSeconds(3);
51+
BookingWorkflow workflow = client.newWorkflowStub(BookingWorkflow.class, options);
52+
String activityTaskList = configHelper.getValueFromConfig(BookingConfigKeys.ACTIVITY_WORKER_TASKLIST);
53+
workflow.makeBooking(activityTaskList, requestId, customerId, true, true);
54+
System.exit(0);
55+
}
56+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
import com.uber.cadence.samples.common.ConfigHelper;
18+
import com.uber.cadence.WorkflowService;
19+
import com.uber.cadence.worker.Worker;
20+
import com.uber.cadence.worker.WorkerOptions;
21+
22+
import java.io.IOException;
23+
import java.util.concurrent.TimeUnit;
24+
25+
/**
26+
* This is the process which hosts all workflows and activities in this sample
27+
*/
28+
public class BookingWorker {
29+
private static WorkflowService.Iface swfService;
30+
private static Worker worker;
31+
private static String domain;
32+
33+
34+
public static void main(String[] args) throws Exception {
35+
// load configuration
36+
ConfigHelper configHelper = loadConfig();
37+
38+
// Start Activity Worker
39+
startWorker(configHelper);
40+
41+
// Add a Shutdown hook to close ActivityWorker
42+
addShutDownHook();
43+
44+
System.out.println("Please press any key to terminate service.");
45+
46+
try {
47+
System.in.read();
48+
}
49+
catch (IOException e) {
50+
e.printStackTrace();
51+
}
52+
53+
System.exit(0);
54+
55+
}
56+
57+
private static void startWorker(ConfigHelper configHelper) throws Exception {
58+
// Start worker to poll the common task list
59+
String taskList = configHelper.getValueFromConfig(BookingConfigKeys.ACTIVITY_WORKER_TASKLIST);
60+
worker = new Worker(swfService, domain, taskList, null);
61+
worker.addWorkflowImplementationType(BookingWorkflowImpl.class);
62+
// Create activity implementations
63+
BookingActivities bookingActivitiesImpl = new BookingActivitiesImpl();
64+
worker.addActivitiesImplementation(bookingActivitiesImpl);
65+
worker.start();
66+
System.out.println("Worker Started for Task List: " + taskList);
67+
}
68+
69+
private static void stopWorker() throws InterruptedException {
70+
System.out.println("Stopping Worker...");
71+
worker.shutdown(10, TimeUnit.SECONDS);
72+
System.out.println("Worker Stopped...");
73+
}
74+
75+
static ConfigHelper loadConfig() throws IllegalArgumentException, IOException{
76+
ConfigHelper configHelper = ConfigHelper.createConfig();
77+
swfService = configHelper.createWorkflowClient();
78+
domain = configHelper.getDomain();
79+
return configHelper;
80+
}
81+
82+
static void addShutDownHook(){
83+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
84+
85+
public void run() {
86+
try {
87+
stopWorker();
88+
}
89+
catch (InterruptedException e) {
90+
e.printStackTrace();
91+
}
92+
}
93+
}));
94+
}
95+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
import com.uber.cadence.workflow.WorkflowMethod;
18+
19+
public interface BookingWorkflow {
20+
@WorkflowMethod
21+
void makeBooking(String activityTaskList, int requestID, int customerID, boolean reserveAir, boolean reserveCar);
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.booking;
16+
17+
import com.uber.cadence.workflow.ActivityOptions;
18+
import com.uber.cadence.workflow.Workflow;
19+
20+
public class BookingWorkflowImpl implements BookingWorkflow {
21+
22+
@Override
23+
public void makeBooking(String activityTaskList, int requestID, int customerID, boolean reserveAir, boolean reserveCar) {
24+
// Demonstrates how to use task list which name is provided at runtime.
25+
ActivityOptions options = new ActivityOptions.Builder()
26+
.setTaskList(activityTaskList)
27+
.setScheduleToCloseTimeoutSeconds(30)
28+
.build();
29+
BookingActivities activities = Workflow.newActivityStub(BookingActivities.class, options);
30+
31+
activities.reserveCar(requestID);
32+
if (reserveAir) {
33+
activities.reserveAirline(requestID);
34+
}
35+
activities.sendConfirmationActivity(customerID);
36+
}
37+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.samples.common;
16+
17+
import com.uber.cadence.WorkflowExecution;
18+
import com.uber.cadence.WorkflowService;
19+
import com.uber.cadence.client.CadenceClient;
20+
import com.uber.cadence.client.UntypedWorkflowStub;
21+
22+
/**
23+
* Simple example utility to query workflow execution using Cadence query API.
24+
* Cadence redirects query to any currently running workflow worker for the workflow type
25+
* of the requested workflow execution.
26+
*
27+
* @author fateev
28+
*/
29+
public class QueryWorkflowExecution {
30+
31+
public static void main(String[] args) throws Exception {
32+
if (args.length < 2 || args.length > 3) {
33+
System.err.println("Usage: java " + QueryWorkflowExecution.class.getName() +
34+
" <queryType> <workflowId> [<runId>]");
35+
System.exit(1);
36+
}
37+
ConfigHelper configHelper = ConfigHelper.createConfig();
38+
WorkflowService.Iface swfService = configHelper.createWorkflowClient();
39+
String domain = configHelper.getDomain();
40+
41+
String queryType = args[0];
42+
43+
WorkflowExecution workflowExecution = new WorkflowExecution();
44+
String workflowId = args[1];
45+
workflowExecution.setWorkflowId(workflowId);
46+
if (args.length == 3) {
47+
String runId = args[1];
48+
workflowExecution.setRunId(runId);
49+
}
50+
CadenceClient client = CadenceClient.newClient(swfService, domain);
51+
UntypedWorkflowStub workflow = client.newUntypedWorkflowStub(workflowExecution);
52+
String result = workflow.query(queryType, String.class);
53+
54+
System.out.println("Query result for " + workflowExecution + ":");
55+
System.out.println(result);
56+
}
57+
}

0 commit comments

Comments
 (0)