package org.nutz.aop.interceptor.async;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.nutz.aop.MethodInterceptor;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.aop.SimpleAopMaker;

public class AsyncAopIocLoader extends SimpleAopMaker<Async>{
	
	protected int size;
	
	protected ExecutorService es;
	
	public AsyncAopIocLoader(){
		this(32);
	}
	
	public AsyncAopIocLoader(int size) {
		this.size = size;
		es = Executors.newFixedThreadPool(size);
	}
	
	public List<? extends MethodInterceptor> makeIt(Async async, Method method, Ioc ioc) {
		if (!async.enable())
			return null;
		return Arrays.asList(new AsyncMethodInterceptor(method, async, es));
	}
	
	public void depose() throws Exception {
		if (es != null)
			es.shutdownNow();
	}
}

@@ -373,31 +373,8 @@
 %7B%0A%09%0A
-%09protected int size;%0A%09%0A
 %09pro
@@ -400,16 +400,16 @@
 ice es;%0A
+
 %09%0A%09publi
@@ -496,29 +496,9 @@
 this
-.size = size;%0A%09%09es = 
+(
 Exec
@@ -527,16 +527,89 @@
 ol(size)
+);%0A%09%7D%0A%09%0A%09public AsyncAopIocLoader(ExecutorService es) %7B%0A%09    this.es = es
 ;%0A%09%7D%0A%09%0A%09
@@ -890,13 +890,87 @@
 nNow();%0A
-
 %09%7D%0A
+%09%0A%09public ExecutorService getExecutorService() %7B%0A        return es;%0A    %7D%0A
 %7D%0A

改进AsyncAopIocLoader,可以自定义ExecutorService