/*
** Module   : CriticalPathElement.java
** Abstract : represents an element that is a bottleneck for all subsequent
**            elements
**
** Copyright (c) 2009, Golden Code Development Corporation.
**
** -#- -I- --Date-- -----------------------Description------------------------
** 001 GES 20090318 Represents an element that is a bottleneck for all
**                  subsequent elements. 
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.goldencode.harness;

import com.goldencode.harness.test.*;

/**
 * Represents an element that is a bottleneck for all subsequent elements. No
 * following elements will execute until this element has finished processing.
 * 
 * @param   <E>
 *          Type of element.
 */
public class CriticalPathElement<E extends Test>
extends SingleElement<E>
implements Dependent
{
   /** Flag to track completion status. */
   private boolean done = false;
   
   /**
    * Construct an instance.
    *
    * @param    element
    *           The element to return from the queue.
    */
   public CriticalPathElement(E element)
   {
      super(element);
      element.addDependent(this);
   }
   
   /**
    * Reports if there are any elements remaining in the queue. This can answer
    * the question of whether there will ever be elements available to
    * {@link #dequeue}. Note that due to dependencies between elements, it is
    * possible for a queue to be non-empty but to not yet be ready to accept
    * a <code>dequeue</code> request.
    *
    * @return   <code>true</code> if all queue elements have been dequeued.
    */
   public synchronized boolean isEmpty()
   {
      return done;
   }
   
   /**
    * Reports on the disposition of an activity on which this object is
    * dependent.
    *
    * @param    status
    *           The status of the activity.
    * @param    reason
    *           Details on the cause of any failure.
    */
   public synchronized void update(Status status, String reason)
   {
      done = true;
   }
}
