Package org.cloudbus.cloudsim.resources
Class HarddriveStorage
java.lang.Object
org.cloudbus.cloudsim.resources.HarddriveStorage
- All Implemented Interfaces:
FileStorage
,Resource
,ResourceCapacity
- Direct Known Subclasses:
SanStorage
public class HarddriveStorage extends Object implements FileStorage
An implementation of a Hard Drive (HD) storage device. It simulates the behavior of a typical hard drive.
The default values for this storage are those of a
"Maxtor DiamondMax 10 ATA"
hard disk with the following parameters:
- latency = 4.17 ms
- avg seek time = 9 m/s
- max transfer rate = 1064 Megabits/sec (133 MBytes/sec)
- Since:
- CloudSim Toolkit 1.0
- Author:
- Uros Cibej, Anthony Sulistio, Manoel Campos da Silva Filho
-
Field Summary
Fields inherited from interface org.cloudbus.cloudsim.resources.FileStorage
FILE_NOT_FOUND
-
Constructor Summary
Constructors Constructor Description HarddriveStorage(long capacity)
Creates a new hard drive storage with a given capacity.HarddriveStorage(String name, long capacity)
Creates a new hard drive storage with a given name and capacity. -
Method Summary
Modifier and Type Method Description double
addFile(List<File> list)
Adds a set of files to the storage.double
addFile(File file)
Adds a file to the storage.double
addReservedFile(File file)
Adds a file for which the space has already been reserved.boolean
contains(String fileName)
Checks whether a file exists in the storage or not.boolean
contains(File file)
Checks whether a file is stored in the storage or not.File
deleteFile(String fileName)
Removes a file from the storage.double
deleteFile(File file)
Removes a file from the storage.long
getAllocatedResource()
Gets the current total amount of allocated resource.long
getAvailableResource()
Gets the amount of the resource that is available (free).double
getAvgSeekTime()
Gets the average seek time of the hard drive in seconds.long
getCapacity()
Gets the total capacity of the resource.File
getFile(String fileName)
Gets the file with the specified name.List<File>
getFileList()
Gets a read-only list with all files stored on the device.List<String>
getFileNameList()
Gets a read-only list with the names of all files stored on the device.double
getLatency()
Gets the latency of this hard drive in seconds.double
getMaxTransferRate()
Gets the maximum local transfer rate of the storage in Mega-bits/sec, i.e., the physical device reading speed.String
getName()
int
getNumStoredFile()
Gets the number of files stored on this device.double
getTransferTime(int fileSize)
Gets the transfer time of a given file.protected double
getTransferTime(int fileSize, double speed)
Gets the time to transfer a file (in MBytes) according to a given transfer speed (in Mbits/sec).double
getTransferTime(String fileName)
Gets the transfer time of a given file.double
getTransferTime(File file)
Gets the transfer time of a given file.boolean
hasFile(String fileName)
Checks if the storage device has a specific file.boolean
hasPotentialAvailableSpace(int fileSize)
Checks whether there is enough space on the storage for a certain fileboolean
isAmountAvailable(double amountToCheck)
Checks if there is a specific amount of resource available (free), where such amount is a double value that will be converted to long.boolean
isAmountAvailable(long amountToCheck)
Checks if there is a specific amount of resource available (free).boolean
isFull()
Checks if the resource is full or not.boolean
renameFile(File file, String newName)
Renames a file on the storage.boolean
reserveSpace(int fileSize)
Makes reservation of space on the storage to store a file.boolean
setAvgSeekTime(double seekTime)
Sets the average seek time of the storage in seconds.boolean
setAvgSeekTime(double seekTime, ContinuousDistribution gen)
Sets the average seek time and a new generator of seek times in seconds.void
setLatency(double latency)
Sets the latency of this hard drive in seconds.void
setMaxTransferRate(double maxTransferRate)
Sets the maximum transfer rate of this storage system in Mega-bits/sec, i.e., the physical device reading speed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cloudbus.cloudsim.resources.Resource
getPercentUtilization, isAmountAvailable, isSubClassOf
-
Constructor Details
-
HarddriveStorage
Creates a new hard drive storage with a given name and capacity.- Parameters:
name
- the name of the new hard drive storagecapacity
- the capacity in MByte- Throws:
IllegalArgumentException
- when the name and the capacity are not valid
-
HarddriveStorage
Creates a new hard drive storage with a given capacity. In this case the name of the storage is a default name.- Parameters:
capacity
- the capacity in MByte- Throws:
IllegalArgumentException
- when the name and the capacity are not valid
-
-
Method Details
-
getNumStoredFile
public int getNumStoredFile()Description copied from interface:FileStorage
Gets the number of files stored on this device.- Specified by:
getNumStoredFile
in interfaceFileStorage
- Returns:
- the number of stored files
-
reserveSpace
public boolean reserveSpace(int fileSize)Description copied from interface:FileStorage
Makes reservation of space on the storage to store a file.- Specified by:
reserveSpace
in interfaceFileStorage
- Parameters:
fileSize
- the size to be reserved (in MByte)- Returns:
- true if reservation succeeded, false otherwise
-
addReservedFile
Description copied from interface:FileStorage
Adds a file for which the space has already been reserved. The time taken (in seconds) for adding the specified file can also be found usingFile.getTransactionTime()
.- Specified by:
addReservedFile
in interfaceFileStorage
- Parameters:
file
- the file to be added- Returns:
- the time (in seconds) required to add the file
-
hasPotentialAvailableSpace
public boolean hasPotentialAvailableSpace(int fileSize)Description copied from interface:FileStorage
Checks whether there is enough space on the storage for a certain file- Specified by:
hasPotentialAvailableSpace
in interfaceFileStorage
- Parameters:
fileSize
- size of the file intended to be stored on the device (in MByte)- Returns:
- true if enough space available, false otherwise
-
hasFile
Description copied from interface:FileStorage
Checks if the storage device has a specific file.- Specified by:
hasFile
in interfaceFileStorage
- Parameters:
fileName
- the name of the file to check if it's contained in this storage device.- Returns:
- true if the storage device has the file, false otherwise.
-
getName
- Specified by:
getName
in interfaceFileStorage
- Returns:
- the name of the storage device
-
setLatency
public void setLatency(double latency)Description copied from interface:FileStorage
Sets the latency of this hard drive in seconds.- Specified by:
setLatency
in interfaceFileStorage
- Parameters:
latency
- the new latency in seconds
-
getLatency
public double getLatency()Description copied from interface:FileStorage
Gets the latency of this hard drive in seconds.- Specified by:
getLatency
in interfaceFileStorage
- Returns:
- the latency in seconds
-
setMaxTransferRate
public void setMaxTransferRate(double maxTransferRate)Description copied from interface:FileStorage
Sets the maximum transfer rate of this storage system in Mega-bits/sec, i.e., the physical device reading speed.Despite disk transfer rate is usually defined in MBytes/sec, it's being used Mbits/sec everywhere to avoid confusions, since
Host
,Vm
,Switch
andSanStorage
use such a data unit.- Specified by:
setMaxTransferRate
in interfaceFileStorage
- Parameters:
maxTransferRate
- the maximum transfer rate in Mbits/sec
-
getMaxTransferRate
public double getMaxTransferRate()Description copied from interface:FileStorage
Gets the maximum local transfer rate of the storage in Mega-bits/sec, i.e., the physical device reading speed.- Specified by:
getMaxTransferRate
in interfaceFileStorage
- Returns:
- the maximum transfer rate in Mega-bits/sec
- See Also:
FileStorage.setMaxTransferRate(double)
-
setAvgSeekTime
public boolean setAvgSeekTime(double seekTime)Sets the average seek time of the storage in seconds.- Parameters:
seekTime
- the average seek time in seconds- Returns:
- true if the values is greater than zero and was set successfully, false otherwise
-
setAvgSeekTime
Sets the average seek time and a new generator of seek times in seconds. The generator determines a randomized seek time.- Parameters:
seekTime
- the average seek time in secondsgen
- the ContinuousGenerator which generates seek times- Returns:
- true if the values is greater than zero and was set successfully, false otherwise
-
getAvgSeekTime
public double getAvgSeekTime()Gets the average seek time of the hard drive in seconds.- Returns:
- the average seek time in seconds
-
getFile
Description copied from interface:FileStorage
Gets the file with the specified name. The time taken (in seconds) for getting the specified file can also be found usingFile.getTransactionTime()
.- Specified by:
getFile
in interfaceFileStorage
- Parameters:
fileName
- the name of the needed file- Returns:
- the file with the specified filename; null if not found
-
getFileNameList
Description copied from interface:FileStorage
Gets a read-only list with the names of all files stored on the device.- Specified by:
getFileNameList
in interfaceFileStorage
- Returns:
- a List of file names
-
getFileList
Description copied from interface:FileStorage
Gets a read-only list with all files stored on the device.- Specified by:
getFileList
in interfaceFileStorage
- Returns:
- a List of files
-
getTransferTime
Description copied from interface:FileStorage
Gets the transfer time of a given file.- Specified by:
getTransferTime
in interfaceFileStorage
- Parameters:
fileName
- the name of the file to compute the transfer time (where its size is defined in MByte)- Returns:
- the transfer time in seconds or
FileStorage.FILE_NOT_FOUND
if the file was not found in this storage device
-
getTransferTime
Description copied from interface:FileStorage
Gets the transfer time of a given file.- Specified by:
getTransferTime
in interfaceFileStorage
- Parameters:
file
- the file to compute the transfer time (where its size is defined in MByte)- Returns:
- the transfer time in seconds
-
getTransferTime
public double getTransferTime(int fileSize)Description copied from interface:FileStorage
Gets the transfer time of a given file.- Specified by:
getTransferTime
in interfaceFileStorage
- Parameters:
fileSize
- the size of the file to compute the transfer time (in MByte)- Returns:
- the transfer time in seconds
-
getTransferTime
protected final double getTransferTime(int fileSize, double speed)Gets the time to transfer a file (in MBytes) according to a given transfer speed (in Mbits/sec).- Parameters:
fileSize
- the size of the file to compute the transfer time (in MBytes)speed
- the speed (in MBits/sec) to compute the time to transfer the file- Returns:
- the transfer time in seconds
-
addFile
Adds a file to the storage. The time taken (in seconds) for adding the specified file can also be found usingFile.getTransactionTime()
.First, the method checks if there is enough space on the storage, then it checks if the file with the same name is already taken to avoid duplicate filenames.
- Specified by:
addFile
in interfaceFileStorage
- Parameters:
file
- the file to be added- Returns:
- the time taken (in seconds) for adding the specified file or zero if there isn't available storage space.
-
addFile
Description copied from interface:FileStorage
Adds a set of files to the storage. The time taken (in seconds) for adding each file can also be found usingFile.getTransactionTime()
.- Specified by:
addFile
in interfaceFileStorage
- Parameters:
list
- the files to be added- Returns:
- the time taken (in seconds) for adding the specified file or zero if the file is invalid or there isn't available storage space.
-
deleteFile
Description copied from interface:FileStorage
Removes a file from the storage. The time taken (in seconds) for deleting the specified file can be found usingFile.getTransactionTime()
.- Specified by:
deleteFile
in interfaceFileStorage
- Parameters:
fileName
- the name of the file to be removed- Returns:
- the deleted file.
-
deleteFile
Description copied from interface:FileStorage
Removes a file from the storage. The time taken (in seconds) for deleting the specified file can also be found usingFile.getTransactionTime()
.- Specified by:
deleteFile
in interfaceFileStorage
- Parameters:
file
- the file to be removed- Returns:
- the time taken (in seconds) for deleting the specified file
-
contains
Description copied from interface:FileStorage
Checks whether a file exists in the storage or not.- Specified by:
contains
in interfaceFileStorage
- Parameters:
fileName
- the name of the file we are looking for- Returns:
- true if the file is in the storage, false otherwise
-
contains
Description copied from interface:FileStorage
Checks whether a file is stored in the storage or not.- Specified by:
contains
in interfaceFileStorage
- Parameters:
file
- the file we are looking for- Returns:
- true if the file is in the storage, false otherwise
-
renameFile
Description copied from interface:FileStorage
Renames a file on the storage. The time taken (in seconds) for renaming the specified file can also be found usingFile.getTransactionTime()
.- Specified by:
renameFile
in interfaceFileStorage
- Parameters:
file
- the file we would like to renamenewName
- the new name of the file- Returns:
- true if the renaming succeeded, false otherwise
-
getCapacity
public long getCapacity()Description copied from interface:ResourceCapacity
Gets the total capacity of the resource.- Specified by:
getCapacity
in interfaceResourceCapacity
- Returns:
- the total resource capacity
-
getAvailableResource
public long getAvailableResource()Description copied from interface:Resource
Gets the amount of the resource that is available (free).- Specified by:
getAvailableResource
in interfaceResource
- Returns:
- the amount of available resource
-
getAllocatedResource
public long getAllocatedResource()Description copied from interface:Resource
Gets the current total amount of allocated resource.- Specified by:
getAllocatedResource
in interfaceResource
- Returns:
- amount of allocated resource
-
isAmountAvailable
public boolean isAmountAvailable(long amountToCheck)Description copied from interface:Resource
Checks if there is a specific amount of resource available (free).- Specified by:
isAmountAvailable
in interfaceResource
- Parameters:
amountToCheck
- the amount of resource to check if is free.- Returns:
- true if the specified amount is free; false otherwise
-
isAmountAvailable
public boolean isAmountAvailable(double amountToCheck)Description copied from interface:Resource
Checks if there is a specific amount of resource available (free), where such amount is a double value that will be converted to long.This method is just a shorthand to avoid explicitly converting a double to long.
- Specified by:
isAmountAvailable
in interfaceResource
- Parameters:
amountToCheck
- the amount of resource to check if is free.- Returns:
- true if the specified amount is free; false otherwise
- See Also:
Resource.isAmountAvailable(long)
-
isFull
public boolean isFull()Description copied from interface:Resource
Checks if the resource is full or not.
-