Skip to content

Commit 517bbd1

Browse files
Merge pull request #44 from longquanzheng/metric
2 parents d540ddf + 2c568e0 commit 517bbd1

24 files changed

+397
-124
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ repositories {
3535
dependencies {
3636
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
3737
errorprone("com.google.errorprone:error_prone_core:2.3.1")
38-
compile group: 'com.uber.cadence', name: 'cadence-client', version: '2.7.8'
38+
compile group: 'com.uber.cadence', name: 'cadence-client', version: '3.0.0'
3939
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
4040
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
41+
compile group: 'com.uber.m3', name: 'tally-core', version: '0.10.0'
42+
compile group: 'com.uber.m3', name: 'tally-prometheus', version: '0.10.0'
43+
compile group: 'io.prometheus', name: 'simpleclient', version: '0.10.0'
44+
compile group: 'io.prometheus', name: 'simpleclient_httpserver', version: '0.10.0'
4145
testCompile group: 'junit', name: 'junit', version: '4.12'
4246
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
4347
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.3'

src/main/java/com/uber/cadence/samples/bookingsaga/TripBookingSaga.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@
1717

1818
package com.uber.cadence.samples.bookingsaga;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.client.WorkflowClient;
2321
import com.uber.cadence.client.WorkflowException;
22+
import com.uber.cadence.serviceclient.ClientOptions;
23+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2424
import com.uber.cadence.worker.Worker;
25+
import com.uber.cadence.worker.WorkerFactory;
2526

2627
public class TripBookingSaga {
2728

2829
static final String TASK_LIST = "TripBooking";
2930

3031
@SuppressWarnings("CatchAndPrintStackTrace")
3132
public static void main(String[] args) {
33+
// Get a new client
34+
WorkflowClient workflowClient =
35+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
3236
// Get worker to poll the common task list.
33-
Worker.Factory factory = new Worker.Factory(DOMAIN);
37+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
3438
final Worker workerForCommonTaskList = factory.newWorker(TASK_LIST);
3539
workerForCommonTaskList.registerWorkflowImplementationTypes(TripBookingWorkflowImpl.class);
3640
TripBookingActivities tripBookingActivities = new TripBookingActivitiesImpl();
@@ -40,8 +44,6 @@ public static void main(String[] args) {
4044
factory.start();
4145
System.out.println("Worker started for task list: " + TASK_LIST);
4246

43-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
44-
4547
// now we can start running instances of our saga - its state will be persisted
4648
TripBookingWorkflow trip1 = workflowClient.newWorkflowStub(TripBookingWorkflow.class);
4749
try {

src/main/java/com/uber/cadence/samples/common/QueryWorkflowExecution.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
package com.uber.cadence.samples.common;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.WorkflowExecution;
2321
import com.uber.cadence.client.WorkflowClient;
2422
import com.uber.cadence.client.WorkflowStub;
23+
import com.uber.cadence.serviceclient.ClientOptions;
2524
import com.uber.cadence.serviceclient.IWorkflowService;
2625
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2726
import java.util.Optional;
@@ -42,7 +41,7 @@ public static void main(String[] args) throws Exception {
4241
+ " <queryType> <workflowId> [<runId>]");
4342
System.exit(1);
4443
}
45-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
44+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
4645

4746
String queryType = args[0];
4847

@@ -53,7 +52,7 @@ public static void main(String[] args) throws Exception {
5352
String runId = args[1];
5453
workflowExecution.setRunId(runId);
5554
}
56-
WorkflowClient client = WorkflowClient.newInstance(cadenceService, DOMAIN);
55+
WorkflowClient client = WorkflowClient.newInstance(cadenceService);
5756
WorkflowStub workflow = client.newUntypedWorkflowStub(workflowExecution, Optional.empty());
5857
String result = workflow.query(queryType, String.class);
5958

src/main/java/com/uber/cadence/samples/common/RegisterDomain.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.uber.cadence.DomainAlreadyExistsError;
2323
import com.uber.cadence.RegisterDomainRequest;
24+
import com.uber.cadence.serviceclient.ClientOptions;
2425
import com.uber.cadence.serviceclient.IWorkflowService;
2526
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2627
import java.io.IOException;
@@ -34,7 +35,7 @@
3435
public class RegisterDomain {
3536

3637
public static void main(String[] args) throws TException, IOException {
37-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
38+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
3839
RegisterDomainRequest request = new RegisterDomainRequest();
3940
request.setDescription("Java Samples");
4041
request.setEmitMetric(false);

src/main/java/com/uber/cadence/samples/common/WorkflowExecutionHistoryPrinter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.uber.cadence.WorkflowExecution;
2323
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
24+
import com.uber.cadence.serviceclient.ClientOptions;
2425
import com.uber.cadence.serviceclient.IWorkflowService;
2526
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2627

@@ -39,7 +40,7 @@ public static void main(String[] args) throws Exception {
3940
+ " <workflowId> <runId>");
4041
System.exit(1);
4142
}
42-
IWorkflowService cadenceService = new WorkflowServiceTChannel();
43+
IWorkflowService cadenceService = new WorkflowServiceTChannel(ClientOptions.defaultInstance());
4344
WorkflowExecution workflowExecution = new WorkflowExecution();
4445
String workflowId = args[0];
4546
workflowExecution.setWorkflowId(workflowId);

src/main/java/com/uber/cadence/samples/fileprocessing/FileProcessingStarter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
package com.uber.cadence.samples.fileprocessing;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.client.WorkflowClient;
21+
import com.uber.cadence.serviceclient.ClientOptions;
22+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2323
import java.net.URL;
2424

2525
/** Starts a file processing sample workflow. */
2626
public class FileProcessingStarter {
2727

2828
public static void main(String[] args) throws Exception {
29-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
29+
// Get a new client
30+
WorkflowClient workflowClient =
31+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
3032
FileProcessingWorkflow workflow = workflowClient.newWorkflowStub(FileProcessingWorkflow.class);
3133

3234
System.out.println("Executing FileProcessingWorkflow");

src/main/java/com/uber/cadence/samples/fileprocessing/FileProcessingWorker.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package com.uber.cadence.samples.fileprocessing;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
20+
import com.uber.cadence.client.WorkflowClient;
21+
import com.uber.cadence.serviceclient.ClientOptions;
22+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2223
import com.uber.cadence.worker.Worker;
24+
import com.uber.cadence.worker.WorkerFactory;
2325
import java.lang.management.ManagementFactory;
2426

2527
/**
@@ -37,8 +39,11 @@ public static void main(String[] args) {
3739

3840
String hostSpecifiTaskList = ManagementFactory.getRuntimeMXBean().getName();
3941

42+
// Get a new client
43+
WorkflowClient workflowClient =
44+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
4045
// Get worker to poll the common task list.
41-
Worker.Factory factory = new Worker.Factory(DOMAIN);
46+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
4247
final Worker workerForCommonTaskList = factory.newWorker(TASK_LIST);
4348
workerForCommonTaskList.registerWorkflowImplementationTypes(FileProcessingWorkflowImpl.class);
4449
StoreActivitiesImpl storeActivityImpl = new StoreActivitiesImpl(hostSpecifiTaskList);

src/main/java/com/uber/cadence/samples/hello/HelloActivity.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
package com.uber.cadence.samples.hello;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
22-
import com.google.common.base.Strings;
2320
import com.uber.cadence.activity.ActivityMethod;
2421
import com.uber.cadence.client.WorkflowClient;
25-
import com.uber.cadence.serviceclient.IWorkflowService;
22+
import com.uber.cadence.serviceclient.ClientOptions;
2623
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2724
import com.uber.cadence.worker.Worker;
25+
import com.uber.cadence.worker.WorkerFactory;
2826
import com.uber.cadence.workflow.Workflow;
2927
import com.uber.cadence.workflow.WorkflowMethod;
3028

@@ -75,19 +73,13 @@ public String composeGreeting(String greeting, String name) {
7573
}
7674

7775
public static void main(String[] args) {
78-
// Start a worker that hosts both workflow and activity implementations.
79-
final WorkflowServiceTChannel.ClientOptions.Builder builder =
80-
new WorkflowServiceTChannel.ClientOptions.Builder();
81-
// Use 5 seconds as RPC timeout
82-
builder.setRpcTimeout(5 * 1000);
83-
IWorkflowService wfService =
84-
new WorkflowServiceTChannel(
85-
Strings.isNullOrEmpty(System.getenv("CADENCE_SEEDS"))
86-
? "127.0.0.1"
87-
: System.getenv("CADENCE_SEEDS"),
88-
7933,
89-
builder.build());
90-
Worker.Factory factory = new Worker.Factory(wfService, DOMAIN);
76+
// Get a new client
77+
// NOTE: to set a different options, you can do like this:
78+
// ClientOptions.newBuilder().setRpcTimeout(5 * 1000).build();
79+
WorkflowClient workflowClient =
80+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
81+
// Get worker to poll the task list.
82+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
9183
Worker worker = factory.newWorker(TASK_LIST);
9284
// Workflows are stateful. So you need a type to create instances.
9385
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
@@ -96,8 +88,6 @@ public static void main(String[] args) {
9688
// Start listening to the workflow and activity task lists.
9789
factory.start();
9890

99-
// Start a workflow execution. Usually this is done from another program.
100-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
10191
// Get a workflow stub using the same task list the worker uses.
10292
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
10393
// Execute a workflow waiting for it to complete.

src/main/java/com/uber/cadence/samples/hello/HelloActivityRetry.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
package com.uber.cadence.samples.hello;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.activity.ActivityOptions;
2321
import com.uber.cadence.client.WorkflowClient;
2422
import com.uber.cadence.client.WorkflowOptions;
2523
import com.uber.cadence.common.RetryOptions;
24+
import com.uber.cadence.serviceclient.ClientOptions;
25+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2626
import com.uber.cadence.worker.Worker;
27+
import com.uber.cadence.worker.WorkerFactory;
2728
import com.uber.cadence.workflow.Functions;
2829
import com.uber.cadence.workflow.Workflow;
2930
import com.uber.cadence.workflow.WorkflowMethod;
@@ -99,8 +100,13 @@ public synchronized String composeGreeting(String greeting, String name) {
99100
}
100101

101102
public static void main(String[] args) {
102-
// Start a worker that hosts both workflow and activity implementations.
103-
Worker.Factory factory = new Worker.Factory(DOMAIN);
103+
// Get a new client
104+
// NOTE: to set a different options, you can do like this:
105+
// ClientOptions.newBuilder().setRpcTimeout(5 * 1000).build();
106+
WorkflowClient workflowClient =
107+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
108+
// Get worker to poll the task list.
109+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
104110
Worker worker = factory.newWorker(TASK_LIST);
105111
// Workflows are stateful. So you need a type to create instances.
106112
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
@@ -109,8 +115,6 @@ public static void main(String[] args) {
109115
// Start listening to the workflow and activity task lists.
110116
factory.start();
111117

112-
// Start a workflow execution. Usually this is done from another program.
113-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
114118
// Get a workflow stub using the same task list the worker uses.
115119
WorkflowOptions workflowOptions =
116120
new WorkflowOptions.Builder()

src/main/java/com/uber/cadence/samples/hello/HelloAsync.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
package com.uber.cadence.samples.hello;
1919

20-
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
21-
2220
import com.uber.cadence.activity.ActivityMethod;
2321
import com.uber.cadence.client.WorkflowClient;
22+
import com.uber.cadence.serviceclient.ClientOptions;
23+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
2424
import com.uber.cadence.worker.Worker;
25+
import com.uber.cadence.worker.WorkerFactory;
2526
import com.uber.cadence.workflow.Async;
2627
import com.uber.cadence.workflow.Functions.Func;
2728
import com.uber.cadence.workflow.Promise;
@@ -79,8 +80,13 @@ public String composeGreeting(String greeting, String name) {
7980
}
8081

8182
public static void main(String[] args) {
82-
// Start a worker that hosts both workflow and activity implementations.
83-
Worker.Factory factory = new Worker.Factory(DOMAIN);
83+
// Get a new client
84+
// NOTE: to set a different options, you can do like this:
85+
// ClientOptions.newBuilder().setRpcTimeout(5 * 1000).build();
86+
WorkflowClient workflowClient =
87+
WorkflowClient.newInstance(new WorkflowServiceTChannel(ClientOptions.defaultInstance()));
88+
// Get worker to poll the task list.
89+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
8490
Worker worker = factory.newWorker(TASK_LIST);
8591
// Workflows are stateful. So you need a type to create instances.
8692
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
@@ -89,8 +95,6 @@ public static void main(String[] args) {
8995
// Start listening to the workflow and activity task lists.
9096
factory.start();
9197

92-
// Start a workflow execution. Usually this is done from another program.
93-
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
9498
// Get a workflow stub using the same task list the worker uses.
9599
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
96100
// Execute a workflow waiting for it to complete.

0 commit comments

Comments
 (0)