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

    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)
     
    Gets an attribute of this file.
    int
    Gets the size of this object (in byte).
    int
    Gets the file checksum.
    double
    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).
    Gets the file name.
    Gets the owner name of this file.
    long
    Gets the file registration ID.
    int
    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
    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
    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
    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
    Sets the owner name of this file.
    boolean
    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).
     
    static void
    validate(File file)
    Check if a file object is valid or not, whether the given file object itself and its file name are valid.
    static String
    Check if the name of a file is valid or not.

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

      public static final int TYPE_UNKNOWN
      Denotes that the type of this file is unknown.
      See Also:
  • 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

    • validate

      public static void validate(File file)
      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 null
      IllegalArgumentException - if the name of the file is blank or null
    • validateFileName

      public static String validateFileName(String fileName)
      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 null
      IllegalArgumentException - if the file name is blank
    • 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 File 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: