1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.pipeline.testFramework;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.commons.pipeline.Stage;
26 import org.apache.commons.pipeline.StageContext;
27 import org.apache.commons.pipeline.StageException;
28 import org.apache.commons.pipeline.validation.ConsumedTypes;
29 import org.apache.commons.pipeline.validation.ProducesConsumed;
30
31 @ConsumedTypes(Object.class)
32 @ProducesConsumed
33 public class TestStage implements Stage {
34 private Log log = LogFactory.getLog(TestStage.class);
35 private int index;
36 private StageContext context;
37
38 public List<Object> processedObjects = Collections.synchronizedList(new ArrayList<Object>());
39 public boolean initialized = false;
40 public boolean preprocessed = false;
41 public boolean postprocessed = false;
42 public boolean released = false;
43
44
45
46
47
48
49 public TestStage(int index) {
50 this.index = index;
51 }
52
53 public int getIndex() {
54 return this.index;
55 }
56
57 public void init(StageContext context) {
58 this.context = context;
59 this.initialized = true;
60 }
61
62 public void preprocess() throws StageException {
63 this.preprocessed = true;
64 }
65
66 public void process(Object obj) throws StageException {
67 log.info(this + " is processing object " + obj);
68 this.processedObjects.add(obj);
69 this.context.getDownstreamFeeder(this).feed(obj);
70 }
71
72 public void postprocess() throws StageException {
73 this.postprocessed = true;
74 }
75
76 public void release() {
77 this.released = true;
78 }
79
80 public String toString() {
81 return "TEST STAGE (" + this.index + ")";
82 }
83 }