package at.oefai.aaa.thread;

import java.io.Serializable;
import java.util.concurrent.CountDownLatch;

/**
 * An interface for all thread like objects that can be safely paused.
 * and restarted again.
 * @author Stefan Rank
 */
public interface IPausable extends Serializable {

    /**
     * Start is called to start the thread.
     * A null param starts it immediately, otherwise the CountDownLatch is waited for.
     * @param startSignal for synchronising the start of some threads
     */
    void start(final CountDownLatch startSignal);

    /**
     * Pause stops execution until the next time start is called.
     * Does not block, a non-null CountDownLatch can be passed in to receive a signal when really paused.
     * @param returnSignal await this to be sure the thread really has stopped.
     */
    void pause(final CountDownLatch returnSignal);

    boolean isPaused();
}
