Class File

java.lang.Object
org.cloudbus.cloudsim.resources.File

public class File
extends Object
A class for representing a physical file in a DataCloud environment
Since:
CloudSim Toolkit 1.0
Author:
Uros Cibej, Anthony Sulistio
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int NOT_REGISTERED
    Denotes that this file has not been registered to a Replica Catalogue.
    static int TYPE_UNKNOWN
    Denotes that the type of this file is unknown.
  • Constructor Summary

    Constructors
    Modifier Constructor Description
      File​(String fileName, int fileSize)
    Creates a new DataCloud file with a given size (in MBytes).
      File​(File file)
    Copy constructor that creates a clone from a source file and set the given file as a replica.
    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.
  • Method Summary

    Modifier and Type Method Description
    protected void createAttribute​(int fileSize)  
    FileAttribute getAttribute()
    Gets an attribute of this file.
    int getAttributeSize()
    Gets the size of this object (in byte).
    int getChecksum()
    Gets the file checksum.
    double getCost()
    Gets the cost associated with the file.
    long getCreationTime()
    Gets the file creation time (in millisecond).
    Datacenter getDatacenter()
    Gets the Datacenter that stores the file.
    double getLastUpdateTime()
    Gets the last update time (in seconds).
    String getName()
    Gets the file name.
    String getOwnerName()
    Gets the owner name of this file.
    long getRegistrationID()
    Gets the file registration ID.
    int getSize()
    Gets the file size (in MBytes).
    int getSizeInByte()
    Gets the file size (in bytes).
    double getTransactionTime()
    Gets the last transaction time of the file (in second).
    int getType()
    Gets the file type.
    boolean isDeleted()
    Checks if the file was deleted or not.
    boolean isMasterCopy()
    Checks whether the file is a master copy or replica.
    boolean isRegistered()
    Checks if the file is already registered to a Replica Catalogue.
    static boolean isValid​(String fileName)
    Check if the name of a file is valid or not.
    static boolean isValid​(File file)
    Check if a file object is valid or not.
    File makeMasterCopy()
    Clone the current file and make the new file as a master copy as well.
    File makeReplica()
    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.
    File setDatacenter​(Datacenter datacenter)
    Sets the Datacenter that will store the file.
    void setDeleted​(boolean deleted)
    Sets the file as deleted or not.
    void setMasterCopy​(boolean masterCopy)
    Marks the file as a master copy or replica.
    void setName​(String name)
    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).
    String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • NOT_REGISTERED

      public static final int NOT_REGISTERED
      Denotes that this file has not been registered to a Replica Catalogue.
      See Also:
      Constant Field Values
    • TYPE_UNKNOWN

      public static final int TYPE_UNKNOWN
      Denotes that the type of this file is unknown.
      See Also:
      Constant Field Values
  • Constructor Details

    • 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) throws IllegalArgumentException
      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) throws IllegalArgumentException
      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
  • Method Details

    • 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
    • createAttribute

      protected void createAttribute​(int fileSize)
    • 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
    • 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
    • getAttribute

      public FileAttribute getAttribute()
      Gets an attribute of this file.
      Returns:
      a file attribute
    • setAttribute

      protected void setAttribute​(FileAttribute attribute)
      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

      public String getName()
      Gets the file name.
      Returns:
      the file name
    • 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
    • getOwnerName

      public String 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 use CloudSim.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

      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
    • 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

      public String toString()
      Overrides:
      toString in class Object
    • getDatacenter

      public Datacenter getDatacenter()
      Gets the Datacenter that stores the file.
      Returns:
    • 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
      Returns: