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 | 37 | private Log log = LogFactory.getLog(TestStage.class); |
35 | |
private int index; |
36 | |
private StageContext context; |
37 | |
|
38 | 37 | public List<Object> processedObjects = Collections.synchronizedList(new ArrayList<Object>()); |
39 | 37 | public boolean initialized = false; |
40 | 37 | public boolean preprocessed = false; |
41 | 37 | public boolean postprocessed = false; |
42 | 37 | public boolean released = false; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 37 | public TestStage(int index) { |
50 | 37 | this.index = index; |
51 | 37 | } |
52 | |
|
53 | |
public int getIndex() { |
54 | 2 | return this.index; |
55 | |
} |
56 | |
|
57 | |
public void init(StageContext context) { |
58 | 35 | this.context = context; |
59 | 35 | this.initialized = true; |
60 | 35 | } |
61 | |
|
62 | |
public void preprocess() throws StageException { |
63 | 21 | this.preprocessed = true; |
64 | 21 | } |
65 | |
|
66 | |
public void process(Object obj) throws StageException { |
67 | 38 | log.info(this + " is processing object " + obj); |
68 | 38 | this.processedObjects.add(obj); |
69 | 38 | this.context.getDownstreamFeeder(this).feed(obj); |
70 | 38 | } |
71 | |
|
72 | |
public void postprocess() throws StageException { |
73 | 21 | this.postprocessed = true; |
74 | 21 | } |
75 | |
|
76 | |
public void release() { |
77 | 21 | this.released = true; |
78 | 21 | } |
79 | |
|
80 | |
public String toString() { |
81 | 252 | return "TEST STAGE (" + this.index + ")"; |
82 | |
} |
83 | |
} |