/*
 * CountDownTimer.java  $Revision: 1.2 $  $Date: 2007/10/03 04:39:39 $
 *
 * Copyright (C) 2007 Meldcraft Corporation
 *
 * This file is part of Scaffold.
 * 
 * Scaffold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Scaffold 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Scaffold.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.meldcraft.util;

/**
 * @version $Revision: 1.2 $ $Date: 2007/10/03 04:39:39 $
 * @author Rob Richards
 */
public class CountDownTimer
{
    private Object  mLock;
    private boolean mDone = false;

    public CountDownTimer(final long millis)
    {
        mLock = new Object();
        Thread thread = new Thread("CountDownTimer-Thread") {
            public void run()
            {
                synchronized(mLock)
                {
                    try
                    {
                        mLock.wait(millis);
                    }
                    catch (InterruptedException e)
                    {
                        // ignored
                    }
                    finally
                    {
                        mDone = true;
                        mLock.notifyAll();
                    }
                }

            }
        };
        thread.start();
    }

    public void waitForCountDown()
    {
        synchronized(mLock)
        {
            if (!mDone)
            {
                try
                {
                    mLock.wait();
                }
                catch (InterruptedException e)
                {
                    // ignored
                }
            }
        }
    }
}



