Package org.cloudbus.cloudsim.resources
Class File
java.lang.Object
org.cloudbus.cloudsim.resources.File
A class for representing a physical file in a DataCloud environment
- Since:
- CloudSim Toolkit 1.0
- Author:
- Uros Cibej, Anthony Sulistio
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Denotes that this file has not been registered to a Replica Catalogue.static final int
Denotes that the type of this file is unknown. -
Constructor Summary
ModifierConstructorDescriptionCreates a new DataCloud file with a given size (in MBytes).Copy constructor that creates a clone from a source file and set the given file as a replica.protected
Copy constructor that creates a clone from a source file and set the given file as a replica or master copy. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
createAttribute
(int fileSize) Gets an attribute of this file.int
Gets the size of this object (in byte).int
Gets the file checksum.double
getCost()
Gets the cost associated with the file.long
Gets the file creation time (in millisecond).Gets the Datacenter that stores the file.double
Gets the last update time (in seconds).getName()
Gets the file name.Gets the owner name of this file.long
Gets the file registration ID.int
getSize()
Gets the file size (in MBytes).int
Gets the file size (in bytes).double
Gets the last transaction time of the file (in second).int
getType()
Gets the file type.boolean
Checks if the file was deleted or not.boolean
Checks whether the file is a master copy or replica.boolean
Checks if the file is already registered to a Replica Catalogue.Clone the current file and make the new file as a master copy as well.Clone the current file and set the cloned one as a replica.protected void
setAttribute
(FileAttribute attribute) Sets an attribute of this file.boolean
setChecksum
(int checksum) Sets the checksum of the file.boolean
setCost
(double cost) Sets the cost associated with the file.final File
setDatacenter
(Datacenter datacenter) Sets the Datacenter that will store the file.void
setDeleted
(boolean deleted) Sets the file as deleted or not.setMasterCopy
(boolean masterCopy) Marks the file as a master copy or replica.final void
Sets the file name.boolean
setOwnerName
(String name) Sets the owner name of this file.boolean
setRegistrationID
(int id) Sets the file registration ID (published by a Replica Catalogue entity).boolean
setSize
(int fileSize) Sets the file size (in MBytes).boolean
setTransactionTime
(double time) Sets the current transaction time (in second) of this file.boolean
setType
(int type) Sets the file type (for instance, raw, tag, etc).boolean
setUpdateTime
(double time) Sets the last update time of this file (in seconds).toString()
static void
Check if a file object is valid or not, whether the given file object itself and its file name are valid.static String
validateFileName
(String fileName) Check if the name of a file is valid or not.
-
Field Details
-
NOT_REGISTERED
public static final int NOT_REGISTEREDDenotes that this file has not been registered to a Replica Catalogue.- See Also:
-
TYPE_UNKNOWN
public static final int TYPE_UNKNOWNDenotes that the type of this file is unknown.- See Also:
-
-
Constructor Details
-
File
Creates a new DataCloud file with a given size (in MBytes).
NOTE: By default, a newly-created file is set to a master copy.- Parameters:
fileName
- file namefileSize
- file size in MBytes- Throws:
IllegalArgumentException
- when one of the following scenarios occur:- the file name is empty or null
- the file size is zero or negative numbers
-
File
Copy constructor that creates a clone from a source file and set the given file as a replica.- Parameters:
file
- the source file to create a copy and that will be set as a replica- Throws:
IllegalArgumentException
- when the source file is null
-
File
Copy constructor that creates a clone from a source file and set the given file as a replica or master copy.- Parameters:
file
- the file to clonemasterCopy
- false to set the cloned file as a replica, true to set the cloned file as a master copy- Throws:
IllegalArgumentException
-
-
Method Details
-
validate
Check if a file object is valid or not, whether the given file object itself and its file name are valid.- Parameters:
file
- the file to be checked for validity- Throws:
NullPointerException
- if the given file is nullIllegalArgumentException
- if the name of the file is blank or null
-
validateFileName
Check if the name of a file is valid or not.- Parameters:
fileName
- the file name to be checked for validity- Returns:
- the given fileName if it's valid
- Throws:
NullPointerException
- if the file name is nullIllegalArgumentException
- if the file name is blank
-
createAttribute
protected void createAttribute(int fileSize) -
makeReplica
Clone the current file and set the cloned one as a replica.- Returns:
- a clone of the current file (as a replica) or null if an error occurs
-
makeMasterCopy
Clone the current file and make the new file as a master copy as well.- Returns:
- a clone of the current file (as a master copy) or null if an error occurs
-
getAttribute
Gets an attribute of this file.- Returns:
- a file attribute
-
setAttribute
Sets an attribute of this file.- Parameters:
attribute
- file attribute
-
getAttributeSize
public int getAttributeSize()Gets the size of this object (in byte).
NOTE: This object size is NOT the actual file size. Moreover, this size is used for transferring this object over a network.- Returns:
- the object size (in byte)
-
getName
Gets the file name.- Returns:
- the file name
-
setName
Sets the file name.- Parameters:
name
- the file name
-
setOwnerName
Sets the owner name of this file.- Parameters:
name
- the owner name- Returns:
- true if successful, false otherwise
-
getOwnerName
Gets the owner name of this file.- Returns:
- the owner name or null if empty
-
getSize
public int getSize()Gets the file size (in MBytes).- Returns:
- the file size (in MBytes)
-
getSizeInByte
public int getSizeInByte()Gets the file size (in bytes).- Returns:
- the file size (in bytes)
-
setSize
public boolean setSize(int fileSize) Sets the file size (in MBytes).- Parameters:
fileSize
- the file size (in MBytes)- Returns:
- true if successful, false otherwise
-
setUpdateTime
public boolean setUpdateTime(double time) Sets the last update time of this file (in seconds).
NOTE: This time is relative to the start time. Preferably useCloudSim.clock()
method.- Parameters:
time
- the last update time (in seconds)- Returns:
- true if successful, false otherwise
-
getLastUpdateTime
public double getLastUpdateTime()Gets the last update time (in seconds).- Returns:
- the last update time (in seconds)
-
setRegistrationID
public boolean setRegistrationID(int id) Sets the file registration ID (published by a Replica Catalogue entity).- Parameters:
id
- registration ID- Returns:
- true if successful, false otherwise
-
getRegistrationID
public long getRegistrationID()Gets the file registration ID.- Returns:
- registration ID
-
setType
public boolean setType(int type) Sets the file type (for instance, raw, tag, etc).- Parameters:
type
- a file type- Returns:
- true if successful, false otherwise
-
getType
public int getType()Gets the file type.- Returns:
- file type
-
setChecksum
public boolean setChecksum(int checksum) Sets the checksum of the file.- Parameters:
checksum
- the checksum of this file- Returns:
- true if successful, false otherwise
-
getChecksum
public int getChecksum()Gets the file checksum.- Returns:
- file checksum
-
setCost
public boolean setCost(double cost) Sets the cost associated with the file.- Parameters:
cost
- cost of this file- Returns:
- true if successful, false otherwise
-
getCost
public double getCost()Gets the cost associated with the file.- Returns:
- the cost of this file
-
getCreationTime
public long getCreationTime()Gets the file creation time (in millisecond).- Returns:
- the file creation time (in millisecond)
-
isRegistered
public boolean isRegistered()Checks if the file is already registered to a Replica Catalogue.- Returns:
- true if it is registered, false otherwise
-
isMasterCopy
public boolean isMasterCopy()Checks whether the file is a master copy or replica.- Returns:
- true if it is a master copy or false otherwise
-
setMasterCopy
Marks the file as a master copy or replica.- Parameters:
masterCopy
- a flag denotes true for master copy or false for a replica
-
isDeleted
public boolean isDeleted()Checks if the file was deleted or not.- Returns:
- true if it was deleted, false otherwise
-
setDeleted
public void setDeleted(boolean deleted) Sets the file as deleted or not.- Parameters:
deleted
- true if it was deleted, false otherwise
-
setTransactionTime
public boolean setTransactionTime(double time) Sets the current transaction time (in second) of this file. This transaction time can be related to the operation of adding, deleting or getting the file on a Datacenter's storage.- Parameters:
time
- the transaction time (in second)- Returns:
- true if successful, false otherwise
-
getTransactionTime
public double getTransactionTime()Gets the last transaction time of the file (in second).- Returns:
- the transaction time (in second)
-
toString
-
getDatacenter
Gets the Datacenter that stores the file.- Returns:
-
setDatacenter
Sets the Datacenter that will store the file. When the file is added to aFileStorage
and such a storage is attached to a Datacenter, the Datacenter sets itself for all files of that storage.- Parameters:
datacenter
- the Datacenter that will store the file- Returns:
-