This commit is contained in:
Redkale
2017-03-21 09:47:18 +08:00
parent c4923f317b
commit 63a9005e6b
5 changed files with 15 additions and 22 deletions

View File

@@ -69,7 +69,7 @@ public abstract class WebSocketServlet extends HttpServlet {
public final void preInit(HttpContext context, AnyValue conf) {
InetSocketAddress addr = context.getServerAddress();
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + name() + "]", this.node, logger);
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + getResourceName() + "]", this.node, logger);
if (this.node == null) this.node = createWebSocketNode();
if (this.node == null) {
this.node = new WebSocketNodeService();
@@ -86,7 +86,7 @@ public abstract class WebSocketServlet extends HttpServlet {
engine.close();
}
public String name() {
public String getResourceName() {
return this.getClass().getSimpleName().replace("Servlet", "").replace("WebSocket", "").toLowerCase();
}

View File

@@ -154,7 +154,7 @@ public final class SncpClient {
this.remote = remote;
this.executor = executor;
this.serviceClass = serviceClass;
this.serviceversion = service.version();
this.serviceversion = 0;
this.clientAddress = clientAddress;
this.name = serviceName;
this.serviceid = Sncp.hash(serviceType.getName() + ':' + serviceName);
@@ -216,7 +216,7 @@ public final class SncpClient {
if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue;
if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue;
if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
if (method.getName().equals("version") || method.getName().equals("name")) continue;
//if (method.getName().equals("version") || method.getName().equals("name")) continue;
//if (onlySncpDyn && method.getAnnotation(SncpDyn.class) == null) continue;
DLong actionid = Sncp.hash(method);
Method old = actionids.get(actionid);

View File

@@ -63,7 +63,7 @@ public final class SncpDynServlet extends SncpServlet {
if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue;
if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue;
if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
if (method.getName().equals("version") || method.getName().equals("name")) continue;
//if (method.getName().equals("version") || method.getName().equals("name")) continue;
final DLong actionid = Sncp.hash(method);
SncpServletAction action = SncpServletAction.create(service, actionid, method);
action.convert = convert;

View File

@@ -8,8 +8,8 @@ package org.redkale.service;
import org.redkale.util.*;
/**
* 所有Service的实现类不得声明为final 允许远程模式的public方法都不能声明为final。
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。
* 所有Service的实现类不得声明为final 允许远程模式的public方法都不能声明为final。<br>
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。<br>
*
* <blockquote><pre>
* Service的资源类型
@@ -59,14 +59,4 @@ public interface Service {
}
/**
* Service的接口版本号
* <b>注: public方法的参数或返回类型或参数类型内部变更后改值必须进行改变</b>
*
* @return 接口版本号
*/
default int version() {
return 0;
}
}

View File

@@ -15,10 +15,13 @@ import java.util.regex.Pattern;
import javax.annotation.Resource;
/**
* 如果Resource(name = "$") 表示资源name采用所属对象的name
* 如果&#64;Resource(name = "$") 表示资源name采用所属对象的name <br>
* 如果没有&#64;Resource 则会取对象的getResourceName()方法值(若存在)
* <blockquote><pre>
* name规则:
* 1: "$"有特殊含义, 不能表示"$"资源本身
* 2: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合
* 1: "$"有特殊含义, 不能表示"$"资源本身
* 2: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合
* </pre></blockquote>
* <p>
* 详情见: https://redkale.org
*
@@ -323,13 +326,13 @@ public final class ResourceFactory {
try {
Resource res = src.getClass().getAnnotation(Resource.class);
if (res == null) {
String srcname = (String) src.getClass().getMethod("name").invoke(src);
String srcname = (String) src.getClass().getMethod("getResourceName").invoke(src);
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
} else {
tname = res.name();
}
} catch (Exception e) { // 获取src中的name()方法的值, 异常则忽略
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or [public String name()] method", e);
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or [public String getResourceName()] method", e);
}
}
final String rcname = tname;