Skip to content

Introduce Workerfactory #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 26, 2018
Merged

Conversation

halakaraki
Copy link
Contributor

No description provided.

@halakaraki halakaraki requested review from mfateev and meiliang86 July 18, 2018 22:58

package com.uber.cadence.common;

public class Validate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private final ArrayList<Worker> workers = new ArrayList<>();
private final Supplier<IWorkflowService> getWorkFlowService;
private String domain;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

this(() -> new WorkflowServiceTChannel(host, port), domain);
}

public Factory(Supplier<IWorkflowService> getWorkFlowService, String domain) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for passing Supplier instead of the IWorkflowService instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control over whether we want to pass a single instance or an instance per worker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case to have an instance per worker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, changed this to passing in an instance. The factory will not be responsible for closing the instance passed in.


public static final class Factory {

private final ArrayList<Worker> workers = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be
private final List<Worker> workers = new ArrayList<>();

}

Worker worker = new Worker(getWorkFlowService.get(), domain, taskList, options);
workers.add(worker);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to workers is not sycnrhonized

state = State.Started;
}

for (Worker worker : workers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access not synchronized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

}
}

enum State {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private enum

import java.time.Duration;
import org.junit.Test;

public class workerFactoryTests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capital W

public class workerFactoryTests {

@Test
public void WhenAFactoryIsStartedAllWorkersStart() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method naming convention is to start from a lower case letter:
whenAFactoryIsStartedAllWorkersStart

build.gradle Outdated
@@ -50,6 +50,7 @@ dependencies {
compile group: 'org.apache.thrift', name: 'libthrift', version: '0.9.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
compile group: 'com.uber.m3', name: 'tally-core', version: '0.2.1'
compile 'com.google.guava:guava:25.1-jre'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the same format as other "compile" entries for consistency?

this(new WorkflowServiceTChannel(), domain, taskList, options);
}
private Worker(IWorkflowService service, String domain, String taskList, WorkerOptions options) {
Preconditions.checkNotNull(service, "service should not be null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Java 8 introduced Objects.requireNotNull for this purpose:

https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html

private Worker(IWorkflowService service, String domain, String taskList, WorkerOptions options) {
Preconditions.checkNotNull(service, "service should not be null");
Preconditions.checkArgument(
domain != null && !"".equals(domain), "domain should not be an empty string");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halakaraki halakaraki merged commit 9beadba into cadence-workflow:master Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants