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