File

public class File

A class for representing a physical file in a DataCloud environment

Author:Uros Cibej, Anthony Sulistio

Fields

NOT_REGISTERED

public static final int NOT_REGISTERED

Denotes that this file has not been registered to a Replica Catalogue.

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN

Denotes that the type of this file is unknown.

Constructors

File

public File(String fileName, int fileSize)

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 name
  • fileSize – 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

public File(File 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

protected File(File file, boolean masterCopy)

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 clone
  • masterCopy – false to set the cloned file as a replica, true to set the cloned file as a master copy
Throws:
  • IllegalArgumentException

Methods

createAttribute

protected void createAttribute(int fileSize)

getAttribute

public FileAttribute getAttribute()

Gets an attribute of this file.

Returns:a 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)

getChecksum

public int getChecksum()

Gets the file checksum.

Returns:file checksum

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)

getDatacenter

public Datacenter getDatacenter()

Gets the Datacenter that stores the file.

getLastUpdateTime

public double getLastUpdateTime()

Gets the last update time (in seconds).

Returns:the last update time (in seconds)

getName

public String getName()

Gets the file name.

Returns:the file name

getOwnerName

public String getOwnerName()

Gets the owner name of this file.

Returns:the owner name or null if empty

getRegistrationID

public long getRegistrationID()

Gets the file registration ID.

Returns:registration ID

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)

getTransactionTime

public double getTransactionTime()

Gets the last transaction time of the file (in second).

Returns:the transaction time (in second)

getType

public int getType()

Gets the file type.

Returns:file type

isDeleted

public boolean isDeleted()

Checks if the file was deleted or not.

Returns:true if it was deleted, 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

isRegistered

public boolean isRegistered()

Checks if the file is already registered to a Replica Catalogue.

Returns:true if it is registered, false otherwise

isValid

public static boolean isValid(String fileName)

Check if the name of a file is valid or not.

Parameters:
  • fileName – the file name to be checked for validity
Returns:

true if the file name is valid, false otherwise

isValid

public static boolean isValid(File file)

Check if a file object is valid or not. This method checks whether the given file object itself and its file name are valid.

Parameters:
  • file – the file to be checked for validity
Returns:

true if the file is valid, false otherwise

makeMasterCopy

public File 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

makeReplica

public File 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

setAttribute

protected void setAttribute(FileAttribute attribute)

Sets an attribute of this file.

Parameters:
  • attribute – file attribute

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

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

setDatacenter

public final File setDatacenter(Datacenter datacenter)

Sets the Datacenter that will store the file. When the file is added to a FileStorage 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

setDeleted

public void setDeleted(boolean deleted)

Sets the file as deleted or not.

Parameters:
  • deletedtrue if it was deleted, false otherwise

setMasterCopy

public void setMasterCopy(boolean masterCopy)

Marks the file as a master copy or replica.

Parameters:
  • masterCopy – a flag denotes true for master copy or false for a replica

setName

public final void setName(String name)

Sets the file name.

Parameters:
  • name – the file name

setOwnerName

public boolean setOwnerName(String name)

Sets the owner name of this file.

Parameters:
  • name – the owner name
Returns:

true if successful, false otherwise

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

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

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

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

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 use org.cloudbus.cloudsim.core.CloudSim.clock() method.

Parameters:
  • time – the last update time (in seconds)
Returns:

true if successful, false otherwise

toString

public String toString()