package com.wildducktheories.tasklet;

import com.wildducktheories.tasklet.impl.APIImpl;


/**
 * Provides methods that can construct, get and set the {@link Scheduler} instance associated with the current {@link Thread}.
 *
 * @author jonseymour
 */
public class SchedulerAPI {
	/**
	 * An per thread override for the thread's current scheduler.
	 */
	private final static ThreadLocal<API> perThread = new ThreadLocal<API>();

	public static API get() {
		API api = perThread.get();
		if (api == null) {
			api = new APIImpl();
		}
		return api;
	}
	
	public static Scheduler with(API api, Scheduler scheduler, Tasklet tasklet) {
		final API saved = perThread.get();
		try {
			perThread.set(api);
			return api.with(scheduler, tasklet);
		} finally {
			if (saved == null) {
				perThread.remove();
			} else {
				perThread.set(saved);
			}
		}
	}
	
	public static void reset() {
		get().reset();
		perThread.remove();
	}
}

@@ -32,16 +32,55 @@
 sklet;%0A%0A
+import java.util.concurrent.Callable;%0A%0A
 import c
@@ -121,16 +121,16 @@
 PIImpl;%0A
-
 %0A%0A/**%0A *
@@ -589,84 +589,947 @@
 %0A%09%0A%09
-public static Scheduler with(API api, Scheduler scheduler, Tasklet tasklet) 
+/**%0A%09 * Run the specified %7B@link Runnable%7D with the specified %7B@link API%7D as the %0A%09 * current %7B@link API%7D for the current thread.%0A%09 * @param api The specified %7B@link API%7DI%0A%09 * @param run The specified %7B@link Runnable%7D%0A%09 */%0A%09public static void with(final API api, final Runnable runnable) %7B%0A%09%09final API saved = perThread.get();%0A%09%09try %7B%0A%09%09%09perThread.set(api);%0A%09%09%09runnable.run();%0A%09%09%7D finally %7B%0A%09%09%09if (saved == null) %7B%0A%09%09%09%09perThread.remove();%0A%09%09%09%7D else %7B%0A%09%09%09%09perThread.set(saved);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * Run the specified %7B@link Callable%7D with the specified %7B@link API%7D as the %0A%09 * current %7B@link API%7D for the current thread. %0A%09 * @param api The specified %7B@link API%7DI%0A%09 * @param run The specified %7B@link Runnable%7D%0A%09 * @return The result of the %7B@link Callable%7D%0A%09 * @throws Exception The exception thrown by the specified %7B@link Callable%7D, if any.%0A%09 */%0A%09public static %3CP%3E P with(final API api, final Callable%3CP%3E callable) %0A%09%09throws Exception%0A%09
 %7B%0A%09%09
@@ -1608,35 +1608,22 @@
 urn 
-api.with(scheduler, tasklet
+callable.call(
 );%0A%09
@@ -1733,18 +1733,68 @@
 %0A%09%09%7D%0A%09%7D%0A
-
 %09%0A
+%09/**%0A%09 * Release all thread local resources.%0A%09 */%0A
 %09public 

Change definition of with method. Add support for Callable and Runnables.