//****************************************************************************
// CLASS NAME:	Timer.java
//
// AUTHOR:	Rick Brink
//		    rick@mail.csh.rit.edu
//		    http://www.csh.rit.edu/~rick
//
// VERSION:	1.0
//
// HISTORY:	4/16/96		Initial Version
//
// COPYRIGHT INFORMATION:
//
// This program and the Java source is in the public domain.
// Permission to use, copy, modify, and distribute this software
// and its documentation for NON-COMMERCIAL purposes and
// without fee is hereby granted.
//
//    Copyright 1996
//
//    Rick Brink
//    1266 Brighton-Henrietta Townline Rd.
//    Rochester, NY 14623
//
// DISCLAIMER:
//
// The author claims no responsibility for any damage, direct or indirect,
// to any harware or software as a result of using this program.
//****************************************************************************

import java.lang.Thread;

/**
  * A class representing a Timer, which will call a timerInterrupt()
  * routine definined in Thread after a specified amount of time.
  *
  * @see java.lang.Thread
  *
  * @version 1.0 July 3, 1996
  *
  * @author  Rick Brink
**/
class Timer extends Thread {
    /** Amount of seconds before timerInterrupt() is called **/
    private protected long seconds_;

    /** Handle to Thread which should be interrupted **/
    private protected ReachabilityTree thread_;

    /**
      * Construct a new Timer to inform thread when the
      * specified seconds have elapsed
    **/
    public Timer(ReachabilityTree thread, long seconds) {
        thread_ = thread;
        seconds_ = seconds;
        this.start();
    }

    /**
      * Sleep for the specified number of seconds, then call the
      * timerInterrupt routine.
    **/
    public void run() {
        try {
            sleep(seconds_ * 1000);
            if (thread_ != null) {
                thread_.timerInterrupt();
            }
            else {
                System.out.println("Timer interrupt on dead thread.");
            }
        }
        catch (InterruptedException e) {
            System.out.println("Error - Could not start timer.");
        }
    }

}
