优化classloader
This commit is contained in:
@@ -20,6 +20,7 @@ import org.redkale.net.sncp.SncpClient;
|
||||
import org.redkale.net.sncp.SncpRpcGroups;
|
||||
import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Environment;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/** @author zhangjx */
|
||||
@@ -33,6 +34,8 @@ public class CachedInstanceTest {
|
||||
|
||||
private static CachedManagerService manager2;
|
||||
|
||||
private static RedkaleClassLoader classLoader;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
LoggingBaseHandler.initDebugLogConfig();
|
||||
CachedInstanceTest test = new CachedInstanceTest();
|
||||
@@ -43,7 +46,7 @@ public class CachedInstanceTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void init() throws Exception {
|
||||
|
||||
classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
|
||||
remoteSource.init(null);
|
||||
resourceFactory = ResourceFactory.create();
|
||||
@@ -61,6 +64,7 @@ public class CachedInstanceTest {
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
ClassLoader parent = Thread.currentThread().getContextClassLoader();
|
||||
Class<CachedInstance> serviceClass = CachedInstance.class;
|
||||
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
|
||||
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
|
||||
@@ -69,10 +73,19 @@ public class CachedInstanceTest {
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CachedInstance instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
classLoader, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
resourceFactory.inject(instance);
|
||||
CachedInstance instance2 = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
|
||||
new RedkaleClassLoader(parent),
|
||||
"",
|
||||
serviceClass,
|
||||
boost2,
|
||||
resourceFactory2,
|
||||
grous,
|
||||
client,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
resourceFactory2.inject(instance2);
|
||||
|
||||
System.out.println(instance.getName2());
|
||||
@@ -98,6 +111,7 @@ public class CachedInstanceTest {
|
||||
|
||||
@Test
|
||||
public void run2() throws Exception {
|
||||
ClassLoader parent = Thread.currentThread().getContextClassLoader();
|
||||
Class<CachedInstance> serviceClass = CachedInstance.class;
|
||||
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
|
||||
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
|
||||
@@ -106,10 +120,28 @@ public class CachedInstanceTest {
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CachedInstance instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
new RedkaleClassLoader(parent),
|
||||
"",
|
||||
serviceClass,
|
||||
boost,
|
||||
resourceFactory,
|
||||
grous,
|
||||
client,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
resourceFactory.inject(instance);
|
||||
CachedInstance instance2 = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
|
||||
new RedkaleClassLoader(parent),
|
||||
"",
|
||||
serviceClass,
|
||||
boost2,
|
||||
resourceFactory2,
|
||||
grous,
|
||||
client,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
resourceFactory2.inject(instance2);
|
||||
|
||||
int threads = Runtime.getRuntime().availableProcessors() * 10;
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.redkale.net.http.HttpServer;
|
||||
import org.redkale.net.http.HttpServlet;
|
||||
import org.redkale.net.sncp.Sncp;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,12 +45,13 @@ public class RestConvertTest {
|
||||
Method method = Application.class.getDeclaredMethod("initWorkExecutor");
|
||||
method.setAccessible(true);
|
||||
method.invoke(application);
|
||||
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
RestConvertService service = Sncp.createSimpleLocalService(RestConvertService.class, resFactory);
|
||||
RestConvertService service =
|
||||
Sncp.createSimpleLocalService(application.getClassLoader(), RestConvertService.class, resFactory);
|
||||
HttpServer server = new HttpServer(application, System.currentTimeMillis(), resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
System.out.println("servlet = " + server.addRestServlet(null, service, null, HttpServlet.class, ""));
|
||||
System.out.println("servlet = " + server.addRestServlet(classLoader, service, null, HttpServlet.class, ""));
|
||||
server.init(AnyValueWriter.create("port", 0));
|
||||
server.start();
|
||||
|
||||
|
||||
@@ -40,10 +40,12 @@ public class RestSleepTest {
|
||||
method.invoke(application);
|
||||
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
RestSleepService service = Sncp.createSimpleLocalService(RestSleepService.class, resFactory);
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RestSleepService service =
|
||||
Sncp.createSimpleLocalService(application.getClassLoader(), RestSleepService.class, resFactory);
|
||||
HttpServer server = new HttpServer(application, System.currentTimeMillis(), resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
System.out.println("servlet = " + server.addRestServlet(null, service, null, HttpServlet.class, ""));
|
||||
System.out.println("servlet = " + server.addRestServlet(classLoader, service, null, HttpServlet.class, ""));
|
||||
server.init(AnyValueWriter.create("port", 0));
|
||||
server.start();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.redkale.net.sncp.Sncp;
|
||||
import org.redkale.net.sncp.SncpClient;
|
||||
import org.redkale.net.sncp.SncpRpcGroups;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -38,6 +39,8 @@ public class MessagedInstanceTest {
|
||||
|
||||
private static ResourceFactory resourceFactory;
|
||||
|
||||
private static RedkaleClassLoader classLoader;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
LoggingBaseHandler.initDebugLogConfig();
|
||||
MessagedInstanceTest test = new MessagedInstanceTest();
|
||||
@@ -51,6 +54,7 @@ public class MessagedInstanceTest {
|
||||
application = Application.create(true);
|
||||
resourceFactory = application.getResourceFactory();
|
||||
engine = new MessageModuleEngine(application);
|
||||
classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
|
||||
MessageAgent agent = createMessageAgent(application, "mymq");
|
||||
MessageAgent[] messageAgents = new MessageAgent[] {agent};
|
||||
@@ -68,9 +72,8 @@ public class MessagedInstanceTest {
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
TestMessageService instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
classLoader, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
resourceFactory.inject(instance);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ABMainService implements Service {
|
||||
rpcGroups.computeIfAbsent("g99", "TCP").putAddress(new InetSocketAddress("127.0.0.1", 5599));
|
||||
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
CService cservice = Sncp.createSimpleLocalService(CService.class, resFactory);
|
||||
CService cservice = Sncp.createSimpleLocalService(application.getClassLoader(), CService.class, resFactory);
|
||||
SncpServer cserver = new SncpServer();
|
||||
cserver.getResourceFactory().register(application);
|
||||
// cserver.getLogger().setLevel(Level.WARNING);
|
||||
@@ -60,8 +60,9 @@ public class ABMainService implements Service {
|
||||
cserver.start();
|
||||
|
||||
// ------------------------ 初始化 BCService ------------------------------------
|
||||
BCService bcservice = Sncp.createSimpleLocalService(BCService.class, resFactory);
|
||||
CService remoteCService = Sncp.createSimpleRemoteService(CService.class, resFactory, rpcGroups, client, "g77");
|
||||
BCService bcservice = Sncp.createSimpleLocalService(application.getClassLoader(), BCService.class, resFactory);
|
||||
CService remoteCService = Sncp.createSimpleRemoteService(
|
||||
application.getClassLoader(), CService.class, resFactory, rpcGroups, client, "g77");
|
||||
if (remoteCService != null) {
|
||||
resFactory.inject(remoteCService);
|
||||
resFactory.register("", remoteCService);
|
||||
@@ -74,9 +75,10 @@ public class ABMainService implements Service {
|
||||
bcserver.start();
|
||||
|
||||
// ------------------------ 初始化 ABMainService ------------------------------------
|
||||
ABMainService service = Sncp.createSimpleLocalService(ABMainService.class, resFactory);
|
||||
BCService remoteBCService =
|
||||
Sncp.createSimpleRemoteService(BCService.class, resFactory, rpcGroups, client, "g88");
|
||||
ABMainService service =
|
||||
Sncp.createSimpleLocalService(application.getClassLoader(), ABMainService.class, resFactory);
|
||||
BCService remoteBCService = Sncp.createSimpleRemoteService(
|
||||
application.getClassLoader(), BCService.class, resFactory, rpcGroups, client, "g88");
|
||||
if (remoteBCService != null) {
|
||||
resFactory.inject(remoteBCService);
|
||||
resFactory.register("", remoteBCService);
|
||||
|
||||
@@ -41,7 +41,8 @@ public class SncpSleepTest {
|
||||
resFactory.register(ProtobufConvert.root());
|
||||
|
||||
// ------------------------ 初始化 CService ------------------------------------
|
||||
SncpSleepService service = Sncp.createSimpleLocalService(SncpSleepService.class, resFactory);
|
||||
SncpSleepService service =
|
||||
Sncp.createSimpleLocalService(application.getClassLoader(), SncpSleepService.class, resFactory);
|
||||
resFactory.inject(service);
|
||||
SncpServer server = new SncpServer(application, System.currentTimeMillis(), null, resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
@@ -56,8 +57,8 @@ public class SncpSleepTest {
|
||||
new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
final SncpRpcGroups rpcGroups = application.getSncpRpcGroups();
|
||||
rpcGroups.computeIfAbsent("cs", "TCP").putAddress(sncpAddress);
|
||||
SncpSleepService remoteCService =
|
||||
Sncp.createSimpleRemoteService(SncpSleepService.class, resFactory, rpcGroups, client, "cs");
|
||||
SncpSleepService remoteCService = Sncp.createSimpleRemoteService(
|
||||
application.getClassLoader(), SncpSleepService.class, resFactory, rpcGroups, client, "cs");
|
||||
long s = System.currentTimeMillis();
|
||||
CompletableFuture[] futures =
|
||||
new CompletableFuture[] {remoteCService.sleep200(), remoteCService.sleep300(), remoteCService.sleep500()
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.redkale.test.sncp;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.boot.*;
|
||||
import org.redkale.convert.pb.ProtobufConvert;
|
||||
@@ -37,25 +38,32 @@ public class SncpTest {
|
||||
|
||||
private static Application application;
|
||||
|
||||
private static RedkaleClassLoader classLoader;
|
||||
|
||||
private static SncpRpcGroups rpcGroups;
|
||||
|
||||
private boolean main;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
SncpTest test = new SncpTest();
|
||||
init();
|
||||
test.main = true;
|
||||
test.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
@BeforeAll
|
||||
public static void init() throws Exception {
|
||||
LoggingBaseHandler.initDebugLogConfig();
|
||||
application = Application.create(true);
|
||||
classLoader = application.getClassLoader();
|
||||
rpcGroups = application.getSncpRpcGroups();
|
||||
factory = application.getResourceFactory();
|
||||
factory.register("", ProtobufConvert.class, ProtobufFactory.root().getConvert());
|
||||
factory.register("", Application.class, application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
if (System.getProperty("client") == null) {
|
||||
runServer();
|
||||
if (port2 > 0) {
|
||||
@@ -95,6 +103,7 @@ public class SncpTest {
|
||||
100);
|
||||
|
||||
final SncpTestIService service = Sncp.createSimpleRemoteService(
|
||||
classLoader,
|
||||
SncpTestIService.class,
|
||||
factory,
|
||||
rpcGroups,
|
||||
@@ -200,6 +209,7 @@ public class SncpTest {
|
||||
}
|
||||
|
||||
SncpTestIService service = Sncp.createSimpleLocalService(
|
||||
classLoader,
|
||||
SncpTestServiceImpl.class,
|
||||
factory); // Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory,
|
||||
// transFactory, addr, "server");
|
||||
@@ -242,6 +252,7 @@ public class SncpTest {
|
||||
.putAddress(new InetSocketAddress(myhost, port));
|
||||
|
||||
Service service = Sncp.createSimpleLocalService(
|
||||
new RedkaleClassLoader(Thread.currentThread().getContextClassLoader()),
|
||||
SncpTestServiceImpl.class,
|
||||
factory); // Sncp.createSimpleLocalService(SncpTestServiceImpl.class, null, factory,
|
||||
// transFactory, addr, "server");
|
||||
|
||||
@@ -95,7 +95,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
final SncpClient client =
|
||||
new SncpClient("", asyncGroup, "0", sncpAddress, new ClientAddress(sncpAddress), "TCP", 16, 100);
|
||||
|
||||
Service service = Sncp.createSimpleLocalService(SncpTestServiceImpl.class, factory);
|
||||
Service service =
|
||||
Sncp.createSimpleLocalService(application.getClassLoader(), SncpTestServiceImpl.class, factory);
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
@@ -104,7 +105,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
System.out.println(method);
|
||||
}
|
||||
System.out.println("-----------------------------------");
|
||||
service = Sncp.createSimpleRemoteService(SncpTestServiceImpl.class, factory, rpcGroups, client, "g70");
|
||||
service = Sncp.createSimpleRemoteService(
|
||||
application.getClassLoader(), SncpTestServiceImpl.class, factory, rpcGroups, client, "g70");
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
@@ -113,7 +115,8 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
System.out.println(method);
|
||||
}
|
||||
System.out.println("-----------------------------------");
|
||||
service = Sncp.createSimpleRemoteService(SncpTestIService.class, factory, rpcGroups, client, "g70");
|
||||
service = Sncp.createSimpleRemoteService(
|
||||
application.getClassLoader(), SncpTestIService.class, factory, rpcGroups, client, "g70");
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user