This commit is contained in:
redkale
2023-12-09 10:51:18 +08:00
parent e7a7461d9d
commit 86cfeafd8d
4 changed files with 143 additions and 7 deletions

View File

@@ -0,0 +1,75 @@
/*
*
*/
package org.redkale.annotation;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
/**
* @TODO 待实现
*
* 标记在Service的缓存接口, 方法有以下限制: <br>
* 1、方法返回类型不能是void
* 2、方法必须是protected/public
* 3、方法不能是final
*
* @since 2.8.0
*/
@Inherited
@Documented
@Target(METHOD)
@Retention(RUNTIME)
public @interface Cached {
/**
* 缓存的key支持参数动态组合比如"key_#{id}"
*
* @return 键
*/
String key();
/**
* 缓存的hash, 默认值用当前Service类的SimpleName
*
* @return hash
*/
String map() default "";
/**
* 本地缓存过期时长, 0表示永不过期 -1表示不作本地缓存。<br>
* 参数值支持方式:<br>
* 100: 设置数值
* 5*60: 乘法表达式值为30
* ${env.cache.expires}: 读取系统配置项
* #delays: 读取宿主对象的delays字段值作为值字段类型必须是int、long数值类型
*
* @return 过期时长
*/
String localExpire() default "-1";
/**
* 远程缓存过期时长, 0表示永不过期 -1表示不作远程缓存。<br>
* 参数值支持方式:<br>
* 100: 设置数值
* 5*60: 乘法表达式值为30
* ${env.cache.expires}: 读取系统配置项
* #delays: 读取宿主对象的delays字段值作为值字段类型必须是int、long数值类型
*
* @return 过期时长
*/
String remoteExpire() default "-1";
/**
* 过期时长的时间单位
*
* @return 时间单位
*/
TimeUnit timeUnit() default TimeUnit.SECONDS;
}

View File

@@ -45,9 +45,11 @@ public @interface Scheduled {
/**
* 延迟时间,支持参数配置、乘法表达式和对象字段值 <br>
* ${env.fixedDelay}: 读取系统配置项
* 参数值支持方式:<br>
* 100: 设置数值
* 5*60: 乘法表达式值为30
* #delays: 读取对象的delays字段值作为值字段类型必须是long
* ${env.scheduling.fixedDelay}: 读取系统配置项
* #delays: 读取宿主对象的delays字段值作为值字段类型必须是int、long数值类型
*
* @return 延迟时间
*/
@@ -55,9 +57,11 @@ public @interface Scheduled {
/**
* 周期时间,支持参数配置、乘法表达式和对象字段值 <br>
* ${env.fixedRate}: 读取系统配置项
* 参数值支持方式:<br>
* 100: 设置数值
* 5*60: 乘法表达式值为30
* #intervals: 读取对象的intervals字段值作为值字段类型必须是long
* ${env.scheduling.fixedRate}: 读取系统配置项
* #intervals: 读取宿主对象的intervals字段值作为值字段类型必须是int、long数值类型
*
* @return 周期时间
*/
@@ -65,9 +69,11 @@ public @interface Scheduled {
/**
* 起始延迟时间,支持参数配置、乘法表达式和对象字段值 <br>
* ${env.initialDelay}: 读取系统配置项
* 参数值支持方式:<br>
* 100: 设置数值
* 5*60: 乘法表达式值为30
* #inits: 读取对象的inits字段值作为值字段类型必须是long
* ${env.scheduling.initialDelay}: 读取系统配置项
* #inits: 读取宿主对象的inits字段值作为值字段类型必须是int、long数值类型
*
* @return 起始延迟时间
*/

View File

@@ -0,0 +1,13 @@
/*
*
*/
package org.redkale.cacheing;
/**
* @TODO 待实现
*
* @author zhangjx
*/
public class CachedFactory {
}

View File

@@ -31,6 +31,11 @@ public abstract class TypeToken<T> {
type = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
/**
* 具体泛型类型
*
* @return 泛型
*/
public final Type getType() {
return type;
}
@@ -74,6 +79,13 @@ public abstract class TypeToken<T> {
return true;
}
/**
* 判断泛型知否包含了不确定的数据类型
*
* @param type 类型
*
* @return 是否含不确定类型
*/
public static final boolean containsUnknownType(final Type type) {
if (type == null) {
return false;
@@ -111,6 +123,13 @@ public abstract class TypeToken<T> {
return true;
}
/**
* 获取type的主类
*
* @param type 类型
*
* @return 主类
*/
public static final Class typeToClass(final Type type) {
if (type instanceof Class) {
return (Class) type;
@@ -133,11 +152,27 @@ public abstract class TypeToken<T> {
return typeToClass(raw != null ? raw : owner);
}
/**
* 获取type的主类如果是不确定类型则返回defClass
*
* @param type 类型
* @param defClass 默认类
*
* @return 确定的类型
*/
public static final Class typeToClassOrElse(final Type type, final Class defClass) {
Class clazz = typeToClass(type);
return clazz == null ? defClass : clazz;
}
/**
* 将泛型中不确定的类型转成确定性类型
*
* @param types 泛型集合
* @param declaringClass 宿主类型
*
* @return 确定性类型集合
*/
public static Type[] getGenericType(final Type[] types, final Type declaringClass) {
Type[] newTypes = new Type[types.length];
for (int i = 0; i < newTypes.length; i++) {
@@ -146,6 +181,13 @@ public abstract class TypeToken<T> {
return newTypes;
}
/**
* 获取primitive类对应的box类型
*
* @param clazz primitive类
*
* @return 基础类型box类型
*/
public static Class primitiveToWrapper(Class clazz) {
if (clazz == boolean.class) {
return Boolean.class;
@@ -630,7 +672,7 @@ public abstract class TypeToken<T> {
nsb.append(ch);
} else if (ch >= 'A' && ch <= 'Z') {
nsb.append(ch);
} else {
} else { //特殊字符统一使用_
nsb.append('_');
}
}