Skip to content

Commit

Permalink
Change to v0.26.0 release of SDK (#21)
Browse files Browse the repository at this point in the history
SDK renamed task list to task queue.
  • Loading branch information
mfateev authored Jun 28, 2020
1 parent c73b084 commit 76713f2
Show file tree
Hide file tree
Showing 47 changed files with 235 additions and 233 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ choose **Gradle** and then click **Next**->**Finish**.

Run Temporal Server using Docker Compose:

curl -L https://github.com/temporalio/temporal/releases/download/v0.25.0/docker.tar.gz | tar -xz --strip-components 1 docker/docker-compose.yml
curl -L https://github.com/temporalio/temporal/releases/download/v0.26.0/docker.tar.gz | tar -xz --strip-components 1 docker/docker-compose.yml
docker-compose up

If this does not work, see the instructions for running Temporal Server at https://github.com/temporalio/temporal/blob/master/README.md.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
}

dependencies {
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.25.0'
implementation group: 'io.temporal', name: 'temporal-sdk', version: '0.26.0'
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class TripBookingSaga {

static final String TASK_LIST = "TripBooking";
static final String TASK_QUEUE = "TripBooking";

@SuppressWarnings("CatchAndPrintStackTrace")
public static void main(String[] args) {
Expand All @@ -37,11 +37,11 @@ public static void main(String[] args) {
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);

// Worker that listens on a task list and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_LIST);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_QUEUE);

// Workflows are stateful. So you need a type to create instances.
worker.registerWorkflowImplementationTypes(TripBookingWorkflowImpl.class);
Expand All @@ -52,10 +52,10 @@ public static void main(String[] args) {

// Start all workers created by this factory.
factory.start();
System.out.println("Worker started for task list: " + TASK_LIST);
System.out.println("Worker started for task queue: " + TASK_QUEUE);

// now we can start running instances of our saga - its state will be persisted
WorkflowOptions options = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build();
TripBookingWorkflow trip1 = client.newWorkflowStub(TripBookingWorkflow.class, options);
try {
trip1.bookTrip("trip1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package io.temporal.samples.fileprocessing;

import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_LIST;
import static io.temporal.samples.fileprocessing.FileProcessingWorker.TASK_QUEUE;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
Expand All @@ -37,7 +37,7 @@ public static void main(String[] args) throws Exception {
FileProcessingWorkflow workflow =
client.newWorkflowStub(
FileProcessingWorkflow.class,
WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@
*/
public class FileProcessingWorker {

static final String TASK_LIST = "FileProcessing";
static final String TASK_QUEUE = "FileProcessing";

public static void main(String[] args) {

String hostSpecifiTaskList = ManagementFactory.getRuntimeMXBean().getName();
String hostSpecifiTaskQueue = ManagementFactory.getRuntimeMXBean().getName();

// gRPC stubs wrapper that talks to the local docker instance of temporal service.
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);
// Worker that listens on a task list and hosts both workflow and activity implementations.
final Worker workerForCommonTaskList = factory.newWorker(TASK_LIST);
workerForCommonTaskList.registerWorkflowImplementationTypes(FileProcessingWorkflowImpl.class);
StoreActivitiesImpl storeActivityImpl = new StoreActivitiesImpl(hostSpecifiTaskList);
workerForCommonTaskList.registerActivitiesImplementations(storeActivityImpl);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
final Worker workerForCommonTaskQueue = factory.newWorker(TASK_QUEUE);
workerForCommonTaskQueue.registerWorkflowImplementationTypes(FileProcessingWorkflowImpl.class);
StoreActivitiesImpl storeActivityImpl = new StoreActivitiesImpl(hostSpecifiTaskQueue);
workerForCommonTaskQueue.registerActivitiesImplementations(storeActivityImpl);

// Get worker to poll the host-specific task list.
final Worker workerForHostSpecificTaskList = factory.newWorker(hostSpecifiTaskList);
workerForHostSpecificTaskList.registerActivitiesImplementations(storeActivityImpl);
// Get worker to poll the host-specific task queue.
final Worker workerForHostSpecificTaskQueue = factory.newWorker(hostSpecifiTaskQueue);
workerForHostSpecificTaskQueue.registerActivitiesImplementations(storeActivityImpl);

// Start all workers created by this factory.
factory.start();
System.out.println("Worker started for task list: " + TASK_LIST);
System.out.println("Worker Started for activity task List: " + hostSpecifiTaskList);
System.out.println("Worker started for task queue: " + TASK_QUEUE);
System.out.println("Worker Started for activity task Queue: " + hostSpecifiTaskQueue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
* This implementation of FileProcessingWorkflow downloads the file, zips it, and uploads it to a
* destination. An important requirement for such a workflow is that while a first activity can run
* on any host, the second and third must run on the same host as the first one. This is achieved
* through use of a host specific task list. The first activity returns the name of the host
* specific task list and all other activities are dispatched using the stub that is configured with
* it. This assumes that FileProcessingWorker has a worker running on the same task list.
* through use of a host specific task queue. The first activity returns the name of the host
* specific task queue and all other activities are dispatched using the stub that is configured
* with it. This assumes that FileProcessingWorker has a worker running on the same task queue.
*/
public class FileProcessingWorkflowImpl implements FileProcessingWorkflow {

// Uses the default task list shared by the pool of workers.
private final StoreActivities defaultTaskListStore;
// Uses the default task queue shared by the pool of workers.
private final StoreActivities defaultTaskQueueStore;

public FileProcessingWorkflowImpl() {
// Create activity clients.
ActivityOptions ao =
ActivityOptions.newBuilder()
.setScheduleToCloseTimeout(Duration.ofSeconds(10))
.setTaskList(FileProcessingWorker.TASK_LIST)
.setTaskQueue(FileProcessingWorker.TASK_QUEUE)
.build();
this.defaultTaskListStore = Workflow.newActivityStub(StoreActivities.class, ao);
this.defaultTaskQueueStore = Workflow.newActivityStub(StoreActivities.class, ao);
}

@Override
Expand All @@ -61,19 +61,19 @@ public void processFile(URL source, URL destination) {
}

private void processFileImpl(URL source, URL destination) {
StoreActivities.TaskListFileNamePair downloaded = defaultTaskListStore.download(source);
StoreActivities.TaskQueueFileNamePair downloaded = defaultTaskQueueStore.download(source);

// Now initialize stubs that are specific to the returned task list.
// Now initialize stubs that are specific to the returned task queue.
ActivityOptions hostActivityOptions =
ActivityOptions.newBuilder()
.setTaskList(downloaded.getHostTaskList())
.setTaskQueue(downloaded.getHostTaskQueue())
.setScheduleToCloseTimeout(Duration.ofSeconds(10))
.build();
StoreActivities hostSpecificStore =
Workflow.newActivityStub(StoreActivities.class, hostActivityOptions);

// Call processFile activity to zip the file.
// Call the activity to process the file using worker-specific task list.
// Call the activity to process the file using worker-specific task queue.
String processed = hostSpecificStore.process(downloaded.getFileName());
// Call upload activity to upload the zipped file.
hostSpecificStore.upload(processed, destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
@ActivityInterface
public interface StoreActivities {

final class TaskListFileNamePair {
private String hostTaskList;
final class TaskQueueFileNamePair {
private String hostTaskQueue;
private String fileName;

public TaskListFileNamePair(String hostTaskList, String fileName) {
this.hostTaskList = hostTaskList;
public TaskQueueFileNamePair(String hostTaskQueue, String fileName) {
this.hostTaskQueue = hostTaskQueue;
this.fileName = fileName;
}

/** Jackson needs it */
public TaskListFileNamePair() {}
public TaskQueueFileNamePair() {}

public String getHostTaskList() {
return hostTaskList;
public String getHostTaskQueue() {
return hostTaskQueue;
}

public String getFileName() {
Expand All @@ -65,7 +65,7 @@ public String getFileName() {
* Downloads file to local disk.
*
* @param url remote file location
* @return local task list and downloaded file name
* @return local task queue and downloaded file name
*/
TaskListFileNamePair download(URL url);
TaskQueueFileNamePair download(URL url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
/** Store activities implementation. */
public class StoreActivitiesImpl implements StoreActivities {

private final String hostSpecificTaskList;
private final String hostSpecificTaskQueue;

public StoreActivitiesImpl(String taskList) {
this.hostSpecificTaskList = taskList;
public StoreActivitiesImpl(String taskQueue) {
this.hostSpecificTaskQueue = taskQueue;
}

@Override
public TaskListFileNamePair download(URL url) {
public TaskQueueFileNamePair download(URL url) {
try {
byte[] binary = Resources.toByteArray(url);
File destination = new File(Files.createTempDir(), "downloaded");
Files.write(binary, destination);
System.out.println(
"download activity: downloaded from " + url + " to " + destination.getAbsolutePath());
return new TaskListFileNamePair(hostSpecificTaskList, destination.getAbsolutePath());
return new TaskQueueFileNamePair(hostSpecificTaskQueue, destination.getAbsolutePath());
} catch (IOException e) {
throw Workflow.wrap(e);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/temporal/samples/hello/HelloActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class HelloActivity {

static final String TASK_LIST = "HelloActivity";
static final String TASK_QUEUE = "HelloActivity";

/** Workflow interface has to have at least one method annotated with @WorkflowMethod. */
@WorkflowInterface
Expand Down Expand Up @@ -88,22 +88,22 @@ public static void main(String[] args) {
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);
// Worker that listens on a task list and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_LIST);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_QUEUE);
// Workflows are stateful. So you need a type to create instances.
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
// Activities are stateless and thread safe. So a shared instance is used.
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
// Start listening to the workflow and activity task lists.
// Start listening to the workflow and activity task queues.
factory.start();

// Start a workflow execution. Usually this is done from another program.
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
// Uses task queue from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build());
// Execute a workflow waiting for it to complete. See {@link
// io.temporal.samples.hello.HelloSignal}
// for an example of starting workflow without waiting synchronously for its result.
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/temporal/samples/hello/HelloActivityRetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class HelloActivityRetry {

static final String TASK_LIST = "HelloActivityRetry";
static final String TASK_QUEUE = "HelloActivityRetry";

@WorkflowInterface
public interface GreetingWorkflow {
Expand Down Expand Up @@ -109,19 +109,19 @@ public static void main(String[] args) {
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);
// Worker that listens on a task list and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_LIST);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_QUEUE);
// Workflows are stateful. So you need a type to create instances.
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
// Activities are stateless and thread safe. So a shared instance is used.
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
// Start listening to the workflow and activity task lists.
// Start listening to the workflow and activity task queues.
factory.start();

// Get a workflow stub using the same task list the worker uses.
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build();
// Get a workflow stub using the same task queue the worker uses.
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build();
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/temporal/samples/hello/HelloAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class HelloAsync {

static final String TASK_LIST = "HelloAsync";
static final String TASK_QUEUE = "HelloAsync";

@WorkflowInterface
public interface GreetingWorkflow {
Expand Down Expand Up @@ -93,22 +93,22 @@ public static void main(String[] args) {
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);
// Worker that listens on a task list and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_LIST);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_QUEUE);
// Workflows are stateful. So you need a type to create instances.
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
// Activities are stateless and thread safe. So a shared instance is used.
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
// Start listening to the workflow and activity task lists.
// Start listening to the workflow and activity task queues.
factory.start();

// Start a workflow execution. Usually this is done from another program.\n'
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
// Uses task queue from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build());
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
System.out.println(greeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class HelloAsyncActivityCompletion {

static final String TASK_LIST = "HelloAsyncActivityCompletion";
static final String TASK_QUEUE = "HelloAsyncActivityCompletion";

@WorkflowInterface
public interface GreetingWorkflow {
Expand Down Expand Up @@ -117,24 +117,24 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
// client that can be used to start and signal workflows
WorkflowClient client = WorkflowClient.newInstance(service);

// worker factory that can be used to create workers for specific task lists
// worker factory that can be used to create workers for specific task queues
WorkerFactory factory = WorkerFactory.newInstance(client);
// Worker that listens on a task list and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_LIST);
// Worker that listens on a task queue and hosts both workflow and activity implementations.
Worker worker = factory.newWorker(TASK_QUEUE);
// Workflows are stateful. So you need a type to create instances.
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
// Activities are stateless and thread safe. So a shared instance is used.
// CompletionClient is passed to activity here only to support unit testing.
ActivityCompletionClient completionClient = client.newActivityCompletionClient();
worker.registerActivitiesImplementations(new GreetingActivitiesImpl(completionClient));
// Start listening to the workflow and activity task lists.
// Start listening to the workflow and activity task queues.
factory.start();

// Start a workflow execution. Usually this is done from another program.
// Uses task list from the GreetingWorkflow @WorkflowMethod annotation.
// Uses task queue from the GreetingWorkflow @WorkflowMethod annotation.
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskList(TASK_LIST).build());
GreetingWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build());
// Execute a workflow asynchronously returning a future that can be used to wait for the
// workflow
// completion.
Expand Down
Loading

0 comments on commit 76713f2

Please sign in to comment.