Package io.github.sumeetk321
Class FIFOChannel<T>
java.lang.Object
io.github.sumeetk321.FIFOChannel<T>
- Type Parameters:
T
- a generic type which determines the data type in the channel
This class defines the first-in-first-out channel object. It is essentially a
wrapper around a Queue object, but also defines the amount of tokens that the
source outputs, as well as the amount of tokens that the destination consumes
to perform its computation. Each node contains several of these objects.
- Author:
- Sumeet Kulkarni
-
Constructor Summary
ConstructorDescriptionDefault constructor.FIFOChannel
(int sourceProduceAmt, int destAcceptAmt) Constructor that sets the source production amount and the destination consumption amount. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the amount of tokens the destination node needs to execute its process.int
Returns the amount of tokens the source node produces after each process execution.pop()
Returns the token at the front of the channel.void
Adds a token to the end of the channel.void
setDestAcceptAmt
(int destAcceptAmt) Sets the amount of tokens the destination node needs to execute its process.void
setSourceProduceAmt
(int sourceProduceAmt) Sets the amount of tokens the source node produces after each process execution.int
size()
Returns the size of the channel.toString()
Returns a string representation of the channel object.
-
Constructor Details
-
FIFOChannel
public FIFOChannel(int sourceProduceAmt, int destAcceptAmt) Constructor that sets the source production amount and the destination consumption amount.- Parameters:
sourceProduceAmt
- the amount of tokens that the source node produces after executing a processdestAcceptAmt
- the amount of tokens the destination node requires from this channel to complete its computation
-
FIFOChannel
public FIFOChannel()Default constructor. Sets source production amount and destination consumption amount to 0.- See Also:
-
-
Method Details
-
pop
Returns the token at the front of the channel.- Returns:
- the token at the front of the channel
-
push
Adds a token to the end of the channel.- Parameters:
token
- the token to be added
-
size
public int size()Returns the size of the channel.- Returns:
- the size of the channel
-
getSourceProduceAmt
public int getSourceProduceAmt()Returns the amount of tokens the source node produces after each process execution.- Returns:
- the amount of tokens the source node produces after each process execution
-
setSourceProduceAmt
public void setSourceProduceAmt(int sourceProduceAmt) Sets the amount of tokens the source node produces after each process execution.- Parameters:
sourceProduceAmt
- the amount of tokens the source node produces after each process execution
-
getDestAcceptAmt
public int getDestAcceptAmt()Returns the amount of tokens the destination node needs to execute its process.- Returns:
- the amount of tokens the destination node needs to execute its process
-
setDestAcceptAmt
public void setDestAcceptAmt(int destAcceptAmt) Sets the amount of tokens the destination node needs to execute its process.- Parameters:
destAcceptAmt
- the amount of tokens the destination node needs to execute its process
-
toString
Returns a string representation of the channel object. Namely, it prints each token in the queue, assuming it has a defined toString() function itself.
-