-
Notifications
You must be signed in to change notification settings - Fork 0
/
File
417 lines (366 loc) · 10.2 KB
/
File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
/**
* A class for representing a physical file in a DataCloud environment
*
* @author Uros Cibej
* @author Anthony Sulistio
* @since CloudSim Toolkit 1.0
*/
public class File {
private String name; // logical file name
private FileAttribute attribute; // a file attribute
// a transaction time for adding / getting /deleting this file
private double transactionTime;
/** Denotes that this file has not been registered to a Replica Catalogue */
public static final int NOT_REGISTERED = -1;
/** Denotes that the type of this file is unknown */
public static final int TYPE_UNKOWN = 0;
/** Denotes that the type of this file is a raw data */
public static final int TYPE_RAW_DATA = 1;
/** Denotes that the type of this file is a reconstructed data */
public static final int TYPE_RECONSTRUCTED_DATA = 2;
/** Denotes that the type of this file is a tag data */
public static final int TYPE_TAG_DATA = 3;
/**
* Creates a new DataCloud file with a given size (in MBytes). <br>
* NOTE: By default, a newly-created file is set to a <b>master</b> copy.
*
* @param fileName file name
* @param fileSize file size is in MBytes
* @throws ParameterException This happens when one of the following scenarios occur:
* <ul>
* <li>the file name is empty or <tt>null</tt>
* <li>the file size is zero or negative numbers
* </ul>
*/
public File(String fileName, int fileSize) throws ParameterException {
if (fileName == null || fileName.length() == 0) {
throw new ParameterException("File(): Error - invalid file name.");
}
if (fileSize <= 0) {
throw new ParameterException("File(): Error - size <= 0.");
}
name = fileName;
attribute = new FileAttribute(fileName, fileSize);
transactionTime = 0;
}
/**
* Copy constructor, i.e. cloning from a source file into this object, but this object is set to
* a <b>replica</b>
*
* @param file the source of a File object to copy
* @throws ParameterException This happens when the source file is <tt>null</tt>
*/
public File(File file) throws ParameterException {
if (file == null) {
throw new ParameterException("File(): Error - file is null.");
}
// copy the attributes into the file
FileAttribute fileAttr = file.getFileAttribute();
attribute.copyValue(fileAttr);
fileAttr.setMasterCopy(false); // set this file to replica
}
/**
* Clone this file but the clone file is set to a <b>replica</b>
*
* @return a clone of this file (as a replica) or <tt>null</tt> if an error occurs
*/
public File makeReplica() {
return makeCopy();
}
/**
* Clone this file and make the new file as a <b>master</b> copy as well
*
* @return a clone of this file (as a master copy) or <tt>null</tt> if an error occurs
*/
public File makeMasterCopy() {
File file = makeCopy();
if (file != null) {
file.setMasterCopy(true);
}
return file;
}
/**
* Makes a copy of this file
*
* @return a clone of this file (as a replica) or <tt>null</tt> if an error occurs
*/
private File makeCopy() {
File file = null;
try {
file = new File(name, attribute.getFileSize());
FileAttribute fileAttr = file.getFileAttribute();
attribute.copyValue(fileAttr);
fileAttr.setMasterCopy(false); // set this file to replica
} catch (Exception e) {
file = null;
}
return file;
}
/**
* Gets an attribute of this file
*
* @return a file attribute
*/
public FileAttribute getFileAttribute() {
return attribute;
}
/**
* Gets the size of this object (in byte).<br>
* NOTE: This object size is NOT the actual file size. Moreover, this size is used for
* transferring this object over a network.
*
* @return the object size (in byte)
*/
public int getAttributeSize() {
return attribute.getAttributeSize();
}
/**
* Sets the resource ID that stores this file
*
* @param resourceID a resource ID
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setResourceID(int resourceID) {
return attribute.setResourceID(resourceID);
}
/**
* Gets the resource ID that stores this file
*
* @return the resource ID
*/
public int getResourceID() {
return attribute.getResourceID();
}
/**
* Returns the file name
*
* @return the file name
*/
public String getName() {
return attribute.getName();
}
/**
* Sets the file name
*
* @param name the file name
*/
public void setName(String name) {
attribute.setName(name);
}
/**
* Sets the owner name of this file
*
* @param name the owner name
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setOwnerName(String name) {
return attribute.setOwnerName(name);
}
/**
* Gets the owner name of this file
*
* @return the owner name or <tt>null</tt> if empty
*/
public String getOwnerName() {
return attribute.getOwnerName();
}
/**
* Gets the file size (in MBytes)
*
* @return the file size (in MBytes)
*/
public int getSize() {
return attribute.getFileSize();
}
/**
* Gets the file size (in bytes)
*
* @return the file size (in bytes)
*/
public int getSizeInByte() {
return attribute.getFileSizeInByte();
}
/**
* Sets the file size (in MBytes)
*
* @param fileSize the file size (in MBytes)
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setFileSize(int fileSize) {
return attribute.setFileSize(fileSize);
}
/**
* Sets the last update time of this file (in seconds)<br>
* NOTE: This time is relative to the start time. Preferably use
* {@link gridsim.CloudSim#clock()} method.
*
* @param time the last update time (in seconds)
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setUpdateTime(double time) {
return attribute.setUpdateTime(time);
}
/**
* Gets the last update time (in seconds)
*
* @return the last update time (in seconds)
*/
public double getLastUpdateTime() {
return attribute.getLastUpdateTime();
}
/**
* Sets the file registration ID (published by a Replica Catalogue entity)
*
* @param id registration ID
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setRegistrationID(int id) {
return attribute.setRegistrationId(id);
}
/**
* Gets the file registration ID
*
* @return registration ID
*/
public int getRegistrationID() {
return attribute.getRegistrationID();
}
/**
* Sets the file type (e.g. raw, tag, etc)
*
* @param type a file type
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setType(int type) {
return attribute.setType(type);
}
/**
* Gets this file type
*
* @return file type
*/
public int getType() {
return attribute.getType();
}
/**
* Sets the checksum of this file
*
* @param checksum the checksum of this file
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setChecksum(int checksum) {
return attribute.setChecksum(checksum);
}
/**
* Gets the file checksum
*
* @return file checksum
*/
public int getChecksum() {
return attribute.getChecksum();
}
/**
* Sets the cost associated with this file
*
* @param cost cost of this file
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
*/
public boolean setCost(double cost) {
return attribute.setCost(cost);
}
/**
* Gets the cost associated with this file
*
* @return the cost of this file
*/
public double getCost() {
return attribute.getCost();
}
/**
* Gets the file creation time (in millisecond)
*
* @return the file creation time (in millisecond)
*/
public long getCreationTime() {
return attribute.getCreationTime();
}
/**
* Checks if this file already registered to a Replica Catalogue
*
* @return <tt>true</tt> if it is registered, <tt>false</tt> otherwise
*/
public boolean isRegistered() {
return attribute.isRegistered();
}
/**
* Marks this file as a master copy or replica
*
* @param masterCopy a flag denotes <tt>true</tt> for master copy or <tt>false</tt> for a
* replica
*/
public void setMasterCopy(boolean masterCopy) {
attribute.setMasterCopy(masterCopy);
}
/**
* Checks whether this file is a master copy or replica
*
* @return <tt>true</tt> if it is a master copy or <tt>false</tt> otherwise
*/
public boolean isMasterCopy() {
return attribute.isMasterCopy();
}
/**
* Marks this file as a read only or not
*
* @param readOnly a flag denotes <tt>true</tt> for read only or <tt>false</tt> for re-writeable
*/
public void setReadOnly(boolean readOnly) {
attribute.setReadOnly(readOnly);
}
/**
* Checks whether this file is a read only or not
*
* @return <tt>true</tt> if it is a read only or <tt>false</tt> otherwise
*/
public boolean isReadOnly() {
return attribute.isReadOnly();
}
/**
* Sets the current transaction time (in second) of this file. This transaction time can be
* related to the operation of adding / deleting / getting this file on a resource's storage.
*
* @param time the transaction time (in second)
* @return <tt>true</tt> if successful, <tt>false</tt> otherwise
* @see gridsim.datagrid.storage.Storage#addFile(File)
* @see gridsim.datagrid.storage.Storage#addFile(List)
* @see gridsim.datagrid.storage.Storage#addReservedFile(File)
* @see gridsim.datagrid.storage.Storage#deleteFile(File)
* @see gridsim.datagrid.storage.Storage#deleteFile(String)
* @see gridsim.datagrid.storage.Storage#deleteFile(String, File)
* @see gridsim.datagrid.storage.Storage#getFile(String)
* @see gridsim.datagrid.storage.Storage#renameFile(File, String)
*/
public boolean setTransactionTime(double time) {
if (time < 0) {
return false;
}
transactionTime = time;
return true;
}
/**
* Gets the last transaction time of this file (in second).
*
* @return the transaction time (in second)
*/
public double getTransactionTime() {
return transactionTime;
}
}