This commit is contained in:
@@ -39,7 +39,7 @@ import org.redkale.util.*;
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public abstract class WebSocketServlet extends HttpServlet {
|
public abstract class WebSocketServlet extends HttpServlet implements Resourcable {
|
||||||
|
|
||||||
@Comment("WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒")
|
@Comment("WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒")
|
||||||
public static final String WEBPARAM__LIVEINTERVAL = "liveinterval";
|
public static final String WEBPARAM__LIVEINTERVAL = "liveinterval";
|
||||||
@@ -69,7 +69,7 @@ public abstract class WebSocketServlet extends HttpServlet {
|
|||||||
|
|
||||||
public final void preInit(HttpContext context, AnyValue conf) {
|
public final void preInit(HttpContext context, AnyValue conf) {
|
||||||
InetSocketAddress addr = context.getServerAddress();
|
InetSocketAddress addr = context.getServerAddress();
|
||||||
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + getResourceName() + "]", this.node, logger);
|
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + resourceName() + "]", this.node, logger);
|
||||||
if (this.node == null) this.node = createWebSocketNode();
|
if (this.node == null) this.node = createWebSocketNode();
|
||||||
if (this.node == null) {
|
if (this.node == null) {
|
||||||
this.node = new WebSocketNodeService();
|
this.node = new WebSocketNodeService();
|
||||||
@@ -86,7 +86,8 @@ public abstract class WebSocketServlet extends HttpServlet {
|
|||||||
engine.close();
|
engine.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResourceName() {
|
@Override
|
||||||
|
public String resourceName() {
|
||||||
return this.getClass().getSimpleName().replace("Servlet", "").replace("WebSocket", "").toLowerCase();
|
return this.getClass().getSimpleName().replace("Servlet", "").replace("WebSocket", "").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.redkale.util.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有Service的实现类不得声明为final, 允许远程模式的public方法都不能声明为final。<br>
|
* 所有Service的实现类不得声明为final, 允许远程模式的public方法都不能声明为final。<br>
|
||||||
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。<br>
|
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。<br>
|
||||||
*
|
*
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* Service的资源类型
|
* Service的资源类型
|
||||||
@@ -23,11 +23,9 @@ import org.redkale.util.*;
|
|||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
* 异步方法:
|
* 异步方法:
|
||||||
* Service编写异步方法:
|
* Service编写异步方法:
|
||||||
* 1、异步方法有且仅有一个类型为AsyncHandler的参数,方法返回类型必须是void。
|
* 1、异步方法有且仅有一个类型为AsyncHandler的参数。
|
||||||
* 2、必须存在对应的同步方法,同步的方法名与异步方法必须相同,方法的参数列表必须与异步方法除AsyncHandler参数的参数列表相同。
|
* 2、异步方法返回类型必须是void。
|
||||||
* 例如:
|
* 例如:
|
||||||
* public int insertRecord(String name, Record record);
|
|
||||||
*
|
|
||||||
* public void insertRecord(AsyncHandler<Integer, Record> handler, String name, @RpcAttachment Record record);
|
* public void insertRecord(AsyncHandler<Integer, Record> handler, String name, @RpcAttachment Record record);
|
||||||
*
|
*
|
||||||
* </pre></blockquote>
|
* </pre></blockquote>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.redkale.util.*;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final class DataJdbcSource implements DataSource, DataCacheListener, Function<Class, EntityInfo>, AutoCloseable {
|
public final class DataJdbcSource implements DataSource, Resourcable, DataCacheListener, Function<Class, EntityInfo>, AutoCloseable {
|
||||||
|
|
||||||
private static final Flipper FLIPPER_ONE = new Flipper(1);
|
private static final Flipper FLIPPER_ONE = new Flipper(1);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public final class DataJdbcSource implements DataSource, DataCacheListener, Func
|
|||||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String name() {
|
public final String resourceName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
src/org/redkale/util/Resourcable.java
Normal file
19
src/org/redkale/util/Resourcable.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.redkale.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象的类没有标记为@Resource, 可以通过实现Resourcable接口实现动态获取Resource.name
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 详情见: https://redkale.org
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
public interface Resourcable {
|
||||||
|
|
||||||
|
public String resourceName();
|
||||||
|
}
|
||||||
@@ -323,17 +323,17 @@ public final class ResourceFactory {
|
|||||||
if (consumer != null) consumer.accept(src, field);
|
if (consumer != null) consumer.accept(src, field);
|
||||||
String tname = rc.name();
|
String tname = rc.name();
|
||||||
if (tname.contains(RESOURCE_PARENT_NAME)) {
|
if (tname.contains(RESOURCE_PARENT_NAME)) {
|
||||||
try {
|
Resource res = src.getClass().getAnnotation(Resource.class);
|
||||||
Resource res = src.getClass().getAnnotation(Resource.class);
|
if (res == null) {
|
||||||
if (res == null) {
|
if (src instanceof Resourcable) {
|
||||||
String srcname = (String) src.getClass().getMethod("getResourceName").invoke(src);
|
tname = tname.replace(RESOURCE_PARENT_NAME, ((Resourcable) src).resourceName());
|
||||||
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
|
|
||||||
} else {
|
} else {
|
||||||
tname = res.name();
|
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or not implements Resourcable");
|
||||||
}
|
}
|
||||||
} catch (Exception e) { // 获取src中的name()方法的值, 异常则忽略
|
} else {
|
||||||
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or [public String getResourceName()] method", e);
|
tname = res.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
final String rcname = tname;
|
final String rcname = tname;
|
||||||
ResourceEntry re = findEntry(rcname, genctype);
|
ResourceEntry re = findEntry(rcname, genctype);
|
||||||
|
|||||||
Reference in New Issue
Block a user