All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.cutexingluo.tools.basepackage.basehandler.aop.BaseJoinPointTaskHandler Maven / Gradle / Ivy

Go to download

xingtools 依赖core,附加,也就是基于 SpringBoot 的一些工具或实体类

The newest version!
package top.cutexingluo.tools.basepackage.basehandler.aop;

import org.aspectj.lang.ProceedingJoinPoint;

import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author XingTian
 * @version 1.0.0
 * @date 2024/1/5 18:47
 */
public interface BaseJoinPointTaskHandler {
    /**
     * 获得任务,手动操作inCatch,否则直接输出异常
     */
    default  Callable getTask(ProceedingJoinPoint joinPoint, Consumer inCatch) {
        return () -> {
            V result = null;
            try {
                result = (V) getTask(joinPoint).call();
            } catch (Exception e) {
                if (inCatch != null) inCatch.accept(e);
                else throw e;
            }
            return result;
        };
    }

    /**
     * 获得任务, 装饰重新抛出
     */
    default  Callable getTask(ProceedingJoinPoint joinPoint) {
        return () -> {
            V result = null;
            try {
                if (joinPoint != null) result = (V) joinPoint.proceed();
            } catch (Exception e) {
                throw e;
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
            return result;
        };
    }

    /**
     * 获得任务, 如果不允许执行就跳过
     */
    default  Callable getTask(ProceedingJoinPoint joinPoint, Supplier canRunTask) {
        return () -> {
            if (canRunTask != null && !canRunTask.get()) {
                return null;
            }
            V result = null;
            try {
                if (joinPoint != null) result = (V) joinPoint.proceed();
            } catch (Exception e) {
                throw e;
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
            return result;
        };
    }

    /**
     * 获得任务, 如果不允许执行就跳过
     */
    default  Callable getTask(ProceedingJoinPoint joinPoint, Supplier canRunTask, Consumer inCatch) {
        return () -> {
            if (canRunTask != null && !canRunTask.get()) {
                return null;
            }
            V result = null;
            try {
                result = (V) getTask(joinPoint).call();
            } catch (Exception e) {
                if (inCatch != null) inCatch.accept(e);
                else throw e;
            }
            return result;
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy