1 |
mojays |
2 |
package appl.parallel.data; |
2 |
|
|
|
3 |
|
|
import java.awt.Rectangle; |
4 |
|
|
import java.io.IOException; |
5 |
|
|
import java.io.Serializable; |
6 |
|
|
|
7 |
|
|
import org.apache.log4j.LogManager; |
8 |
|
|
import org.apache.log4j.Logger; |
9 |
|
|
|
10 |
|
|
import appl.parallel.client.ClientDataServer; |
11 |
|
|
import appl.parallel.spmd.split.DataPartition; |
12 |
|
|
import appl.parallel.spmd.split.SplittableResource; |
13 |
mojays |
114 |
import de.appl.data.LoadingException; |
14 |
mojays |
2 |
|
15 |
|
|
/** |
16 |
|
|
* This class is used as a base class for loaders. It is especially intended for |
17 |
|
|
* use with the SPMD-Paradigm, but may be used with other loaders, too. It |
18 |
|
|
* implements the reusable stuff of the {@link PartitionDataHandler} Interface. |
19 |
|
|
* Notice that each loader is responsible for exactly one data element. It must |
20 |
|
|
* be {@link Cloneable}, so that multi-data elements can add another element. |
21 |
|
|
* |
22 |
|
|
* @author Dominik Appl |
23 |
|
|
*/ |
24 |
|
|
public abstract class AbstractDataHandler implements PartitionDataHandler { |
25 |
|
|
|
26 |
|
|
protected transient Logger LOG = LogManager.getLogger(this.getClass() |
27 |
|
|
.getName()); |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* The id of the currently handled {@link SplittableResource} |
31 |
|
|
*/ |
32 |
|
|
protected int rootID; |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* The partition bounds (the whole bounds) of the current |
36 |
|
|
* {@link SplittableResource} |
37 |
|
|
*/ |
38 |
|
|
protected Rectangle partitionBounds; |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* the currently handled data (must be initialized before calling |
42 |
|
|
* {@link #unload()} |
43 |
|
|
*/ |
44 |
|
|
protected transient DataPartition data; |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* The unload bounds differ may differ from the partitionBounds. If there is |
48 |
|
|
* a neighborhood region it is important, that only the core-region (without |
49 |
|
|
* the neighborhood) is unloaded. |
50 |
|
|
*/ |
51 |
|
|
protected Rectangle unloadBounds; |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* A {@link ClientDataServer} may be used locally for faster access. |
55 |
|
|
*/ |
56 |
|
|
protected transient ClientDataServer spmdClient; |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Constructs a new {@link AbstractDataHandler}. The local IP address at |
60 |
|
|
* the time of construction is later used on serverside for communication |
61 |
|
|
* (e.g. unloading). |
62 |
|
|
* |
63 |
|
|
* @param rootID |
64 |
|
|
* the id of the data |
65 |
|
|
* @param client |
66 |
|
|
* a {@link ClientDataServer} which may be used to get meta |
67 |
|
|
* information on client side before transferring the loader to |
68 |
|
|
* its destination |
69 |
|
|
* @param partitionBounds |
70 |
|
|
* the bounds of the partition to be retrieved on server side |
71 |
|
|
* @param unloadBounds |
72 |
|
|
* the bounds of the partition which is to be uploaded to the |
73 |
|
|
* client after calculation (may only be the calculation area) |
74 |
|
|
*/ |
75 |
|
|
public AbstractDataHandler(int rootID, ClientDataServer client, |
76 |
|
|
Rectangle partitionBounds, Rectangle unloadBounds) { |
77 |
|
|
this.spmdClient = client; |
78 |
|
|
this.rootID = rootID; |
79 |
|
|
this.partitionBounds = partitionBounds; |
80 |
|
|
this.unloadBounds = unloadBounds; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* sets a local {@link ClientDataServer} which MAY be used by the handler |
85 |
|
|
* for local access |
86 |
|
|
* |
87 |
|
|
* @param localSPMDClient |
88 |
|
|
*/ |
89 |
|
|
public void setSPMDClient(ClientDataServer localSPMDClient) { |
90 |
|
|
this.spmdClient = localSPMDClient; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* (empty constructors are important for deserialization) |
95 |
|
|
* |
96 |
|
|
* @see #AbstractDataHandler(int, ClientDataServer, Rectangle, Rectangle) |
97 |
|
|
*/ |
98 |
|
|
public AbstractDataHandler() { |
99 |
|
|
this(-1, null, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 0, 0)); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
/* |
103 |
|
|
* (non-Javadoc) |
104 |
|
|
* |
105 |
|
|
* @see appl.data.DataLoader#getLoadInfo() |
106 |
|
|
*/ |
107 |
|
|
public abstract String getLoadInfo(); |
108 |
|
|
|
109 |
|
|
/* |
110 |
|
|
* (non-Javadoc) |
111 |
|
|
* |
112 |
|
|
* @see appl.data.DataLoader#getLoadInfo() |
113 |
|
|
*/ |
114 |
|
|
public abstract String getUnloadInfo(); |
115 |
|
|
|
116 |
|
|
/* |
117 |
|
|
* (non-Javadoc) |
118 |
|
|
* |
119 |
|
|
* @see appl.data.DataLoader#load() |
120 |
|
|
*/ |
121 |
|
|
public abstract DataPartition load() throws LoadingException; |
122 |
|
|
|
123 |
|
|
/** |
124 |
|
|
* Initializes the {@link Logger} after deserialization (used by |
125 |
|
|
* {@link java.io.Serializable}) |
126 |
|
|
* |
127 |
|
|
* @throws IOException |
128 |
|
|
* @see Serializable |
129 |
|
|
*/ |
130 |
|
|
private synchronized void readObject(java.io.ObjectInputStream s) |
131 |
|
|
throws IOException, ClassNotFoundException { |
132 |
|
|
// reading standard fields |
133 |
|
|
s.defaultReadObject(); |
134 |
|
|
// initialize Logger |
135 |
|
|
LOG = LogManager.getLogger(this.getClass().getName()); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/* |
139 |
|
|
* (non-Javadoc) |
140 |
|
|
* |
141 |
|
|
* @see appl.data.PartitionDataHandler#setUnloadPartition(java.awt.Rectangle) |
142 |
|
|
*/ |
143 |
|
|
public void setUnloadBounds(Rectangle unloadBounds) { |
144 |
|
|
this.unloadBounds = unloadBounds; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/* |
148 |
|
|
* (non-Javadoc) |
149 |
|
|
* |
150 |
|
|
* @see appl.data.PartitionDataHandler#setBasePartition(appl.parallel.spmd.split.DataPartition) |
151 |
|
|
*/ |
152 |
|
|
public void setBasePartition(DataPartition data) { |
153 |
|
|
this.data = data; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
/* |
157 |
|
|
* (non-Javadoc) |
158 |
|
|
* |
159 |
|
|
* @see appl.data.DataUnloader#unload() |
160 |
|
|
*/ |
161 |
|
|
public abstract void unload(); |
162 |
|
|
|
163 |
|
|
/* |
164 |
|
|
* (non-Javadoc) |
165 |
|
|
* |
166 |
|
|
* @see appl.data.PartitionDataHandler#setRootID(int) |
167 |
|
|
*/ |
168 |
|
|
public void setRootID(int rootID) { |
169 |
|
|
this.rootID = rootID; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
/* |
173 |
|
|
* (non-Javadoc) |
174 |
|
|
* |
175 |
|
|
* @see java.lang.Object#clone() |
176 |
|
|
*/ |
177 |
|
|
public PartitionDataHandler clone() { |
178 |
|
|
return newInstance(rootID, spmdClient, this.unloadBounds, |
179 |
|
|
this.partitionBounds); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
} |