This commit is contained in:
@@ -97,7 +97,7 @@
|
||||
</resources>
|
||||
<!--
|
||||
protocol: required server所启动的协议,Redkale内置的有HTTP、SNCP、WATCH,SNCP使用TCP实现;
|
||||
name: 服务的名称,用于监控识别,一个配置文件中的server.name不能重复,命名规则: 字母、数字、下划线、减号
|
||||
name: 服务的名称,用于监控识别,一个配置文件中的server.name不能重复,命名规则: 字母、数字、下划线
|
||||
host: 服务所占address , 默认: 0.0.0.0
|
||||
port: required 服务所占端口
|
||||
root: 如果是web类型服务,则包含页面 默认:{APP_HOME}/root
|
||||
|
||||
@@ -366,14 +366,45 @@ public final class Application {
|
||||
public void load(ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) {
|
||||
try {
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res == null || !res.name().isEmpty()) return;
|
||||
if (res == null) return;
|
||||
if (!(src instanceof WatchService) || Sncp.isRemote((Service) src)) return; //远程模式不得注入
|
||||
Class type = field.getType();
|
||||
if (type == Application.class) {
|
||||
field.set(src, application);
|
||||
// } else if (type == WatchFactory.class) {
|
||||
// field.set(src, application.watchFactory);
|
||||
} else if (type == NodeSncpServer.class) {
|
||||
NodeServer server = null;
|
||||
for (NodeServer ns : application.getNodeServers()) {
|
||||
if (ns.getClass() == NodeSncpServer.class) continue;
|
||||
if (res.name().equals(ns.server.getName())) {
|
||||
server = ns;
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.set(src, server);
|
||||
} else if (type == NodeHttpServer.class) {
|
||||
NodeServer server = null;
|
||||
for (NodeServer ns : application.getNodeServers()) {
|
||||
if (ns.getClass() == NodeHttpServer.class) continue;
|
||||
if (res.name().equals(ns.server.getName())) {
|
||||
server = ns;
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.set(src, server);
|
||||
} else if (type == NodeWatchServer.class) {
|
||||
NodeServer server = null;
|
||||
for (NodeServer ns : application.getNodeServers()) {
|
||||
if (ns.getClass() == NodeWatchServer.class) continue;
|
||||
if (res.name().equals(ns.server.getName())) {
|
||||
server = ns;
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.set(src, server);
|
||||
}
|
||||
// if (type == WatchFactory.class) {
|
||||
// field.set(src, application.watchFactory);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
}
|
||||
@@ -383,8 +414,8 @@ public final class Application {
|
||||
public boolean autoNone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}, Application.class, WatchFactory.class);
|
||||
|
||||
}, Application.class, WatchFactory.class, NodeSncpServer.class, NodeHttpServer.class, NodeWatchServer.class);
|
||||
//--------------------------------------------------------------------------
|
||||
initResources();
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ public class NodeHttpServer extends NodeServer {
|
||||
return new HttpServer(application.getStartTime());
|
||||
}
|
||||
|
||||
public HttpServer getHttpServer() {
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getSocketAddress() {
|
||||
return httpServer == null ? null : httpServer.getSocketAddress();
|
||||
|
||||
@@ -604,6 +604,10 @@ public abstract class NodeServer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ResourceFactory getResourceFactory() {
|
||||
return resourceFactory;
|
||||
}
|
||||
|
||||
public InetSocketAddress getSncpAddress() {
|
||||
return sncpAddress;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package org.redkale.watch;
|
||||
* <p> 详情见: https://redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
public interface WatchNode {
|
||||
interface WatchNode {
|
||||
|
||||
public String getName();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.concurrent.atomic.*;
|
||||
* <p> 详情见: https://redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class WatchNumber extends AtomicLong implements WatchNode {
|
||||
final class WatchNumber extends AtomicLong implements WatchNode {
|
||||
|
||||
private final boolean interval;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Documented
|
||||
@Target({FIELD, METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Watchable {
|
||||
@interface Watchable {
|
||||
|
||||
String name();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user