Package org.cloudbus.cloudsim.util
Class TraceReaderAbstract
java.lang.Object
org.cloudbus.cloudsim.util.TraceReaderAbstract
- All Implemented Interfaces:
TraceReader
- Direct Known Subclasses:
SwfWorkloadFileReader
,TraceReaderBase
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
-
Field Summary
Fields inherited from interface org.cloudbus.cloudsim.util.TraceReader
LOGGER
-
Constructor Summary
ModifierConstructorDescriptionTraceReaderAbstract
(String filePath) Create a new SwfWorkloadFileReader object.protected
TraceReaderAbstract
(String filePath, InputStream inputStream) Create a new SwfWorkloadFileReader object. -
Method Summary
Modifier and TypeMethodDescriptionString[]
Gets the Strings that identifies the start of a comment line.Gets the regex defining how fields are delimited in the trace file.Gets the path of the trace file.protected InputStream
int
Gets the number of the last line read from the trace file (starting from 0).int
Gets the maximum number of lines of the workload reader that will be read.protected String[]
parseTraceLine
(String line) protected void
Reads traces from the file indicated by thegetFilePath()
, then creates a Cloudlet for each line read.protected void
readGZIPFile
(InputStream inputStream, Function<String[], Boolean> processParsedLineFunction) Reads traces from a gzip file, then creates a Cloudlet for each line read.protected void
readTextFile
(InputStream inputStream, Function<String[], Boolean> processParsedLineFunction) Reads traces from a text file, then creates a Cloudlet for each line read.protected boolean
readZipFile
(InputStream inputStream, Function<String[], Boolean> processParsedLineFunction) Reads a set of trace files inside a Zip file, then creates a Cloudlet for each line read.setCommentString
(String... commentString) Sets a string that identifies the start of a comment line.final TraceReader
setFieldDelimiterRegex
(String fieldDelimiterRegex) Sets the regex defining how fields are delimited in the trace file.final TraceReader
setMaxLinesToRead
(int maxLinesToRead) Sets the maximum number of lines of the workload reader that will be read.
-
Constructor Details
-
TraceReaderAbstract
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 0FileNotFoundException
- when the trace file is not foundIllegalArgumentException
- when the workload trace file name is null or emptyIOException
-
TraceReaderAbstract
Create a new SwfWorkloadFileReader object.- Parameters:
filePath
- the workload trace file path in one of the following formats: ASCII text, zip, gz.inputStream
- aInputStreamReader
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
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 interfaceTraceReader
- Parameters:
commentString
- the comment Strings to set
-
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 interfaceTraceReader
- Returns:
-
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 interfaceTraceReader
- Returns:
-
setFieldDelimiterRegex
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 interfaceTraceReader
- 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 interfaceTraceReader
- Returns:
-
setMaxLinesToRead
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 interfaceTraceReader
- Parameters:
maxLinesToRead
- the maximum number of lines to set
-
getFilePath
Description copied from interface:TraceReader
Gets the path of the trace file.- Specified by:
getFilePath
in interfaceTraceReader
- Returns:
-
getInputStream
-
parseTraceLine
-
readTextFile
protected void readTextFile(InputStream inputStream, Function<String[], Boolean> processParsedLineFunction) throws IOExceptionReads traces from a text file, then creates a Cloudlet for each line read.- Parameters:
inputStream
- aInputStream
to read the fileprocessParsedLineFunction
- aFunction
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 IOExceptionReads traces from a gzip file, then creates a Cloudlet for each line read.- Parameters:
inputStream
- aInputStream
to read the fileprocessParsedLineFunction
- aFunction
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 IOExceptionReads a set of trace files inside a Zip file, then creates a Cloudlet for each line read.- Parameters:
inputStream
- aInputStream
to read the fileprocessParsedLineFunction
- aFunction
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
Reads traces from the file indicated by thegetFilePath()
, then creates a Cloudlet for each line read.- Parameters:
processParsedLineFunction
- aFunction
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 interfaceTraceReader
- Returns:
-