| 1 | package de.uka.ipd.sdq.pipesandfilters.framework; |
| 2 | |
| 3 | import java.util.Observable; |
| 4 | import java.util.Observer; |
| 5 | |
| 6 | /** |
| 7 | * This abstract class is the super class of any elements the pipe may consist |
| 8 | * of, namely any filters or and recorders. |
| 9 | * |
| 10 | * @author Baum |
| 11 | * |
| 12 | */ |
| 13 | public abstract class PipeElement extends Observable implements Observer { |
| 14 | |
| 15 | protected final int MAX_IN_DEGREE; |
| 16 | protected final int MAX_OUT_DEGREE; |
| 17 | protected int inDegree = 0; |
| 18 | protected int outDegree = 0; |
| 19 | |
| 20 | /** |
| 21 | * The Constructor of a pipe element. |
| 22 | * |
| 23 | * @param MAX_IN_DEGREE |
| 24 | * The maximum in degree (i.e. the maximum number of |
| 25 | * predecessors) of the pipe element in the filter chain. |
| 26 | * @param MAX_OUT_DEGREE |
| 27 | * The maximum out degree (i.e. the maximum number of successors) |
| 28 | * of the pipe element in the filter chain. |
| 29 | */ |
| 30 | protected PipeElement(int MAX_IN_DEGREE, int MAX_OUT_DEGREE) { |
| 31 | this.MAX_IN_DEGREE = MAX_IN_DEGREE; |
| 32 | this.MAX_OUT_DEGREE = MAX_OUT_DEGREE; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * This method should be called once at the start of the experiment to |
| 37 | * initialize the pipe. Filters are responsible of forwarding the passed |
| 38 | * parameter to their successive pipe element. |
| 39 | * |
| 40 | * @param metaData |
| 41 | * The initializing meta data. |
| 42 | */ |
| 43 | protected abstract void initialize(MetaDataInit metaData); |
| 44 | |
| 45 | /** |
| 46 | * This method notifies a pipe element of the end of the current experiment |
| 47 | * run. A pipe element may need this notification to perform terminal |
| 48 | * operations. Filters are responsible of forwarding the method call to |
| 49 | * their successive pipe elements. |
| 50 | * |
| 51 | */ |
| 52 | protected abstract void flush(); |
| 53 | |
| 54 | /** |
| 55 | * The actual task of a pipe element during an experiment run is called via |
| 56 | * this method. Filters are responsible of forwarding the data to their |
| 57 | * successive pipe element. |
| 58 | * |
| 59 | * @param data |
| 60 | * The measured data to be handled by the pipe element. |
| 61 | */ |
| 62 | protected abstract void processData(final PipeData data); |
| 63 | |
| 64 | /** |
| 65 | * Forwards data to all successive elements. |
| 66 | * |
| 67 | * @param data |
| 68 | * The data to be forwarded. |
| 69 | */ |
| 70 | protected void forwardData(PipeData data) { |
| 71 | setChanged(); |
| 72 | notifyObservers(data); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Forwards the notification to flush to all successive elements. |
| 77 | */ |
| 78 | protected void forwardFlush() { |
| 79 | setChanged(); |
| 80 | notifyObservers("flush"); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * On update, the incoming Object is checked. If it contains a data element, |
| 85 | * the data is processed. If it contains a String holding a flush command, |
| 86 | * the flush method is called. |
| 87 | */ |
| 88 | @Override |
| 89 | public void update(Observable o, Object arg) { |
| 90 | if (arg instanceof PipeData) { |
| 91 | processData((PipeData) arg); |
| 92 | } else if (arg instanceof String && arg.equals("flush")) { |
| 93 | flush(); |
| 94 | } |
| 95 | } |
| 96 | } |