This commit is contained in:
@@ -135,6 +135,9 @@ public final class Application {
|
||||
//Server启动的计数器,用于确保所有Server都启动完后再进行下一步处理
|
||||
private final CountDownLatch serversLatch;
|
||||
|
||||
//根ClassLoader
|
||||
private final NodeClassLoader classLoader;
|
||||
|
||||
private Application(final AnyValue config) {
|
||||
this(false, config);
|
||||
}
|
||||
@@ -264,6 +267,8 @@ public final class Application {
|
||||
}
|
||||
}
|
||||
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup);
|
||||
this.classLoader = new NodeClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||
}
|
||||
|
||||
public ResourceFactory getResourceFactory() {
|
||||
@@ -274,9 +279,10 @@ public final class Application {
|
||||
return transportFactory;
|
||||
}
|
||||
|
||||
// public WatchFactory getWatchFactory() {
|
||||
// return watchFactory;
|
||||
// }
|
||||
public NodeClassLoader getNodeClassLoader() {
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
public List<NodeServer> getNodeServers() {
|
||||
return new ArrayList<>(servers);
|
||||
}
|
||||
|
||||
28
src/org/redkale/boot/NodeClassLoader.java
Normal file
28
src/org/redkale/boot/NodeClassLoader.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.boot;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class NodeClassLoader extends URLClassLoader {
|
||||
|
||||
public NodeClassLoader(ClassLoader parent) {
|
||||
super(new URL[0], parent);
|
||||
}
|
||||
|
||||
public Class<?> loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(URL url) {
|
||||
super.addURL(url);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,9 @@ public abstract class NodeServer {
|
||||
//当前Server对象
|
||||
protected final Server server;
|
||||
|
||||
//ClassLoader
|
||||
protected final NodeClassLoader classLoader;
|
||||
|
||||
//当前Server的SNCP协议的组
|
||||
protected String sncpGroup = null;
|
||||
|
||||
@@ -86,6 +89,8 @@ public abstract class NodeServer {
|
||||
this.resourceFactory = application.getResourceFactory().createChild();
|
||||
this.server = server;
|
||||
this.logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
this.classLoader = new NodeClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||
}
|
||||
|
||||
protected Consumer<Runnable> getExecutor() throws Exception {
|
||||
@@ -592,6 +597,10 @@ public abstract class NodeServer {
|
||||
return resourceFactory;
|
||||
}
|
||||
|
||||
public NodeClassLoader getNodeClassLoader() {
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
public InetSocketAddress getSncpAddress() {
|
||||
return sncpAddress;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user