01: package org.kohsuke.donothing;
02:
03: import dalma.Workflow;
04: import static dalma.TimeUnit.SECONDS;
05:
06: import java.io.IOException;
07: import java.util.Random;
08:
09: /**
10: * A sample workflow.
11: */
12: public class ConversationImpl extends Workflow {
13:
14: // these instance variables live across JVM sessions
15: private final int id = iota++;
16: private final Random r = new Random();
17:
18: @Override
19: public void run() {
20: for (int i = 0; i < 5; i++) {
21: // setting the title allows the management UI to see what this workflow is about
22: setTitle(String.format("ID %1$s in its iteration %2$s", id,
23: i));
24:
25: // logged messages can be seen from the management UI, and therefore
26: // ideal for recording what happened during the course of a workflow.
27: getLogger().fine("Rolling a dice");
28: switch (r.nextInt(3)) {
29: case 0:
30: // reproduce : create another workflow
31: getLogger().fine("reproduce");
32: try {
33: getOwner().getEngine().createConversation(
34: new ConversationImpl());
35: } catch (IOException e) {
36: e.printStackTrace();
37: return; //hmm?
38: }
39: break;
40: case 1:
41: // noop
42: getLogger().fine("noop");
43: break;
44: case 2:
45: // die
46: getLogger().fine("die");
47: return;
48: }
49:
50: // sleep 3 seconds
51: sleep(3, SECONDS);
52: }
53: }
54:
55: static int iota = 0;
56: }
|