/*
 *  bondFaultDisseminator.java
 *   @contains It initiates the dissemination of
 *             event information. See README in this
 *             directory.
 *   @author Kyungkoo Jun
 *   Bond group, CS, Purdue Univ.
 *   created on Nov 15, 2000
 *
 *   modified by Kyungkoo Jun, Nov. 18. 2000
 *     -- The instances of this class do not register to
 *        the local directory to save the space in the
 *        directory.
 */

package bond.agent.FaultDetection;

import java.util.*;

public class bondFaultDisseminator
extends bondFaultDetectionExecutable
{

  String info;

  public bondFaultDisseminator(bondFaultStatus fs, String info) {
    super(fs);
    this.info = info;
    go();
  }

  public void run() {

    Vector v = fs.getFaultFreeList();
    v.remove(fs.getMyID());
    v.remove(info);

    int sz = v.size();

    if (sz == 0) {
    }
    else if (sz == 1) {
      fs.spreadInfo((String)v.elementAt(0), new Vector(), info); // send empty vector
      return;
    }
    else {
      final Vector v1, v2;
      int half = sz / 2;
      v1 = v;
      v2 = (Vector)v.clone();
      v2.subList(0, half).clear();
      v1.subList(half, sz).clear();

      final String temp = (String)v1.remove(0);
      Thread th = new Thread() {
	  public void run() {
	    fs.spreadInfo(temp, v1, info);
	  }
	};
	th.start();
      //      fs.spreadInfo(temp, v1, info);
      final String temp2 = (String)v2.remove(0);
      fs.spreadInfo(temp2, v2, info);
    }
    dir.unregister(this);
  }
}
