All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.akurilov.commons.concurrent.AsyncRunnable Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
package com.github.akurilov.commons.concurrent;

import java.io.Closeable;
import java.rmi.RemoteException;
import java.util.concurrent.TimeUnit;

public interface AsyncRunnable
extends Closeable {

	enum State {
		INITIAL, STARTED, SHUTDOWN, STOPPED, FINISHED
	}

	/**
	 @return the current state, null if closed
	 */
	State state()
	throws RemoteException;

	/**
	 @return true if the state is "initial", false otherwise
	 */
	boolean isInitial()
	throws RemoteException;

	/**
	 @return true if the state is "started", false otherwise
	 */
	boolean isStarted()
	throws RemoteException;

	/**
	 @return true if the state is "shutdown", false otherwise
	 */
	boolean isShutdown()
	throws RemoteException;

	/**
	 @return true if the state is "stopped", false otherwise
	 */
	boolean isStopped()
	throws RemoteException;

	/**
	 @return true if the state is "finished", false otherwise
	 */
	boolean isFinished()
	throws RemoteException;

	/**
	 @return true if there's no state, false otherwise
	 */
	boolean isClosed()
	throws RemoteException;

	/**
	 Start/resume the execution
	 @return the same instance with state changed to STARTED if call was successful.
	 @throws IllegalStateException if the previous state is not INITIAL neither STOPPED
	 */
	AsyncRunnable start()
	throws IllegalStateException, RemoteException;

	/**
	 Notify to stop to enqueue incoming requests. The await method should be used after this to make
	 sure that everything accepted before the shutdown is done.
	 */
	AsyncRunnable shutdown()
	throws IllegalStateException, RemoteException;

	/**
	 Stop (with further resumption capability)
	 @return the same instance with state changed to STOPPED if call was successful
	 @throws IllegalStateException if the previous state is not STARTED
	 */
	AsyncRunnable stop()
	throws IllegalStateException, RemoteException;

	/**
	 Wait while the state is STARTED
	 @return the same instance
	 @throws InterruptedException
	 */
	AsyncRunnable await()
	throws InterruptedException, RemoteException;

	boolean await(final long timeout, final TimeUnit timeUnit)
	throws InterruptedException, RemoteException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy