Package io.github.sumeetk321
Class ProcessNode<T>
java.lang.Object
io.github.sumeetk321.ProcessNode<T>
- Type Parameters:
T
- a generic which determines the type of data this node outputs
This class defines the process node object in the Kahn Process Network. Each
node contains a list of incoming FIFO channels, as well as a singular output
channel, as is consistent with an open KPN. It also contains a string
identifier. A node is considered "active" if there is nothing preventing it
from executing. However, if it stalls due to a read dependency, it becomes
inactive, or in a waiting state.
The actual process method must be user-defined, which is why it is abstract.
The user must create a subclass that extends this one, and define their own
process method. Note that the method takes in an array of Objects - ensure to
cast them to your desired data type before performing computations on them.
- Author:
- Sumeet Kulkarni
-
Constructor Summary
ConstructorDescriptionProcessNode
(String name) A constructor which sets the name/identifier of the node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a FIFO channel to the list of incoming FIFO channels.void
Pops the requisite number of tokens from all of the incoming FIFO channels and executes the node's process, then adds the result(s) to the outgoing FIFO channel.List<FIFOChannel<T>>
Returns the list of incoming FIFO channels.Returns the outgoing FIFO channel.boolean
isActive()
Returns whether this node is active; that is, whether this node is able to execute its process without any dependencies.The abstract process method which must be user-defined.void
setActive
(boolean a) Sets the isActive member.void
Sets the outgoing FIFO channeltoString()
Returns a string representation of the node.
-
Constructor Details
-
ProcessNode
A constructor which sets the name/identifier of the node.- Parameters:
name
- the name/ID of the node
-
-
Method Details
-
process
The abstract process method which must be user-defined. A process is any sort of computation, and the parameters can be of any number and data type.- Parameters:
params
- an abstract, generic list of Objects with variable length- Returns:
- the result of the process
-
getIncomingChannels
Returns the list of incoming FIFO channels.- Returns:
- the list of incoming FIFO channels
-
addIncomingChannel
Adds a FIFO channel to the list of incoming FIFO channels.- Parameters:
f
- the FIFO channel to be added
-
getOutgoingChannel
Returns the outgoing FIFO channel.- Returns:
- the outgoing FIFO channel
-
setOutgoingChannel
Sets the outgoing FIFO channel- Parameters:
f
- the outgoing FIFO channel
-
isActive
public boolean isActive()Returns whether this node is active; that is, whether this node is able to execute its process without any dependencies.- Returns:
- whether the node is active
-
setActive
public void setActive(boolean a) Sets the isActive member.- Parameters:
a
- the new isActive state
-
addTokensToChannel
public void addTokensToChannel()Pops the requisite number of tokens from all of the incoming FIFO channels and executes the node's process, then adds the result(s) to the outgoing FIFO channel. This node is also set to active. -
toString
Returns a string representation of the node.
-