// 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.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.baidu.unbiz.multitask.exception.TaskBizException;
import com.baidu.unbiz.multitask.task.Taskable;
            public <E> Object work(E request) {
                return invokeMethod(service, method, beanName, NORMAL_PARAM_LENTH, request);
            }
        };
    }

    private static <E> Object invokeMethod(final Object service, final Method method, final String beanName,
                                           final int paramLen, E request) {
        String logFormat = "Fail to run task bean: %s";
        Exception ex = null;
        try {
            return TaskBeanHelper.invokeMethod(service, method, request, paramLen);
        } catch (IllegalArgumentException e) {
            ex = e;
        } catch (IllegalAccessException e) {
            ex = e;
        } catch (InvocationTargetException e) {
            LOG.error(String.format(logFormat, beanName), e);
            // 该类异常通常为业务异常导致，需获取原始原因并上抛
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else {
                ex = e;
            }
        } catch (Exception e) {
            ex = e;
        }
        // 执行到此处，则说明发生异常
        LOG.error(String.format(logFormat, beanName), ex);
// 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/TaskBeanHelper.java
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.baidu.unbiz.multitask.exception.TaskBizException;
import com.baidu.unbiz.multitask.task.Taskable;

            public <E> Object work(E request) {
                return invokeMethod(service, method, beanName, NORMAL_PARAM_LENTH, request);
            }
        };
    }

    private static <E> Object invokeMethod(final Object service, final Method method, final String beanName,
                                           final int paramLen, E request) {
        String logFormat = "Fail to run task bean: %s";
        Exception ex = null;
        try {
            return TaskBeanHelper.invokeMethod(service, method, request, paramLen);
        } catch (IllegalArgumentException e) {
            ex = e;
        } catch (IllegalAccessException e) {
            ex = e;
        } catch (InvocationTargetException e) {
            LOG.error(String.format(logFormat, beanName), e);
            // 该类异常通常为业务异常导致，需获取原始原因并上抛
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else {
                ex = e;
            }
        } catch (Exception e) {
            ex = e;
        }
        // 执行到此处，则说明发生异常
        LOG.error(String.format(logFormat, beanName), ex);
        throw new TaskBizException(String.format(logFormat, beanName), ex);