This commit is contained in:
Redkale
2020-06-01 10:04:20 +08:00
parent f83fc52e9c
commit 2dee61223d
4 changed files with 33 additions and 15 deletions

View File

@@ -59,6 +59,7 @@
-->
<!--
MQ管理接口配置
不同MQ节点所配置的MQ集群不能重复。
name: 服务的名称用于监控识别多个mq节点时只能有一个name为空的节点mq.name不能重复,命名规则: 字母、数字、下划线
value 实现类名必须是org.redkale.mq.MessageAgent的子类
MQ节点下的子节点配置没有固定格式, 根据MessageAgent实现方的定义来配置

View File

@@ -6,6 +6,7 @@
package org.redkale.mq;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.*;
import java.util.logging.Logger;
import org.redkale.boot.*;
@@ -38,11 +39,17 @@ public abstract class MessageAgent {
protected Map<String, Service> localConsumers;
public void init(AnyValue config) {
}
public CompletableFuture<Void> start() {
return null;
}
public CompletableFuture<Void> stop() {
return null;
}
public void destroy(AnyValue config) {
}
public String getName() {

View File

@@ -73,6 +73,7 @@ public class HttpRequest extends Request<HttpContext> {
protected Annotation[] annotations;
// @since 2.1.0
protected Serializable currentUserid;
protected Object currentUser;
@@ -305,12 +306,14 @@ public class HttpRequest extends Request<HttpContext> {
/**
* 设置当前用户ID, 通常在HttpServlet.preExecute方法里设置currentUserid <br>
* 数据类型通常是int、long、String
* 数据类型只能是int、long、String、JavaBean
*
* @param <T> 泛型
* @param userid 用户ID
*
* @return HttpRequest
*
* @since 2.1.0
*/
public <T extends Serializable> HttpRequest setCurrentUserid(T userid) {
this.currentUserid = userid;
@@ -320,9 +323,11 @@ public class HttpRequest extends Request<HttpContext> {
/**
* 获取当前用户ID<br>
*
* @param <T> 通常是int、long、String类型
* @param <T> 数据类型只能是int、long、String、JavaBean
*
* @return 用户信息
* @return 用户ID
*
* @since 2.1.0
*/
@SuppressWarnings("unchecked")
public <T extends Serializable> T currentUserid() {

View File

@@ -205,6 +205,11 @@ public final class Rest {
}
}
//仅供Rest动态构建里 currentUserid() 使用
public static <T> T orElse(T t, T defValue) {
return t == null ? defValue : t;
}
public static <T extends HttpServlet> T createRestWebSocketServlet(final ClassLoader classLoader, final Class<? extends WebSocket> webSocketType) {
if (webSocketType == null) throw new RuntimeException("Rest WebSocket Class is null on createRestWebSocketServlet");
if (Modifier.isAbstract(webSocketType.getModifiers())) throw new RuntimeException("Rest WebSocket Class(" + webSocketType + ") cannot abstract on createRestWebSocketServlet");
@@ -726,6 +731,7 @@ public final class Rest {
if (!java.lang.reflect.Modifier.isPublic(mod)) throw new RuntimeException(baseServletType + " is not Public Class on createRestServlet");
if (java.lang.reflect.Modifier.isAbstract(mod)) throw new RuntimeException(baseServletType + " cannot a abstract Class on createRestServlet");
final String restInternalName = Type.getInternalName(Rest.class);
final String serviceDesc = Type.getDescriptor(serviceType);
final String webServletDesc = Type.getDescriptor(WebServlet.class);
final String resDesc = Type.getDescriptor(Resource.class);
@@ -1300,27 +1306,26 @@ public final class Rest {
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "currentUserid", "()Ljava/io/Serializable;", false);
if (ptype == int.class) {
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
mv.visitMethodInsn(INVOKESTATIC, restInternalName, "orElse", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
mv.visitVarInsn(ISTORE, maxLocals);
varInsns.add(new int[]{ILOAD, maxLocals});
} else if (ptype == float.class) {
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
mv.visitVarInsn(FSTORE, maxLocals);
varInsns.add(new int[]{FLOAD, maxLocals});
} else if (ptype == long.class) {
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitInsn(LCONST_0);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
mv.visitMethodInsn(INVOKESTATIC, restInternalName, "orElse", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitVarInsn(LSTORE, maxLocals);
varInsns.add(new int[]{LLOAD, maxLocals});
maxLocals++;
} else if (ptype == double.class) {
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
mv.visitVarInsn(DSTORE, maxLocals);
varInsns.add(new int[]{DLOAD, maxLocals});
maxLocals++;
} else {
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(ptype));
mv.visitVarInsn(ASTORE, maxLocals);