1
2
3 package org.galagosearch.tupleflow.execution;
4
5 import java.util.ArrayList;
6
7 /***
8 * Represents a data connection between two stages in a TupleFlow job.
9 *
10 * @see org.galagosearch.tupleflow.execution.Job
11 * @author trevor
12 */
13 public class Connection extends Locatable implements Cloneable {
14 String className;
15 String connectionName;
16 String[] order;
17 String[] hash;
18 int hashCount;
19 public ArrayList<ConnectionEndPoint> inputs = new ArrayList<ConnectionEndPoint>();
20 public ArrayList<ConnectionEndPoint> outputs = new ArrayList<ConnectionEndPoint>();
21
22 public Connection(FileLocation location, String connectionName, String className, String[] order, String[] hash, int hashCount) {
23 super(location);
24 this.connectionName = connectionName;
25 this.className = className;
26 this.order = order;
27 this.hash = hash;
28 this.hashCount = hashCount;
29 }
30
31 public Connection(FileLocation location, String className, String[] order, String[] hash, int hashCount) {
32 this(location, null, className, order, hash, hashCount);
33 }
34
35 public String getName() {
36 if (connectionName == null) {
37 assert inputs.size() > 0;
38 return inputs.get(0).getStageName() + "-" + inputs.get(0).getPointName();
39 } else {
40 return connectionName;
41 }
42 }
43
44 String getClassName() {
45 return className;
46 }
47
48 String[] getOrder() {
49 return order;
50 }
51
52 String[] getHash() {
53 return hash;
54 }
55
56 int getHashCount() {
57 return hashCount;
58 }
59
60 @Override
61 public Connection clone() {
62 try {
63 Connection copy = (Connection) super.clone();
64 ArrayList<ConnectionEndPoint> inputCopy = new ArrayList<ConnectionEndPoint>();
65
66 for (ConnectionEndPoint point : inputs) {
67 inputCopy.add(point.clone());
68 }
69
70 ArrayList<ConnectionEndPoint> outputCopy = new ArrayList<ConnectionEndPoint>();
71
72 for (ConnectionEndPoint point : outputs) {
73 outputCopy.add(point.clone());
74 }
75
76 copy.inputs = inputCopy;
77 copy.outputs = outputCopy;
78 return copy;
79 } catch (CloneNotSupportedException ex) {
80 throw new RuntimeException("Expected cloning to be supported in superclass", ex);
81 }
82 }
83 }