Class TraceReaderAbstract

java.lang.Object
org.cloudbus.cloudsim.util.TraceReaderAbstract
All Implemented Interfaces:
TraceReader
Direct Known Subclasses:
SwfWorkloadFileReader, TraceReaderBase

public abstract class TraceReaderAbstract extends Object implements TraceReader
An abstract class providing features for subclasses implementing trace file readers for specific file formats.

NOTES:

  • This class can only read trace files in the following format: ASCII text, zip, gz.
  • If you need to load multiple trace files, create multiple instances of this class.
  • If size of the trace reader is huge or contains lots of traces, please increase the JVM heap size accordingly by using java -Xmx option when running the simulation. For instance, you can use java -Xmx200M to define the JVM heap size will be 200MB.

Since:
CloudSim Plus 4.0.0
Author:
Manoel Campos da Silva Filho
  • Constructor Details

    • TraceReaderAbstract

      public TraceReaderAbstract(String filePath) throws IOException
      Create a new SwfWorkloadFileReader object.
      Parameters:
      filePath - the workload trace file path in one of the following formats: ASCII text, zip, gz.
      Throws:
      IllegalArgumentException - when the workload trace file name is null or empty; or the resource PE mips is less or equal to 0
      FileNotFoundException - when the trace file is not found
      IllegalArgumentException - when the workload trace file name is null or empty
      IOException
    • TraceReaderAbstract

      protected TraceReaderAbstract(String filePath, InputStream inputStream)
      Create a new SwfWorkloadFileReader object.
      Parameters:
      filePath - the workload trace file path in one of the following formats: ASCII text, zip, gz.
      inputStream - a InputStreamReader object to read the file
      Throws:
      IllegalArgumentException - when the workload trace file name is null or empty; or the resource PE mips is less or equal to 0
  • Method Details

    • setCommentString

      public TraceReader setCommentString(String... commentString)
      Description copied from interface: TraceReader
      Sets a string that identifies the start of a comment line. If there are multiple ways to comment a line, the different Strings representing comments can be specified as parameters.
      Specified by:
      setCommentString in interface TraceReader
      Parameters:
      commentString - the comment Strings to set
    • getCommentString

      public String[] getCommentString()
      Gets the Strings that identifies the start of a comment line. For instance ; # % //.

      It's returned a defensive copy of the array.

      Specified by:
      getCommentString in interface TraceReader
      Returns:
    • getFieldDelimiterRegex

      public String getFieldDelimiterRegex()
      Description copied from interface: TraceReader
      Gets the regex defining how fields are delimited in the trace file. Usually, this can be just a String with a single character such as a space, comma, semi-colon or tab (\t).
      Specified by:
      getFieldDelimiterRegex in interface TraceReader
      Returns:
    • setFieldDelimiterRegex

      public final TraceReader setFieldDelimiterRegex(String fieldDelimiterRegex)
      Description copied from interface: TraceReader
      Sets the regex defining how fields are delimited in the trace file. Usually, this can be just a String with a single character such as a space, comma or semi-colon or tab (\t).
      Specified by:
      setFieldDelimiterRegex in interface TraceReader
      Parameters:
      fieldDelimiterRegex - the field separator regex to set
    • getMaxLinesToRead

      public int getMaxLinesToRead()
      Description copied from interface: TraceReader
      Gets the maximum number of lines of the workload reader that will be read. The value -1 indicates that all lines will be read, creating a cloudlet from every one.
      Specified by:
      getMaxLinesToRead in interface TraceReader
      Returns:
    • setMaxLinesToRead

      public final TraceReader setMaxLinesToRead(int maxLinesToRead)
      Description copied from interface: TraceReader
      Sets the maximum number of lines of the workload reader that will be read. The value -1 indicates that all lines will be read, creating a cloudlet from every one.
      Specified by:
      setMaxLinesToRead in interface TraceReader
      Parameters:
      maxLinesToRead - the maximum number of lines to set
    • getFilePath

      public String getFilePath()
      Description copied from interface: TraceReader
      Gets the path of the trace file.
      Specified by:
      getFilePath in interface TraceReader
      Returns:
    • getInputStream

      protected InputStream getInputStream()
    • parseTraceLine

      protected String[] parseTraceLine(String line)
    • readTextFile

      protected void readTextFile(InputStream inputStream, Function<String[],Boolean> processParsedLineFunction) throws IOException
      Reads traces from a text file, then creates a Cloudlet for each line read.
      Parameters:
      inputStream - a InputStream to read the file
      processParsedLineFunction - a Function that receives each parsed line as an array and performs an operation over it, returning true if the operation was executed
      Throws:
      IOException - if the there was any error reading the file
    • readGZIPFile

      protected void readGZIPFile(InputStream inputStream, Function<String[],Boolean> processParsedLineFunction) throws IOException
      Reads traces from a gzip file, then creates a Cloudlet for each line read.
      Parameters:
      inputStream - a InputStream to read the file
      processParsedLineFunction - a Function that receives each parsed line as an array and performs an operation over it, returning true if the operation was executed
      Throws:
      IOException - if the there was any error reading the file
    • readZipFile

      protected boolean readZipFile(InputStream inputStream, Function<String[],Boolean> processParsedLineFunction) throws IOException
      Reads a set of trace files inside a Zip file, then creates a Cloudlet for each line read.
      Parameters:
      inputStream - a InputStream to read the file
      processParsedLineFunction - a Function that receives each parsed line as an array and performs an operation over it, returning true if the operation was executed
      Returns:
      true if reading a file is successful; false otherwise.
      Throws:
      IOException - if the there was any error reading the file
    • readFile

      protected void readFile(Function<String[],Boolean> processParsedLineFunction)
      Reads traces from the file indicated by the getFilePath(), then creates a Cloudlet for each line read.
      Parameters:
      processParsedLineFunction - a Function that receives each parsed line as an array and performs an operation over it, returning true if the operation was executed
      Throws:
      UncheckedIOException - if the there was any error reading the file
    • getLastLineNumber

      public int getLastLineNumber()
      Description copied from interface: TraceReader
      Gets the number of the last line read from the trace file (starting from 0).
      Specified by:
      getLastLineNumber in interface TraceReader
      Returns: