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

public abstract class ProcessNode<T> extends Object
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 Details

    • ProcessNode

      public ProcessNode(String name)
      A constructor which sets the name/identifier of the node.
      Parameters:
      name - the name/ID of the node
  • Method Details

    • process

      public abstract List<T> process(Object... params)
      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

      public List<FIFOChannel<T>> getIncomingChannels()
      Returns the list of incoming FIFO channels.
      Returns:
      the list of incoming FIFO channels
    • addIncomingChannel

      public void addIncomingChannel(FIFOChannel<T> f)
      Adds a FIFO channel to the list of incoming FIFO channels.
      Parameters:
      f - the FIFO channel to be added
    • getOutgoingChannel

      public FIFOChannel<T> getOutgoingChannel()
      Returns the outgoing FIFO channel.
      Returns:
      the outgoing FIFO channel
    • setOutgoingChannel

      public void setOutgoingChannel(FIFOChannel<T> f)
      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

      public String toString()
      Returns a string representation of the node.
      Overrides:
      toString in class Object