// Path: deferred/src/main/java/com/tuenti/deferred/DeferredManager.java
// enum StartPolicy {
// 	/**
// 	 * Let Deferred Manager to determine whether to start the task at its own
// 	 * discretion.
// 	 */
// 	DEFAULT,
// 
// 	/**
// 	 * Tells Deferred Manager to automatically start the task
// 	 */
// 	AUTO,
// 
// 	/**
// 	 * Tells Deferred Manager that this task will be manually started
// 	 */
// 	MANUAL
// }


import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import com.tuenti.deferred.DeferredManager.StartPolicy;
/*
 * Copyright 2013 Ray Tsang
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tuenti.deferred;




/**
 * FutureTask can wrap around {@link Callable} and {@link Runnable}.
 * In these two cases, a new {@link Deferred} object will be created.
 * This class will override {@link FutureTask#done} to trigger the 
 * appropriate {@link Deferred} actions.
 * 
 * Note, type used for {@link Deferred#reject(Object)} is always {@link Throwable}.
 * 
 * When the task is completed successfully, {@link Deferred#resolve(Object)} will be called.
 * When a task is canceled, {@link Deferred#reject(Object)} will be called with an instance of {@link CancellationException}
 * If any Exception occured, {@link Deferred#reject(Object)} will be called with the Exception instance.
 * 
 * @author Ray Tsang
 *
 * @param <D> Type used for {@link Deferred#resolve(Object)}
 * @param <P> Type used for {@link Deferred#notify(Object)}
 */
class DeferredFutureTask<D, P> extends FutureTask<D> {
	protected final Deferred<D, Throwable, P> deferred;
// Path: deferred/src/main/java/com/tuenti/deferred/DeferredManager.java
// enum StartPolicy {
// 	/**
// 	 * Let Deferred Manager to determine whether to start the task at its own
// 	 * discretion.
// 	 */
// 	DEFAULT,
// 
// 	/**
// 	 * Tells Deferred Manager to automatically start the task
// 	 */
// 	AUTO,
// 
// 	/**
// 	 * Tells Deferred Manager that this task will be manually started
// 	 */
// 	MANUAL
// }


// Path: deferred/src/main/java/com/tuenti/deferred/DeferredFutureTask.java
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import com.tuenti.deferred.DeferredManager.StartPolicy;

/*
 * Copyright 2013 Ray Tsang
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tuenti.deferred;




/**
 * FutureTask can wrap around {@link Callable} and {@link Runnable}.
 * In these two cases, a new {@link Deferred} object will be created.
 * This class will override {@link FutureTask#done} to trigger the 
 * appropriate {@link Deferred} actions.
 * 
 * Note, type used for {@link Deferred#reject(Object)} is always {@link Throwable}.
 * 
 * When the task is completed successfully, {@link Deferred#resolve(Object)} will be called.
 * When a task is canceled, {@link Deferred#reject(Object)} will be called with an instance of {@link CancellationException}
 * If any Exception occured, {@link Deferred#reject(Object)} will be called with the Exception instance.
 * 
 * @author Ray Tsang
 *
 * @param <D> Type used for {@link Deferred#resolve(Object)}
 * @param <P> Type used for {@link Deferred#notify(Object)}
 */
class DeferredFutureTask<D, P> extends FutureTask<D> {
	protected final Deferred<D, Throwable, P> deferred;
	protected final StartPolicy startPolicy;