HarddriveStorage

public class HarddriveStorage 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)
Author:Uros Cibej, Anthony Sulistio, Manoel Campos da Silva Filho

Fields

DEF_LATENCY_SECS

public static final double DEF_LATENCY_SECS

DEF_SEEK_TIME_SECS

public static final double DEF_SEEK_TIME_SECS

Constructors

HarddriveStorage

public HarddriveStorage(String name, long capacity)

Creates a new hard drive storage with a given name and capacity.

Parameters:
  • name – the name of the new hard drive storage
  • capacity – the capacity in MByte
Throws:
  • IllegalArgumentException – when the name and the capacity are not valid

HarddriveStorage

public HarddriveStorage(long capacity)

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

Methods

addFile

public double addFile(File file)

{@inheritDoc}

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.

Parameters:
Returns:

{@inheritDoc}

addFile

public double addFile(List<File> list)

addReservedFile

public double addReservedFile(File file)

contains

public boolean contains(String fileName)

contains

public boolean contains(File file)

deleteFile

public File deleteFile(String fileName)

deleteFile

public double deleteFile(File file)

getAllocatedResource

public long getAllocatedResource()

getAvailableResource

public long getAvailableResource()

getAvgSeekTime

public double getAvgSeekTime()

Gets the average seek time of the hard drive in seconds.

Returns:the average seek time in seconds

getCapacity

public long getCapacity()

getFile

public File getFile(String fileName)

getFileList

public List<File> getFileList()

getFileNameList

public List<String> getFileNameList()

getLatency

public double getLatency()

getMaxTransferRate

public double getMaxTransferRate()

getName

public String getName()

getNumStoredFile

public int getNumStoredFile()

getTransferTime

public double getTransferTime(String fileName)

getTransferTime

public double getTransferTime(File file)

getTransferTime

public double getTransferTime(int fileSize)

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

hasFile

public boolean hasFile(String fileName)

hasPotentialAvailableSpace

public boolean hasPotentialAvailableSpace(int fileSize)

isAmountAvailable

public boolean isAmountAvailable(long amountToCheck)

isAmountAvailable

public boolean isAmountAvailable(double amountToCheck)

isFull

public boolean isFull()

renameFile

public boolean renameFile(File file, String newName)

reserveSpace

public boolean reserveSpace(int fileSize)

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

public boolean setAvgSeekTime(double seekTime, ContinuousDistribution gen)

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 seconds
  • gen – the ContinuousGenerator which generates seek times
Returns:

true if the values is greater than zero and was set successfully, false otherwise

setLatency

public void setLatency(double latency)

setMaxTransferRate

public void setMaxTransferRate(double maxTransferRate)