Package io.github.sumeetk321
Class KahnProcessNetwork<T>
java.lang.Object
io.github.sumeetk321.KahnProcessNetwork<T>
- Type Parameters:
T
- a generic which defines the type of each "atom" or "token" in the KPN.
The root class for Kahn Process Network construction. A KPN object simply
contains a set of process nodes, each of which contain their own set of
first-in-first-out channels that send and receive tokens (data).
Each process node will read a certain number of tokens and perform some
user-defined function (through polymorphism), which must be deterministic
(e.g., given some initial input, the process gives the same output each
time).
Reading from channels is blocked; that is, if a process node does not have a
sufficient number of tokens to perform its process, it will stall. Writing to
a channel, however, is not blocked - it will always succeed. Keep this in
mind when constructing your own models; reading dependencies can cascade and
lead to overflows or deadlocks that disrupt the whole network.
Note that this KPN class defines an *open* KPN, in which each process node
contains at least one input channel and exactly one output channel.
- Author:
- Sumeet Kulkarni
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFIFOChannel
(ProcessNode<T> source, ProcessNode<T> dest) Same asaddFIFOChannel(ProcessNode, ProcessNode, int, int)
, except sourceProduceAmt and destAcceptAmt are set by default to 1.void
addFIFOChannel
(ProcessNode<T> source, ProcessNode<T> dest, int sourceProduceAmt, int destAcceptAmt) Adds a first-in-first-out channel between two nodes to the network.void
addProcessNode
(ProcessNode<T> node) Adds a process node to the network.void
Simulates a single time step in the execution of the network.toString()
Returns a string representation of the network at the current time step.
-
Constructor Details
-
KahnProcessNetwork
public KahnProcessNetwork()Default constructor. Initializes the empty set of nodes.
-
-
Method Details
-
addProcessNode
Adds a process node to the network.- Parameters:
node
- the node to be added
-
addFIFOChannel
public void addFIFOChannel(ProcessNode<T> source, ProcessNode<T> dest, int sourceProduceAmt, int destAcceptAmt) Adds a first-in-first-out channel between two nodes to the network. This channel will send tokens from the source node to the destination node.- Parameters:
source
- the source node from which the channel startsdest
- the destination node where the channel endssourceProduceAmt
- the amount of tokens the source node produces each time its process is executeddestAcceptAmt
- the amount of tokens the destination node consumes to execute its process
-
addFIFOChannel
Same asaddFIFOChannel(ProcessNode, ProcessNode, int, int)
, except sourceProduceAmt and destAcceptAmt are set by default to 1.- Parameters:
source
- the source node from which the channel startsdest
- the destination node where the channel ends- See Also:
-
simulateTimestep
public void simulateTimestep()Simulates a single time step in the execution of the network. Nodes that do not have the tokens required in any channel to perform their process stall and do not execute, rendering them inactive. -
toString
Returns a string representation of the network at the current time step.
-