This commit is contained in:
@@ -135,6 +135,9 @@ public final class Application {
|
|||||||
//Server启动的计数器,用于确保所有Server都启动完后再进行下一步处理
|
//Server启动的计数器,用于确保所有Server都启动完后再进行下一步处理
|
||||||
private final CountDownLatch serversLatch;
|
private final CountDownLatch serversLatch;
|
||||||
|
|
||||||
|
//根ClassLoader
|
||||||
|
private final NodeClassLoader classLoader;
|
||||||
|
|
||||||
private Application(final AnyValue config) {
|
private Application(final AnyValue config) {
|
||||||
this(false, config);
|
this(false, config);
|
||||||
}
|
}
|
||||||
@@ -264,6 +267,8 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup);
|
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup);
|
||||||
|
this.classLoader = new NodeClassLoader(Thread.currentThread().getContextClassLoader());
|
||||||
|
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceFactory getResourceFactory() {
|
public ResourceFactory getResourceFactory() {
|
||||||
@@ -274,9 +279,10 @@ public final class Application {
|
|||||||
return transportFactory;
|
return transportFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public WatchFactory getWatchFactory() {
|
public NodeClassLoader getNodeClassLoader() {
|
||||||
// return watchFactory;
|
return classLoader;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public List<NodeServer> getNodeServers() {
|
public List<NodeServer> getNodeServers() {
|
||||||
return new ArrayList<>(servers);
|
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对象
|
//当前Server对象
|
||||||
protected final Server server;
|
protected final Server server;
|
||||||
|
|
||||||
|
//ClassLoader
|
||||||
|
protected final NodeClassLoader classLoader;
|
||||||
|
|
||||||
//当前Server的SNCP协议的组
|
//当前Server的SNCP协议的组
|
||||||
protected String sncpGroup = null;
|
protected String sncpGroup = null;
|
||||||
|
|
||||||
@@ -86,6 +89,8 @@ public abstract class NodeServer {
|
|||||||
this.resourceFactory = application.getResourceFactory().createChild();
|
this.resourceFactory = application.getResourceFactory().createChild();
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.logger = Logger.getLogger(this.getClass().getSimpleName());
|
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 {
|
protected Consumer<Runnable> getExecutor() throws Exception {
|
||||||
@@ -592,6 +597,10 @@ public abstract class NodeServer {
|
|||||||
return resourceFactory;
|
return resourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NodeClassLoader getNodeClassLoader() {
|
||||||
|
return classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
public InetSocketAddress getSncpAddress() {
|
public InetSocketAddress getSncpAddress() {
|
||||||
return sncpAddress;
|
return sncpAddress;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user