You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the goals of the reference implementation is to maintain the number of dependencies as lower as possible. With that spirit, a modular approach has been followed, letting the users decide, depending on their workflows nature, which dependencies should be include.
50
50
51
-
In practical terms, this means a separation between the core part and additional dependencies that should be explicitly included if your workflow is interacting with an external service that communicated using a particular technology supported by the specification (at this moment, just HTTP). The intention of this is to avoid adding dependencies that you do not really need (for example, when gRPC call will be implemented, if we were adding the gRPC stack to the core dependencies, you wont be able to get rid of it even if none of your workflows use it)
51
+
In practical terms, this means a separation between the core part and additional dependencies that should be explicitly included if your workflow is interacting with an external service that communicated using a particular technology supported by the specification (at this moment, just HTTP). The intention of this is to avoid adding dependencies that you do not need (for example, when gRPC call will be implemented, if we were adding the gRPC stack to the core dependencies, you won't be able to get rid of it even if none of your workflows use it)
Quick version is intended for impatient users that want to try something as soon as possible.
94
+
The quick version is intended for impatient users who want to try something as soon as possible.
95
95
96
-
Detailed version is more suitable for those users interested on a more thoughtful discussion of the API.
96
+
The detailed version is more suitable for those users interested in a more thoughtful discussion of the API.
97
97
98
98
### Quick version
99
99
100
-
For a quick introduction, we are going to use a simple workflow [definition](../examples/simpleGet/src/main/resources/get.yaml) that performs a get call.
100
+
For a quick introduction, we will use a simple workflow [definition](../examples/simpleGet/src/main/resources/get.yaml) that performs a get call.
101
101
We are going to show two ways of invoking the workflow:
102
102
- blocking the thread till the get request goes through
103
103
- returning control to the caller, so the main thread continues while the get is executed
104
104
105
-
In order to execute the workflow, blocking the thread till the http request is completed, you should write
105
+
In order to execute the workflow, blocking the thread till the HTTP request is completed, you should write
@@ -126,9 +126,11 @@ In order to execute the workflow, without blocking the calling thread till the h
126
126
.thenAccept(node -> logger.info("Workflow output is {}", node));
127
127
}
128
128
```
129
-
When the http request is done, both examples will print a similar output
129
+
When the HTTP request is done, both examples will print a similar output
130
130
131
-
`Workflow output is {"id":10,"category":{"id":10,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":10,"name":"string"}],"status":"string"}`
131
+
132
+
```shell
133
+
Workflow output is {"id":10,"category":{"id":10,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":10,"name":"string"}],"status":"string"}
132
134
133
135
You can find the complete java code [here](../examples/simpleGet/src/main/java/NotBlockingExample.java)
134
136
@@ -138,15 +140,15 @@ To discuss runtime API we are going to use a couple of workflow:
138
140
- [listen.yaml](../examples/events/src/main/listen.yaml), which waits for an event reporting a temperature greater than 38
139
141
- [emit.yaml](../examples/events/src/main/emit.yaml), which emits events with a certain temperature, specified as workflow parameter.
140
142
141
-
A brief summary of what we are trying to do. We will start listen.yaml, which will complete when it receives an event with the proper temperature, but it wont block the main thread while waiting for it. Then, we will send an event with a lower temperature, that will be ignored. And finally, we will send an event with a greater temperature, that will complete the waiting workflow.
143
+
Here is a summary of what we are trying to do: We will start the `listen.yaml` workflow, which will be completed when it receives an event with the proper temperature. It won't block the main thread while waiting for it. Then, we will send an event with a lower temperature that will be ignored. Finally, we will send an event with a higher temperature to complete the waiting workflow.
142
144
143
-
The first step is to create a [WorkflowApplication](core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java) instance. An application is an abstraction that allow customization of different aspect of the workflow execution (for example change the default `ExecutorService` for thread spawning)
145
+
The first step is to create a [WorkflowApplication](core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java) instance. An application is an abstraction that allows customization of different aspects of the workflow execution (for example, change the default `ExecutorService` for thread spawning)
144
146
145
-
Since `WorkflowApplication` implements `Autocloseable`, we better use a try...finally block, ensuring any resource that might have been used by the workflow is freed when done.
147
+
Since `WorkflowApplication` implements `Autocloseable`, we better use a try...finally block, ensuring any resource that the workflow might have used is freed when done.
Once we have the application object, we use it to parse our definition examples. To load each workflow definition, we use `readFromClasspath` helper method defined in [WorkflowReader](api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java) class.
151
+
Once we have the application object, we use it to parse our definition examples. To load each workflow definition, we use the `readFromClasspath` helper method defined in [WorkflowReader](api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java) class.
150
152
151
153
```java
152
154
WorkflowDefinition listenDefinition =
@@ -155,9 +157,9 @@ Once we have the application object, we use it to parse our definition examples.
A [WorkflowDefinition](core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java) object is immutable and therefore threadsafe. It is used to execute as many workflow instances as desired.
160
+
A [WorkflowDefinition](core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java) object is immutable and, therefore, thread-safe. It is used to execute as many workflow instances as desired.
159
161
160
-
To execute a workflow, we first create a [WorkflowInstance](core/src/main/java/io/serverlessworkflow/impl/WorkflowInstance.java) object (the initial status is PENDING) and then invoke `start` method on it (the status is changed to RUNNING). `start` method returns a [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html), which we use to indicate that a log message should be printed when the workflow is completed.
162
+
To execute a workflow, we first create a [WorkflowInstance](core/src/main/java/io/serverlessworkflow/impl/WorkflowInstance.java) object (its initial status is PENDING) and then invoke the `start` method on it (its status is changed to RUNNING). The `start` method returns a [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html), which we use to indicate that a log message should be printed when the workflow is completed.
@@ -168,13 +170,13 @@ To execute a workflow, we first create a [WorkflowInstance](core/src/main/java/i
168
170
169
171
The next line will be executed as soon as the workflow execution starts waiting for events to arrive, moment at which control is returned to the calling thread. Therefore, we can execute another workflow instance while the first one is waiting.
170
172
171
-
We are going to send an event with a temperature that does not satisfy the criteria, so the listen instance will continue waiting. To pass parameters to the workflow instance that sends the event, we use a regular Java `Map`. Notice that, since we want to wait till the event is published before executing the next line, we call `join` after `start`, telling the `CompletableFuture` to wait for workflow completion.
173
+
We will send an event with a temperature that does not satisfy the criteria, so the listen instance will continue waiting. We use a regular Java ' Map ' to pass parameters to the workflow instance that sends the event. Note that since we want to wait till the event is published before executing the following line, we call `join` after `start`, telling the `CompletableFuture` to wait for workflow completion.
0 commit comments