This commit is contained in:
@@ -25,7 +25,7 @@ import org.redkale.util.*;
|
||||
* @author zhangjx
|
||||
*/
|
||||
@AutoLoad(false)
|
||||
@LocalService
|
||||
@Local
|
||||
public final class ApiDocsService extends AbstractService {
|
||||
|
||||
private final Application app; //Application全局对象
|
||||
|
||||
@@ -168,7 +168,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
RestService rs = (RestService) stype.getAnnotation(RestService.class);
|
||||
if (rs != null && rs.ignore()) return;
|
||||
if (mustsign && rs == null) return;
|
||||
if (stype.getAnnotation(LocalService.class) != null && rs == null) return;
|
||||
if (stype.getAnnotation(Local.class) != null && rs == null) return;
|
||||
|
||||
final String stypename = stype.getName();
|
||||
if (!autoload && !includeValues.contains(stypename)) return;
|
||||
|
||||
@@ -317,7 +317,7 @@ public abstract class NodeServer {
|
||||
final boolean localed = (this.sncpAddress == null && entry.isEmptyGroups() && !serviceImplClass.isInterface() && !Modifier.isAbstract(serviceImplClass.getModifiers())) //非SNCP的Server,通常是单点服务
|
||||
|| groups.contains(this.sncpGroup) //本地IP含在内的
|
||||
|| (this.sncpGroup == null && entry.isEmptyGroups()) //空的SNCP配置
|
||||
|| serviceImplClass.getAnnotation(LocalService.class) != null;//本地模式
|
||||
|| serviceImplClass.getAnnotation(Local.class) != null;//本地模式
|
||||
if (localed && (serviceImplClass.isInterface() || Modifier.isAbstract(serviceImplClass.getModifiers()))) continue; //本地模式不能实例化接口和抽象类的Service类
|
||||
final BiConsumer<ResourceFactory, Boolean> runner = (ResourceFactory rf, Boolean needinject) -> {
|
||||
try {
|
||||
|
||||
@@ -243,7 +243,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前用户信息, 通常在HttpServlet.authenticate方法里设置currentUser <br>
|
||||
* 设置当前用户信息, 通常在HttpServlet.preExecute方法里设置currentUser <br>
|
||||
* 数据类型由@HttpUserType指定
|
||||
*
|
||||
* @param <T> 泛型
|
||||
@@ -257,7 +257,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息, 通常在HttpServlet.authenticate方法里设置currentUser <br>
|
||||
* 获取当前用户信息<br>
|
||||
* 数据类型由@HttpUserType指定
|
||||
*
|
||||
* @param <T> @HttpUserType指定的用户信息类型
|
||||
|
||||
@@ -100,10 +100,14 @@ public abstract class HttpServlet extends Servlet<HttpContext, HttpRequest, Http
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 预执行方法,在execute方法之前运行,通常用于常规统计或基础检测,例如 : <br>
|
||||
* 预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 : <br>
|
||||
* <blockquote><pre>
|
||||
* @Override
|
||||
* public void preExecute(final HttpRequest request, final HttpResponse response) throws IOException {
|
||||
* //设置当前用户信息
|
||||
* final String sessionid = request.getSessionid(false);
|
||||
* if (sessionid != null) request.setCurrentUser(userService.current(sessionid));
|
||||
*
|
||||
* if (finer) response.recycleListener((req, resp) -> { //记录处理时间比较长的请求
|
||||
* long e = System.currentTimeMillis() - ((HttpRequest) req).getCreatetime();
|
||||
* if (e > 200) logger.finer("http-execute-cost-time: " + e + " ms. request = " + req);
|
||||
@@ -128,7 +132,7 @@ public abstract class HttpServlet extends Servlet<HttpContext, HttpRequest, Http
|
||||
* <blockquote><pre>
|
||||
* @Override
|
||||
* public void authenticate(HttpRequest request, HttpResponse response) throws IOException {
|
||||
* UserInfo info = currentUser(request);
|
||||
* UserInfo info = request.currentUser();
|
||||
* if (info == null) {
|
||||
* response.finishJson(RET_UNLOGIN);
|
||||
* return;
|
||||
|
||||
@@ -228,6 +228,7 @@ public final class SncpClient {
|
||||
final int mod = method.getModifiers();
|
||||
if (Modifier.isStatic(mod)) continue;
|
||||
if (Modifier.isFinal(mod)) continue;
|
||||
if (method.getAnnotation(Local.class) != null) continue;
|
||||
if (method.getName().equals("getClass") || method.getName().equals("toString")) continue;
|
||||
if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue;
|
||||
if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue;
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
package org.redkale.service;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* 本地模式注解。
|
||||
* 声明为LocalService的Service只能以本地模式存在, 即使配置文件中配置成远程模式也将被忽略。
|
||||
* 声明为Local的Service只能以本地模式存在, 即使配置文件中配置成远程模式也将被忽略。
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
@@ -20,9 +20,9 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({TYPE})
|
||||
@Target({TYPE, METHOD, PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
public @interface LocalService {
|
||||
public @interface Local {
|
||||
|
||||
String comment() default ""; //备注描述
|
||||
}
|
||||
@@ -22,8 +22,8 @@ import org.redkale.util.*;
|
||||
* <blockquote><pre>
|
||||
* 异步方法:
|
||||
* Service编写异步方法:
|
||||
* 1、异步方法有且仅有一个类型为AsyncHandler的参数。若参数类型为AsyncHandler子类,必须保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数。
|
||||
* 2、异步方法返回类型必须是void。
|
||||
* 1、异步方法有且仅有一个类型为AsyncHandler的参数, 返回类型必须是void。若参数类型为AsyncHandler子类,必须保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数。
|
||||
* 2、异步方法返回类型是CompletableFuture。
|
||||
* 例如:
|
||||
* public void insertRecord(AsyncHandler<Integer, Record> handler, String name, @RpcAttachment Record record);
|
||||
*
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@LocalService
|
||||
@Local
|
||||
@AutoLoad(false)
|
||||
@ResourceType({CacheSource.class})
|
||||
public class CacheMemorySource<K extends Serializable, V extends Object> extends AbstractService implements CacheSource<K, V>, Service, AutoCloseable, Resourcable {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@LocalService
|
||||
@Local
|
||||
@AutoLoad(false)
|
||||
@SuppressWarnings("unchecked")
|
||||
@ResourceType({DataSource.class})
|
||||
|
||||
Reference in New Issue
Block a user