-
Notifications
You must be signed in to change notification settings - Fork 113
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
Introduce Workerfactory #188
Conversation
|
||
package com.uber.cadence.common; | ||
|
||
public class Validate { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Access not synchronized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
} | ||
} | ||
|
||
enum State { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.