// Path: src/main/java/com/baidu/unbiz/multitask/exception/TaskBizException.java
// public class TaskBizException extends RuntimeException {
// 
//     private static final long serialVersionUID = -7375423850222016116L;
// 
//     public TaskBizException(String msg) {
//         super(msg);
//     }
// 
//     public TaskBizException(Throwable cause) {
//         super(cause);
//     }
// 
//     public TaskBizException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/com/baidu/unbiz/multitask/task/Taskable.java
// public interface Taskable<T> {
// 
//     /**
//      * 执行数据获取
//      * 
//      * @param request
//      * @return 返回结果
//      * @since 2015-7-3 by wangchongjie
//      */
//     <E> T work(E request);
// 
// }


import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import com.baidu.unbiz.multitask.annotation.TaskBean;
import com.baidu.unbiz.multitask.annotation.TaskService;
import com.baidu.unbiz.multitask.exception.TaskBizException;
import com.baidu.unbiz.multitask.task.Taskable;
    /**
     * 优先使用@Resource方式注入，此处为预留接口,也可获取Fetcher Bean
     *
     * @param beanName
     *
     * @return bean
     */
    @SuppressWarnings("unchecked")
    public <T> T bean(String beanName) {
        T bean = (T) container.get(beanName);
        if (bean != null) {
            return bean;
        } else {
            return (T) TaskBeanContainer.getBean(beanName);
        }
    }

    public Taskable<?> task(String beanName) {
        return bean(beanName);
    }

    /**
     * 注册一个Fetcher
     *
     * @param service
     * @param method
     * @param beanName
     */
    private static void registerFetcher(final Object service, final Method method, final String beanName) {
        if (TaskBeanContainer.containsBean(beanName)) {
// Path: src/main/java/com/baidu/unbiz/multitask/exception/TaskBizException.java
// public class TaskBizException extends RuntimeException {
// 
//     private static final long serialVersionUID = -7375423850222016116L;
// 
//     public TaskBizException(String msg) {
//         super(msg);
//     }
// 
//     public TaskBizException(Throwable cause) {
//         super(cause);
//     }
// 
//     public TaskBizException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/com/baidu/unbiz/multitask/task/Taskable.java
// public interface Taskable<T> {
// 
//     /**
//      * 执行数据获取
//      * 
//      * @param request
//      * @return 返回结果
//      * @since 2015-7-3 by wangchongjie
//      */
//     <E> T work(E request);
// 
// }


// Path: src/main/java/com/baidu/unbiz/multitask/spring/integration/TaskBeanContainer.java
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import com.baidu.unbiz.multitask.annotation.TaskBean;
import com.baidu.unbiz.multitask.annotation.TaskService;
import com.baidu.unbiz.multitask.exception.TaskBizException;
import com.baidu.unbiz.multitask.task.Taskable;

    /**
     * 优先使用@Resource方式注入，此处为预留接口,也可获取Fetcher Bean
     *
     * @param beanName
     *
     * @return bean
     */
    @SuppressWarnings("unchecked")
    public <T> T bean(String beanName) {
        T bean = (T) container.get(beanName);
        if (bean != null) {
            return bean;
        } else {
            return (T) TaskBeanContainer.getBean(beanName);
        }
    }

    public Taskable<?> task(String beanName) {
        return bean(beanName);
    }

    /**
     * 注册一个Fetcher
     *
     * @param service
     * @param method
     * @param beanName
     */
    private static void registerFetcher(final Object service, final Method method, final String beanName) {
        if (TaskBeanContainer.containsBean(beanName)) {
            throw new TaskBizException("Fetcher bean duplicate for Spring:" + beanName);