Skip to content

Commit dabe434

Browse files
committed
Update developer
1 parent 924e7b8 commit dabe434

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

site/developer.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,31 @@ Each `Step` has a reference to the next `Step` in the processing flow; however,
189189
In this sample, the caller creates an `Engine`, `Fiber`, linked set of `Step` instances, and `Packet`. The `Fiber` is then started. The `Engine` would typically be a singleton, since it's backed by a `ScheduledExecutorService`. The `Packet` would also typically be pre-loaded with values that the `Steps` would use in their `apply()` methods.
190190

191191
```java
192+
static class Test {
193+
public static void main(String[] args) {
192194
Engine engine = new Engine("worker-pool");
193-
195+
194196
Fiber fiber = engine.createFiber();
195-
197+
196198
Step step = new StepOne(new StepTwo(new StepThree(null)));
197-
Packet packet = new Packet();
198-
199-
fiber.start(step, packet, new CompletionCallback() {
200-
@Override
201-
public void onCompletion(Packet packet) {
202-
// Fiber has completed successfully
203-
}
199+
Packet packet = new Packet();
200+
201+
fiber.start(
202+
step,
203+
packet,
204+
new CompletionCallback() {
205+
@Override
206+
public void onCompletion(Packet packet) {
207+
// Fiber has completed successfully
208+
}
204209

205-
@Override
206-
public void onThrowable(Packet packet, Throwable throwable) {
207-
// Fiber processing was terminated with an exception
208-
}
209-
});
210+
@Override
211+
public void onThrowable(Packet packet, Throwable throwable) {
212+
// Fiber processing was terminated with an exception
213+
}
214+
});
215+
}
216+
}
210217
```
211218

212219
`Steps` must not invoke sleep or blocking calls from within `apply()`. This prevents the worker threads from serving other `Fibers`. Instead, use asynchronous calls and the `Fiber` suspend/resume pattern. `Step` provides a method, `doDelay()`, which creates a `NextAction` to drive `Fiber` suspend/resume that is a better option than sleep precisely because the worker thread can serve other `Fibers` during the delay. For asynchronous IO or similar patterns, suspend the `Fiber`. In the callback as the `Fiber` suspends, initiate the asynchronous call. Finally, when the call completes, resume the `Fiber`. The suspend/resume functionality handles the case where resumed before the suspending callback completes.
@@ -232,7 +239,7 @@ In this sample, the step uses asynchronous file IO and the suspend/resume `Fiber
232239
ByteBuffer buffer = ByteBuffer.allocate(1024);
233240
fileChannel.read(buffer, 0, buffer, new CompletionHandler<Integer, ByteBuffer>() {
234241
@Override
235-
public void completed(Integer result, ByteBuffer attachment) {
242+
void completed(Integer result, ByteBuffer attachment) {
236243
// Store data in Packet and resume Fiber
237244
packet.put("DATA_SIZE_READ", result);
238245
packet.put("DATA_FROM_SOMEFILE", attachment);
@@ -284,7 +291,7 @@ In this sample, the developer is using the pattern to list pods from the default
284291
}
285292

286293
@Override
287-
public NextAction onSuccess(Packet packet, V1PodList result, int statusCode,
294+
NextAction onSuccess(Packet packet, V1PodList result, int statusCode,
288295
Map<String, List<String>> responseHeaders) {
289296
// do something with the result Pod, if not null
290297
return doNext(packet);

0 commit comments

Comments
 (0)