This commit is contained in:
Redkale
2017-05-13 15:27:34 +08:00
parent c3cc9de5b5
commit 242b13fff0
11 changed files with 27 additions and 20 deletions

View File

@@ -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全局对象

View File

@@ -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;

View File

@@ -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 {

View File

@@ -243,7 +243,7 @@ public class HttpRequest extends Request<HttpContext> {
}
/**
* 设置当前用户信息, 通常在HttpServlet.authenticate方法里设置currentUser <br>
* 设置当前用户信息, 通常在HttpServlet.preExecute方法里设置currentUser <br>
* 数据类型由&#64;HttpUserType指定
*
* @param <T> 泛型
@@ -257,7 +257,7 @@ public class HttpRequest extends Request<HttpContext> {
}
/**
* 获取当前用户信息, 通常在HttpServlet.authenticate方法里设置currentUser <br>
* 获取当前用户信息<br>
* 数据类型由&#64;HttpUserType指定
*
* @param <T> &#64;HttpUserType指定的用户信息类型

View File

@@ -100,10 +100,14 @@ public abstract class HttpServlet extends Servlet<HttpContext, HttpRequest, Http
/**
* <p>
* 预执行方法在execute方法之前运行通常用于常规统计基础检测,例如 : <br>
* 预执行方法在execute方法之前运行设置当前用户信息,或者加入常规统计基础检测,例如 : <br>
* <blockquote><pre>
* &#64;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) -&#62; { //记录处理时间比较长的请求
* long e = System.currentTimeMillis() - ((HttpRequest) req).getCreatetime();
* if (e &#62; 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>
* &#64;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;

View File

@@ -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;

View File

@@ -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 ""; //备注描述
}

View File

@@ -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&#60;Integer, Record&#62; handler, String name, &#64;RpcAttachment Record record);
*

View File

@@ -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 {

View File

@@ -25,7 +25,7 @@ import org.redkale.util.*;
*
* @author zhangjx
*/
@LocalService
@Local
@AutoLoad(false)
@SuppressWarnings("unchecked")
@ResourceType({DataSource.class})