1
2 package org.galagosearch.tupleflow.execution;
3
4 import java.io.File;
5 import java.io.Serializable;
6
7 /***
8 * A data pipe carries tuples from m sources/outputs to
9 * n sinks/outputs.
10 *
11 * @author trevor
12 */
13 ;
14
15 public class DataPipe implements Serializable {
16 public DataPipe(String root, String pipeName, String className, String[] order, String[] hash, int inputCount, int outputCount) {
17 this.root = root;
18 this.pipeName = pipeName;
19 this.className = className;
20 this.order = order;
21 this.hash = hash;
22 this.setInputCount(inputCount);
23 this.setOutputCount(outputCount);
24 }
25
26 public String getPipeName() {
27 return pipeName;
28 }
29
30 private String getFileNamesString(String[] fileNames) {
31 StringBuilder builder = new StringBuilder();
32 for (String fileName : fileNames) {
33 if (builder.length() != 0) {
34 builder.append(':');
35 }
36 builder.append(fileName);
37 }
38 return builder.toString();
39 }
40
41 @Override
42 public String toString() {
43 String out = String.format("className: %s\n", className);
44 out += "Pipe path: " + root + "\n";
45 out += getInputCount() + "\n";
46 out += getOutputCount() + "\n";
47
48 out += "order: [" + order.length + "]/";
49
50 for (String o : order) {
51 out += o + "/";
52 }
53 out += "\n";
54
55 out += "hash: [" + hash.length + "]/";
56 for (String h : hash) {
57 out += h + "/";
58 }
59 out += "\n";
60 return out;
61 }
62
63 public String[] getInputFileNames(int index) {
64 String[] inputNames = null;
65
66 if (hash != null) {
67 inputNames = new String[getOutputCount()];
68
69 for (int i = 0; i < getOutputCount(); i++) {
70 inputNames[i] = getFileName(index, i);
71 }
72 } else {
73 inputNames = new String[]{getFileName(index, index)};
74 }
75
76 return inputNames;
77 }
78
79 public String[] getOutputFileNames(int index) {
80 String[] outputNames = null;
81
82 if (hash != null) {
83 outputNames = new String[getInputCount()];
84
85 for (int i = 0; i < getInputCount(); i++) {
86 outputNames[i] = getFileName(i, index);
87 }
88 } else {
89 outputNames = new String[]{getFileName(index, index)};
90 }
91
92 return outputNames;
93 }
94
95 public String getFileName(int inputIndex, int outputIndex) {
96 return root + File.separator + inputIndex + File.separator + outputIndex;
97 }
98
99 public void makeDirectories() {
100 for (int i = 0; i < getInputCount(); i++) {
101 new File(root + File.separator + i).mkdirs();
102 }
103 }
104
105 public int getInputCount() {
106 return inputCount;
107 }
108
109 public void setInputCount(int inputCount) {
110 this.inputCount = inputCount;
111 }
112
113 public int getOutputCount() {
114 return outputCount;
115 }
116
117 public void setOutputCount(int outputCount) {
118 this.outputCount = outputCount;
119 }
120
121 public String[] getHash() {
122 return hash;
123 }
124
125 public String getClassName() {
126 return className;
127 }
128
129 public String[] getOrder() {
130 return order;
131 }
132
133 public String root;
134 public String pipeName;
135 private int inputCount;
136 private int outputCount;
137 public String className;
138 public String[] order;
139 public String[] hash;
140 }