diff --git a/src/org/redkale/boot/NodeInterceptor.java b/src/org/redkale/boot/NodeInterceptor.java
index 6c927c897..d9770f401 100644
--- a/src/org/redkale/boot/NodeInterceptor.java
+++ b/src/org/redkale/boot/NodeInterceptor.java
@@ -5,6 +5,9 @@
*/
package org.redkale.boot;
+import java.util.Objects;
+import org.redkale.service.Service;
+
/**
*
*
@@ -21,4 +24,64 @@ public class NodeInterceptor {
public void preShutdown(NodeServer server) {
}
+
+ public static class InterceptorServiceWrapper {
+
+ private String name;
+
+ private Class type;
+
+ private T service;
+
+ public InterceptorServiceWrapper() {
+ }
+
+ public InterceptorServiceWrapper(String name, Class type, T service) {
+ this.name = name;
+ this.type = type;
+ this.service = service;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Class getType() {
+ return type;
+ }
+
+ public void setType(Class type) {
+ this.type = type;
+ }
+
+ public T getService() {
+ return service;
+ }
+
+ public void setService(T service) {
+ this.service = service;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 97 * hash + Objects.hashCode(this.name);
+ hash = 97 * hash + Objects.hashCode(this.type);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ final InterceptorServiceWrapper> other = (InterceptorServiceWrapper>) obj;
+ return Objects.equals(this.name, other.name) && Objects.equals(this.type, other.type);
+ }
+
+ }
}
diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java
index 5fc7a690b..90e4a480c 100644
--- a/src/org/redkale/boot/NodeServer.java
+++ b/src/org/redkale/boot/NodeServer.java
@@ -75,6 +75,9 @@ public abstract class NodeServer {
//加载server节点后的拦截器
protected NodeInterceptor interceptor;
+ //供interceptor使用的Service对象集合
+ protected final Set interceptorServiceWrappers = new LinkedHashSet<>();
+
//本地模式的Service对象集合
protected final Set localServiceWrappers = new LinkedHashSet<>();
@@ -266,7 +269,11 @@ public abstract class NodeServer {
if (WebSocketNode.class.isAssignableFrom(type)) continue;
}
if (entry.getName().contains("$")) throw new RuntimeException(" value cannot contains '$' in " + entry.getProperty());
- if (resourceFactory.find(entry.getName(), type) != null) continue; //Server加载Service时需要判断是否已经加载过了。
+ if (resourceFactory.find(entry.getName(), type) != null) { //Server加载Service时需要判断是否已经加载过了。
+ Service oldother = resourceFactory.find(entry.getName(), type);
+ interceptorServiceWrappers.add(new NodeInterceptor.InterceptorServiceWrapper(entry.getName(), type, oldother));
+ continue;
+ }
final HashSet groups = entry.getGroups(); //groups.isEmpty()表示没有配置groups属性。
if (groups.isEmpty() && isSNCP() && this.sncpGroup != null) groups.add(this.sncpGroup);
@@ -299,6 +306,7 @@ public abstract class NodeServer {
remoteServiceWrappers.add(wrapper);
} else {
localServiceWrappers.add(wrapper);
+ interceptorServiceWrappers.add(new NodeInterceptor.InterceptorServiceWrapper(entry.getName(), type, service));
if (consumer != null) consumer.accept(wrapper);
}
} catch (RuntimeException ex) {
@@ -526,6 +534,10 @@ public abstract class NodeServer {
return (T) server;
}
+ public Set getInterceptorServiceWrappers() {
+ return new LinkedHashSet<>(interceptorServiceWrappers);
+ }
+
public Set getLocalServiceWrappers() {
return new LinkedHashSet<>(localServiceWrappers);
}