package propagation;

/**
 * The <code>PropagationRule</code> interface is a summary and propagation
 * logic.<br />
 * This interface's user creates it's instance and sets it to <code>Node</code>
 * objects. The <code>PropagationRule</code> interface don't have states
 * (logic only). So, you have only to create one instance and set to any
 * <code>Node</code>s which you want to use.
 *
 * @author y-komori
 */
public interface PropagationRule {
   /**
    * A constant for summary state. It represents the node is not failed.
    */
   public static final long STATE_CLEAR = 2000;

   /**
    * Changes the specified <code>Node</code>'s <code>StateItem</code> to
    * the specified state.
    * When the specified <code>StateItem</code>'s state is changed,
    * calculates and propagates the node's summary state using
    * <code>summaryUpperPropagate</code> method.
    *
    * @param node   the node to change state
    * @param itemId the <code>StateItem</code>'s item ID to change state
    * @param state  a new state
    * @see PropagationRule#summaryUpperPropagate(Node)
    */
   public void changeState(Node node, long itemId, long state);

   /**
    * Calculates the specified <code>Node</code>'s summary state and
    * propagates to it's parent nodes.
    * This method calculates the specified <code>Node</code>'s summary state
    * from it's <code>StateItem</code>s and child <code>Node</code>'s
    * summary.<br />
    * As a result of summary calculation, when the specified node's summary is
    * changed, propagates it's summary state to parent and upper nodes calling
    * their <code>PropagationRule</code>'s <code>changeState</code>
    * method.
    *
    * @param node the node to calculate it's summary state
    */
   public void summaryUpperPropagate(Node node);
}
