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