优化classloader
This commit is contained in:
@@ -151,7 +151,8 @@ class AppConfig {
|
||||
if (compileMode || this.classLoader instanceof RedkaleClassLoader.RedkaleCacheClassLoader) {
|
||||
this.serverClassLoader = this.classLoader;
|
||||
} else {
|
||||
this.serverClassLoader = new RedkaleClassLoader(this.classLoader);
|
||||
//this.serverClassLoader = RedkaleClassLoader.getRedkaleClassLoader(this.classLoader);
|
||||
this.serverClassLoader = this.classLoader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,11 @@ class NodeExpectServiceLoader implements ResourceTypeLoader {
|
||||
group,
|
||||
entry.getProperty());
|
||||
}
|
||||
final Class restype = Sncp.getResourceType(service);
|
||||
if (rf.find(resourceName, restype) == null) {
|
||||
regFactory.register(resourceName, restype, service);
|
||||
final Class resType = Sncp.getResourceType(service);
|
||||
if (rf.find(resourceName, resType) == null) {
|
||||
regFactory.register(resourceName, resType, service);
|
||||
} else if (nodeServer.isSNCP() && !entry.isAutoload()) {
|
||||
throw new RedkaleException(restype.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:"
|
||||
throw new RedkaleException(resType.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:"
|
||||
+ resourceName + ", group:" + group + ") is repeat.");
|
||||
}
|
||||
if (Sncp.isRemote(service)) {
|
||||
|
||||
@@ -119,8 +119,8 @@ public class NodeHttpServer extends NodeServer {
|
||||
|
||||
@Override
|
||||
protected void loadService(ClassFilter<? extends Service> serviceFilter) throws Exception {
|
||||
super.loadService(serviceFilter);
|
||||
resourceFactory.register(new NodeWebSocketNodeLoader(this));
|
||||
super.loadService(serviceFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -110,12 +110,7 @@ public abstract class NodeServer {
|
||||
this.server = server;
|
||||
this.resourceFactory = server.getResourceFactory();
|
||||
this.logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
if (application.isCompileMode()
|
||||
|| application.getServerClassLoader() instanceof RedkaleClassLoader.RedkaleCacheClassLoader) {
|
||||
this.serverClassLoader = application.getServerClassLoader();
|
||||
} else {
|
||||
this.serverClassLoader = RedkaleClassLoader.getRedkaleClassLoader(application.getServerClassLoader());
|
||||
}
|
||||
this.serverClassLoader = application.getServerClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.serverClassLoader);
|
||||
this.serverThread = Thread.currentThread();
|
||||
this.server.setServerClassLoader(serverClassLoader);
|
||||
@@ -301,6 +296,12 @@ public abstract class NodeServer {
|
||||
throw new RedkaleException("Not found group(" + entry.getGroup() + ")");
|
||||
}
|
||||
Service oldOther = resourceFactory.find(entry.getName(), serviceImplClass);
|
||||
if (oldOther == null) {
|
||||
Class<? extends Service> resType = Sncp.getResourceType(serviceImplClass);
|
||||
if (resType != serviceImplClass) {
|
||||
oldOther = resourceFactory.find(entry.getName(), resType);
|
||||
}
|
||||
}
|
||||
if (oldOther != null) { // Server加载Service时需要判断是否已在其他协议服务中加载
|
||||
if (!Sncp.isRemote(oldOther)) {
|
||||
if (!Sncp.isComponent(oldOther)) {
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class clz = loader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
JsonDynEncoder resultEncoder =
|
||||
(JsonDynEncoder) newClazz.getConstructor(JsonFactory.class, Type.class, ObjectEncoder.class)
|
||||
@@ -681,7 +681,7 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
loader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(
|
||||
newClazz, newDynName.replace('/', '.'), JsonFactory.class, Type.class);
|
||||
try {
|
||||
|
||||
@@ -69,13 +69,13 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
||||
}
|
||||
}
|
||||
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/convert/pb/_Dyn" + ProtobufDynEncoder.class.getSimpleName() + "__"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
ProtobufDynEncoder resultEncoder = (ProtobufDynEncoder)
|
||||
newClazz.getConstructor(ProtobufFactory.class, Type.class, ProtobufObjectEncoder.class)
|
||||
.newInstance(factory, clazz, selfObjEncoder);
|
||||
@@ -321,8 +321,8 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<ProtobufDynEncoder> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<ProtobufDynEncoder> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
ProtobufDynEncoder resultEncoder = (ProtobufDynEncoder)
|
||||
|
||||
@@ -328,7 +328,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
||||
consumerBytes.forEach((innerFullName, bytes) -> {
|
||||
String clzName = innerFullName.replace('/', '.');
|
||||
Class clazz = classLoader.loadClass(clzName, bytes);
|
||||
RedkaleClassLoader.putDynClass(clzName, bytes, clazz);
|
||||
classLoader.putDynClass(clzName, bytes, clazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
||||
AnnotationVisitor av2 =
|
||||
av1.visitAnnotation(null, org.redkale.asm.Type.getDescriptor(DynForMessaged.class));
|
||||
|
||||
@@ -459,7 +459,7 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
try {
|
||||
String clzName = innerFullName.replace('/', '.');
|
||||
Class<? extends MessageConsumer> clazz = classLoader.loadClass(clzName, bytes);
|
||||
RedkaleClassLoader.putDynClass(clzName, bytes, clazz);
|
||||
classLoader.putDynClass(clzName, bytes, clazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
||||
MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service);
|
||||
addMessageConsumer(consumer);
|
||||
|
||||
@@ -108,10 +108,10 @@ public class HttpContext extends Context {
|
||||
final String handlerDesc = Type.getDescriptor(CompletionHandler.class);
|
||||
final String newDynName = "org/redkaledyn/http/handler/_DynHttpAsyncHandler__"
|
||||
+ handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
return Creator.create(newHandlerClazz);
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
@@ -213,8 +213,8 @@ public class HttpContext extends Context {
|
||||
}
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<CompletionHandler> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<CompletionHandler> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
return (Creator<H>) Creator.create(newClazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
* @return RestServlet
|
||||
*/
|
||||
public <S extends WebSocket, T extends WebSocketServlet> T addRestWebSocketServlet(
|
||||
final ClassLoader classLoader,
|
||||
final RedkaleClassLoader classLoader,
|
||||
final Class<S> webSocketType,
|
||||
final MessageAgent messageAgent,
|
||||
final String prefix,
|
||||
@@ -300,7 +300,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
* @return RestServlet
|
||||
*/
|
||||
public <S extends Service, T extends HttpServlet> T addRestServlet(
|
||||
final ClassLoader classLoader,
|
||||
final RedkaleClassLoader classLoader,
|
||||
final S service,
|
||||
final Class userType,
|
||||
final Class<T> baseServletType,
|
||||
@@ -324,7 +324,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends Service, T extends HttpServlet> T addRestServlet(
|
||||
final ClassLoader classLoader,
|
||||
final RedkaleClassLoader classLoader,
|
||||
final String name,
|
||||
final S service,
|
||||
final Class userType,
|
||||
|
||||
@@ -560,12 +560,12 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
for (Class cz : method.getParameterTypes()) {
|
||||
tmpps.append("__").append(cz.getName().replace('.', '_'));
|
||||
}
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/http/servlet/action/_DynHttpActionServlet__"
|
||||
+ this.getClass().getName().replace('.', '_').replace('$', '_') + "__" + method.getName() + tmpps;
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
HttpServlet instance =
|
||||
(HttpServlet) newClazz.getDeclaredConstructor().newInstance();
|
||||
instance.getClass().getField("_factServlet").set(instance, this);
|
||||
@@ -626,8 +626,8 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
cw.visitEnd();
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
HttpServlet instance =
|
||||
|
||||
@@ -307,7 +307,7 @@ public final class Rest {
|
||||
}
|
||||
|
||||
public static <T extends WebSocketServlet> T createRestWebSocketServlet(
|
||||
final ClassLoader classLoader, final Class<? extends WebSocket> webSocketType, MessageAgent messageAgent) {
|
||||
RedkaleClassLoader classLoader, Class<? extends WebSocket> webSocketType, MessageAgent messageAgent) {
|
||||
if (webSocketType == null) {
|
||||
throw new RestException("Rest WebSocket Class is null on createRestWebSocketServlet");
|
||||
}
|
||||
@@ -348,7 +348,6 @@ public final class Rest {
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
final Set<Field> resourcesFieldSet = new LinkedHashSet<>();
|
||||
final ClassLoader loader = classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader;
|
||||
final Set<String> resourcesFieldNameSet = new HashSet<>();
|
||||
Class clzz = webSocketType;
|
||||
do {
|
||||
@@ -456,9 +455,9 @@ public final class Rest {
|
||||
final String newDynConsumerSimpleName = "_DynRestOnMessageConsumer";
|
||||
final String newDynConsumerFullName = newDynName + "$" + newDynConsumerSimpleName;
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
if (clz == null) {
|
||||
clz = loader.loadClass(newDynName.replace('/', '.'));
|
||||
clz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
}
|
||||
T servlet = (T) clz.getDeclaredConstructor().newInstance();
|
||||
Map<String, Annotation[]> msgclassToAnnotations = new HashMap<>();
|
||||
@@ -660,7 +659,6 @@ public final class Rest {
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
RedkaleClassLoader newLoader = RedkaleClassLoader.getRedkaleClassLoader(loader);
|
||||
Map<String, Annotation[]> msgclassToAnnotations = new HashMap<>();
|
||||
for (int i = 0; i < messageMethods.size(); i++) { // _DyncXXXWebSocketMessage 子消息List
|
||||
final Method method = messageMethods.get(i);
|
||||
@@ -901,8 +899,8 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = newLoader.loadClass((newDynSuperMessageFullName).replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass((newDynSuperMessageFullName).replace('/', '.'), bytes, cz);
|
||||
Class cz = classLoader.loadClass((newDynSuperMessageFullName).replace('/', '.'), bytes);
|
||||
classLoader.putDynClass((newDynSuperMessageFullName).replace('/', '.'), bytes, cz);
|
||||
}
|
||||
|
||||
if (wildcardMethod == null) { // _DynXXXWebSocketMessage class
|
||||
@@ -959,8 +957,8 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = newLoader.loadClass(newDynMessageFullName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynMessageFullName.replace('/', '.'), bytes, cz);
|
||||
Class cz = classLoader.loadClass(newDynMessageFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynMessageFullName.replace('/', '.'), bytes, cz);
|
||||
}
|
||||
|
||||
{ // _DynXXXWebSocket class
|
||||
@@ -1002,8 +1000,8 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = newLoader.loadClass(newDynWebSokcetFullName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynWebSokcetFullName.replace('/', '.'), bytes, cz);
|
||||
Class cz = classLoader.loadClass(newDynWebSokcetFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynWebSokcetFullName.replace('/', '.'), bytes, cz);
|
||||
}
|
||||
|
||||
{ // _DynRestOnMessageConsumer class
|
||||
@@ -1110,14 +1108,14 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
Class cz = newLoader.loadClass(newDynConsumerFullName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynConsumerFullName.replace('/', '.'), bytes, cz);
|
||||
Class cz = classLoader.loadClass(newDynConsumerFullName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynConsumerFullName.replace('/', '.'), bytes, cz);
|
||||
}
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = newLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
JsonFactory.root().loadDecoder(newClazz.getAnnotation(RestDyn.class).types()[2]); // 固定Message类
|
||||
|
||||
@@ -1152,7 +1150,7 @@ public final class Rest {
|
||||
}
|
||||
|
||||
public static <T extends HttpServlet> T createRestServlet(
|
||||
final ClassLoader classLoader,
|
||||
final RedkaleClassLoader classLoader,
|
||||
final Class userType0,
|
||||
final Class<T> baseServletType,
|
||||
final Class<? extends Service> serviceType,
|
||||
@@ -1277,7 +1275,6 @@ public final class Rest {
|
||||
final boolean serRpcOnly = controller != null && controller.rpcOnly();
|
||||
final Boolean parentNonBlocking = parentNon0;
|
||||
|
||||
ClassLoader loader = classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader;
|
||||
String stname = serviceType.getSimpleName();
|
||||
if (stname.startsWith("Service")) { // 类似ServiceWatchService这样的类保留第一个Service字样
|
||||
stname = "Service" + stname.substring("Service".length()).replaceAll("Service.*$", "");
|
||||
@@ -1304,9 +1301,9 @@ public final class Rest {
|
||||
+ (namePostfix.isEmpty() ? "" : ("_" + namePostfix) + "DynServlet");
|
||||
|
||||
try {
|
||||
Class newClazz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = classLoader.findClass(newDynName.replace('/', '.'));
|
||||
if (newClazz == null) {
|
||||
newClazz = loader.loadClass(newDynName.replace('/', '.'));
|
||||
newClazz = classLoader.loadClass(newDynName.replace('/', '.'));
|
||||
}
|
||||
T obj = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -1989,7 +1986,6 @@ public final class Rest {
|
||||
return null; // 没有可HttpMapping的方法
|
||||
}
|
||||
Collections.sort(entrys);
|
||||
RedkaleClassLoader newLoader = RedkaleClassLoader.getRedkaleClassLoader(loader);
|
||||
final int moduleid = controller == null ? 0 : controller.moduleid();
|
||||
{ // 注入 @WebServlet 注解
|
||||
String urlpath = "";
|
||||
@@ -4072,7 +4068,7 @@ public final class Rest {
|
||||
}
|
||||
cw2.visitEnd();
|
||||
byte[] bytes = cw2.toByteArray();
|
||||
newLoader.addDynClass((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
||||
classLoader.addDynClass((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
||||
innerClassBytesMap.put((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
||||
}
|
||||
} // end for each
|
||||
@@ -4236,18 +4232,18 @@ public final class Rest {
|
||||
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
newLoader.addDynClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.addDynClass(newDynName.replace('/', '.'), bytes);
|
||||
try {
|
||||
Class<?> newClazz = newLoader.findClass(newDynName.replace('/', '.'));
|
||||
Class<?> newClazz = classLoader.findClass(newDynName.replace('/', '.'));
|
||||
innerClassBytesMap.forEach((n, bs) -> {
|
||||
try {
|
||||
RedkaleClassLoader.putDynClass(n, bs, newLoader.findClass(n));
|
||||
classLoader.putDynClass(n, bs, classLoader.findClass(n));
|
||||
RedkaleClassLoader.putReflectionClass(n);
|
||||
} catch (Exception e) {
|
||||
throw new RestException(e);
|
||||
}
|
||||
});
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
for (java.lang.reflect.Type t : retvalTypes) {
|
||||
JsonFactory.root().loadEncoder(t);
|
||||
|
||||
@@ -483,7 +483,7 @@ public abstract class Sncp {
|
||||
* 创建Service的本地模式Class
|
||||
*
|
||||
* @param <T> Service子类
|
||||
* @param dynLoader DynBytesClassLoader
|
||||
* @param classLoader DynBytesClassLoader
|
||||
* @param name 资源名
|
||||
* @param serviceImplClass Service类
|
||||
* @param methodBoost 方法扩展
|
||||
@@ -491,7 +491,7 @@ public abstract class Sncp {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <T extends Service> Class<? extends T> createLocalServiceClass(
|
||||
RedkaleClassLoader dynLoader,
|
||||
RedkaleClassLoader classLoader,
|
||||
final String name,
|
||||
final Class<T> serviceImplClass,
|
||||
final AsmMethodBoost methodBoost) {
|
||||
@@ -527,17 +527,16 @@ public abstract class Sncp {
|
||||
}
|
||||
newDynName += "_" + (normal ? name : hash(name));
|
||||
}
|
||||
if (Utility.inNativeImage() || methodBoost == null) { // 加强动态时不能重复加载
|
||||
try {
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynClass);
|
||||
return (Class<T>) (clz == null ? dynLoader.loadClass(newDynClass) : clz);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// do nothing
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
// if (Utility.inNativeImage() || methodBoost == null) { // 加强动态时不能重复加载
|
||||
try {
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
return (Class<T>) classLoader.findClass(newDynClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// do nothing
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
// }
|
||||
// ------------------------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
FieldVisitor fv;
|
||||
@@ -584,8 +583,8 @@ public abstract class Sncp {
|
||||
fv.visitEnd();
|
||||
}
|
||||
if (methodBoost != null) {
|
||||
createNewMethods(dynLoader, serviceImplClass, methodBoost, new HashSet<>(), cw, newDynName, supDynName);
|
||||
methodBoost.doAfterMethods(dynLoader, cw, newDynName, FIELDPREFIX);
|
||||
createNewMethods(classLoader, serviceImplClass, methodBoost, new HashSet<>(), cw, newDynName, supDynName);
|
||||
methodBoost.doAfterMethods(classLoader, cw, newDynName, FIELDPREFIX);
|
||||
}
|
||||
{ // 构造函数
|
||||
mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
|
||||
@@ -593,7 +592,7 @@ public abstract class Sncp {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, supDynName, "<init>", "()V", false);
|
||||
if (methodBoost != null) {
|
||||
methodBoost.doConstructorMethod(dynLoader, cw, mv, newDynName, FIELDPREFIX, false);
|
||||
methodBoost.doConstructorMethod(classLoader, cw, mv, newDynName, FIELDPREFIX, false);
|
||||
}
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
@@ -602,9 +601,9 @@ public abstract class Sncp {
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class<?> newClazz = dynLoader.loadClass(newDynClass, bytes);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynClass, bytes);
|
||||
|
||||
RedkaleClassLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
classLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicClasses(newDynClass);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynClass);
|
||||
try {
|
||||
@@ -620,8 +619,9 @@ public abstract class Sncp {
|
||||
}
|
||||
|
||||
public static <T extends Service> T createSimpleLocalService(
|
||||
Class<T> serviceImplClass, ResourceFactory resourceFactory) {
|
||||
return createLocalService(null, "", serviceImplClass, null, resourceFactory, null, null, null, null, null);
|
||||
RedkaleClassLoader classLoader, Class<T> serviceImplClass, ResourceFactory resourceFactory) {
|
||||
return createLocalService(
|
||||
classLoader, "", serviceImplClass, null, resourceFactory, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private static void createNewMethods(
|
||||
@@ -765,8 +765,7 @@ public abstract class Sncp {
|
||||
final String remoteGroup,
|
||||
final AnyValue conf) {
|
||||
try {
|
||||
final RedkaleClassLoader dynLoader = RedkaleClassLoader.getRedkaleClassLoader(classLoader);
|
||||
final Class newClazz = createLocalServiceClass(dynLoader, name, serviceImplClass, methodBoost);
|
||||
final Class newClazz = createLocalServiceClass(classLoader, name, serviceImplClass, methodBoost);
|
||||
T service = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||
// --------------------------------------
|
||||
Service remoteService = null;
|
||||
@@ -818,7 +817,7 @@ public abstract class Sncp {
|
||||
}
|
||||
if (methodBoost != null) {
|
||||
// 必须用servcie的ClassLoader, 因为service是动态ClassLoader会与doMethod里的动态ClassLoader不一致
|
||||
methodBoost.doInstance(dynLoader, resourceFactory, service);
|
||||
methodBoost.doInstance(classLoader, resourceFactory, service);
|
||||
}
|
||||
return service;
|
||||
} catch (RuntimeException rex) {
|
||||
@@ -829,6 +828,7 @@ public abstract class Sncp {
|
||||
}
|
||||
|
||||
public static <T extends Service> T createSimpleRemoteService(
|
||||
RedkaleClassLoader classLoader,
|
||||
Class<T> serviceImplClass,
|
||||
ResourceFactory resourceFactory,
|
||||
SncpRpcGroups sncpRpcGroups,
|
||||
@@ -841,7 +841,7 @@ public abstract class Sncp {
|
||||
throw new SncpException(SncpClient.class.getSimpleName() + " is null");
|
||||
}
|
||||
return createRemoteService(
|
||||
null, "", serviceImplClass, null, resourceFactory, sncpRpcGroups, client, null, group, null);
|
||||
classLoader, "", serviceImplClass, null, resourceFactory, sncpRpcGroups, client, null, group, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -897,7 +897,7 @@ public abstract class Sncp {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Service> T createRemoteService(
|
||||
final ClassLoader classLoader,
|
||||
final RedkaleClassLoader classLoader,
|
||||
final String name,
|
||||
final Class<T> serviceTypeOrImplClass,
|
||||
final AsmMethodBoost methodBoost,
|
||||
@@ -938,7 +938,6 @@ public abstract class Sncp {
|
||||
final String sncpInfoDesc = Type.getDescriptor(SncpRemoteInfo.class);
|
||||
final String sncpDynDesc = Type.getDescriptor(SncpDyn.class);
|
||||
final String anyValueDesc = Type.getDescriptor(AnyValue.class);
|
||||
final RedkaleClassLoader dynLoader = RedkaleClassLoader.getRedkaleClassLoader(classLoader);
|
||||
String newDynName = "org/redkaledyn/service/remote/_DynRemoteService__"
|
||||
+ serviceTypeOrImplClass.getName().replace('.', '_').replace('$', '_');
|
||||
if (!name.isEmpty()) {
|
||||
@@ -955,8 +954,8 @@ public abstract class Sncp {
|
||||
}
|
||||
try {
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynClass);
|
||||
Class newClazz = clz == null ? dynLoader.loadClass(newDynClass) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynClass);
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynClass) : clz;
|
||||
T service = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||
{
|
||||
Field c = newClazz.getDeclaredField(FIELDPREFIX + "_conf");
|
||||
@@ -975,7 +974,7 @@ public abstract class Sncp {
|
||||
}
|
||||
if (methodBoost != null) {
|
||||
// 必须用servcie的ClassLoader, 因为service是动态ClassLoader会与doMethod里的动态ClassLoader不一致
|
||||
methodBoost.doInstance(dynLoader, resourceFactory, service);
|
||||
methodBoost.doInstance(classLoader, resourceFactory, service);
|
||||
}
|
||||
return service;
|
||||
} catch (Throwable ex) {
|
||||
@@ -1087,7 +1086,7 @@ public abstract class Sncp {
|
||||
if (methodBoost != null) {
|
||||
List<Class<? extends Annotation>> filterAnns = methodBoost.filterMethodAnnotations(method);
|
||||
newMethod = methodBoost.doMethod(
|
||||
dynLoader, cw, serviceTypeOrImplClass, newDynName, FIELDPREFIX, filterAnns, method, null);
|
||||
classLoader, cw, serviceTypeOrImplClass, newDynName, FIELDPREFIX, filterAnns, method, null);
|
||||
}
|
||||
if (newMethod != null) {
|
||||
acc = newMethod.getMethodAccs();
|
||||
@@ -1214,8 +1213,8 @@ public abstract class Sncp {
|
||||
mv.visitEnd();
|
||||
}
|
||||
if (methodBoost != null) {
|
||||
createNewMethods(dynLoader, serviceTypeOrImplClass, methodBoost, methodKeys, cw, newDynName, supDynName);
|
||||
methodBoost.doAfterMethods(dynLoader, cw, newDynName, FIELDPREFIX);
|
||||
createNewMethods(classLoader, serviceTypeOrImplClass, methodBoost, methodKeys, cw, newDynName, supDynName);
|
||||
methodBoost.doAfterMethods(classLoader, cw, newDynName, FIELDPREFIX);
|
||||
}
|
||||
{ // 构造函数
|
||||
mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
|
||||
@@ -1228,7 +1227,7 @@ public abstract class Sncp {
|
||||
"()V",
|
||||
false);
|
||||
if (methodBoost != null) {
|
||||
methodBoost.doConstructorMethod(dynLoader, cw, mv, newDynName, FIELDPREFIX, true);
|
||||
methodBoost.doConstructorMethod(classLoader, cw, mv, newDynName, FIELDPREFIX, true);
|
||||
}
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
@@ -1237,8 +1236,8 @@ public abstract class Sncp {
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
final String newDynClass = newDynName.replace('/', '.');
|
||||
Class<?> newClazz = dynLoader.loadClass(newDynClass, bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynClass, bytes);
|
||||
classLoader.putDynClass(newDynClass, bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynClass);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynClass);
|
||||
try {
|
||||
@@ -1263,7 +1262,7 @@ public abstract class Sncp {
|
||||
}
|
||||
if (methodBoost != null) {
|
||||
// 必须用servcie的ClassLoader, 因为service是动态ClassLoader会与doMethod里的动态ClassLoader不一致
|
||||
methodBoost.doInstance(dynLoader, resourceFactory, service);
|
||||
methodBoost.doInstance(classLoader, resourceFactory, service);
|
||||
}
|
||||
return service;
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -356,11 +356,11 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
final boolean boolReturnTypeFuture = Future.class.isAssignableFrom(method.getReturnType());
|
||||
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionServlet__"
|
||||
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
Class<?> newClazz = null;
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -371,8 +371,7 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
TypeToken.getGenericType(method.getGenericReturnType(), serviceClass);
|
||||
|
||||
final Class[] paramClasses = method.getParameterTypes();
|
||||
java.lang.reflect.Type paramComposeBeanType0 = SncpRemoteAction.createParamComposeBeanType(
|
||||
loader, serviceImplClass, method, actionid, originalParamTypes, paramClasses);
|
||||
java.lang.reflect.Type paramComposeBeanType0 = SncpRemoteAction.createParamComposeBeanType(classLoader, serviceImplClass, method, actionid, originalParamTypes, paramClasses);
|
||||
if (paramComposeBeanType0 != null && paramComposeBeanType0 == originalParamTypes[0]) {
|
||||
paramComposeBeanType0 = null;
|
||||
}
|
||||
@@ -712,8 +711,8 @@ public abstract class SncpActionServlet extends SncpServlet {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
|
||||
try {
|
||||
|
||||
@@ -54,10 +54,10 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
final String realHandlerDesc = Type.getDescriptor(CompletionHandler.class);
|
||||
final String newDynName = "org/redkaledyn/sncp/handler/_Dyn" + sncpHandlerClass.getSimpleName()
|
||||
+ "__" + handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newHandlerClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz);
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
@@ -206,8 +206,8 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
}
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
return (Creator<SncpAsyncHandler>) Creator.create(newClazz);
|
||||
})
|
||||
.create(factHandler);
|
||||
|
||||
@@ -249,7 +249,7 @@ public final class SncpRemoteAction {
|
||||
}
|
||||
|
||||
public static Type createParamComposeBeanType(
|
||||
RedkaleClassLoader loader,
|
||||
RedkaleClassLoader classLoader,
|
||||
Class resourceType,
|
||||
Method method,
|
||||
Uint128 actionid,
|
||||
@@ -273,8 +273,8 @@ public final class SncpRemoteAction {
|
||||
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionParamBean_"
|
||||
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class<?> newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class<?> newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
return newClazz;
|
||||
} catch (Throwable ex) {
|
||||
// do nothing
|
||||
@@ -327,8 +327,8 @@ public final class SncpRemoteAction {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
Creator.load(newClazz, 1); // 只一个Object[]参数
|
||||
ProtobufFactory.root().loadDecoder(newClazz);
|
||||
|
||||
@@ -80,12 +80,12 @@ public abstract class EntityFullFunc<T> {
|
||||
final String objectDesc = Type.getDescriptor(Object.class);
|
||||
final String serisDesc = Type.getDescriptor(Serializable[].class);
|
||||
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/source/_Dyn" + EntityFullFunc.class.getSimpleName() + "__"
|
||||
+ entityType.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (EntityFullFunc) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (EntityFullFunc) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getConstructor(Class.class, Creator.class, Attribute[].class)
|
||||
.newInstance(entityType, creator, attrs);
|
||||
} catch (Throwable ex) {
|
||||
@@ -793,8 +793,8 @@ public abstract class EntityFullFunc<T> {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<EntityFullFunc> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<EntityFullFunc> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return newClazz.getConstructor(Class.class, Creator.class, Attribute[].class)
|
||||
|
||||
@@ -60,14 +60,14 @@ public final class DataSqlMapperBuilder {
|
||||
if (!mapperType.isInterface()) {
|
||||
throw new SourceException(mapperType + " is not interface");
|
||||
}
|
||||
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final Class entityType = entityType(mapperType);
|
||||
final String supDynName = mapperType.getName().replace('.', '/');
|
||||
final String newDynName = "org/redkaledyn/source/mapper/_DynDataSqlMapper_"
|
||||
+ mapperType.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
M mapper = (M) newClazz.getDeclaredConstructor().newInstance();
|
||||
{ // DataSqlSource
|
||||
Field c = newClazz.getDeclaredField("_source");
|
||||
@@ -363,8 +363,8 @@ public final class DataSqlMapperBuilder {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
|
||||
@@ -1002,9 +1002,9 @@ public interface Attribute<T, F> {
|
||||
final String interDesc = Type.getDescriptor(TypeToken.typeToClass(subclass));
|
||||
final String columnDesc = Type.getDescriptor(column);
|
||||
Class realclz = TypeToken.typeToClass(subclass);
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
try {
|
||||
loader.loadClass(realclz.getName());
|
||||
classLoader.loadClass(realclz.getName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -1021,8 +1021,8 @@ public interface Attribute<T, F> {
|
||||
final String newDynName = "org/redkaledyn/attribute/" + pkgname + "_Dyn" + Attribute.class.getSimpleName()
|
||||
+ "__" + clzname + "__" + fieldkey.substring(fieldkey.indexOf('.') + 1);
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Attribute rs = (Attribute) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Attribute rs = (Attribute) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
java.lang.reflect.Field _gtype = rs.getClass().getDeclaredField("_gtype");
|
||||
@@ -1233,8 +1233,8 @@ public interface Attribute<T, F> {
|
||||
cw.visitEnd();
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<Attribute> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<Attribute> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
Attribute rs = newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -679,7 +679,7 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
final String srcClassName = srcClass.getName().replace('.', '/');
|
||||
final String destDesc = Type.getDescriptor(destClass);
|
||||
final String srcDesc = Type.getDescriptor(srcClass);
|
||||
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String utilClassName = Utility.class.getName().replace('.', '/');
|
||||
final String newDynName = "org/redkaledyn/copier/_Dyn" + Copier.class.getSimpleName() + "_" + options
|
||||
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_')
|
||||
@@ -688,8 +688,8 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
: ("__" + destClass.getName().replace('.', '_').replace('$', '_')))
|
||||
+ (extendInfo.length() == 0 ? "" : Utility.md5Hex(extendInfo.toString()));
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Copier) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Copier) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -1337,8 +1337,8 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
||||
cw.visitEnd();
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return (Copier) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -292,13 +292,12 @@ public interface Creator<T> {
|
||||
final String supDynName = Creator.class.getName().replace('.', '/');
|
||||
final String interName = clazz.getName().replace('.', '/');
|
||||
final String interDesc = Type.getDescriptor(clazz);
|
||||
RedkaleClassLoader loader =
|
||||
RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/creator/_Dyn" + Creator.class.getSimpleName() + "__"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + (paramCount < 0 ? "" : ("_" + paramCount));
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Creator) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Creator) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -569,8 +568,8 @@ public interface Creator<T> {
|
||||
|
||||
byte[] bytes = cw.toByteArray();
|
||||
try {
|
||||
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
return (Creator) newClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
*/
|
||||
package org.redkale.util;
|
||||
|
||||
import static org.redkale.util.Utility.hexToBin;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Function;
|
||||
import static org.redkale.util.Utility.hexToBin;
|
||||
|
||||
/**
|
||||
* Flow简单的操作
|
||||
@@ -134,7 +133,8 @@ public abstract class Flows {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass("org.redkale.util.AnonymousMonoFutureFunction", classBytes);
|
||||
RedkaleClassLoader.putDynClass(monoFuncClass.getName(), classBytes, monoFuncClass);
|
||||
RedkaleClassLoader.getRedkaleClassLoader()
|
||||
.putDynClass(monoFuncClass.getName(), classBytes, monoFuncClass);
|
||||
}
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(monoFuncClass, monoFuncClass.getName());
|
||||
reactorMonoFunction0 = (Function<Object, CompletableFuture>)
|
||||
@@ -158,7 +158,8 @@ public abstract class Flows {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass("org.redkale.util.AnonymousFluxFutureFunction", classBytes);
|
||||
RedkaleClassLoader.putDynClass(fluxFuncClass.getName(), classBytes, fluxFuncClass);
|
||||
RedkaleClassLoader.getRedkaleClassLoader()
|
||||
.putDynClass(fluxFuncClass.getName(), classBytes, fluxFuncClass);
|
||||
}
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(fluxFuncClass, fluxFuncClass.getName());
|
||||
reactorFluxFunction0 = (Function<Object, CompletableFuture>)
|
||||
|
||||
@@ -231,12 +231,12 @@ class Inners {
|
||||
}
|
||||
final String interName = clazz.getName().replace('.', '/');
|
||||
final String interDesc = org.redkale.asm.Type.getDescriptor(clazz);
|
||||
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/creator/_DynArrayFunction__"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (IntFunction) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (IntFunction) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -283,8 +283,8 @@ class Inners {
|
||||
cw.visitEnd();
|
||||
final byte[] bytes = cw.toByteArray();
|
||||
try {
|
||||
Class<?> resultClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
Class<?> resultClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||
return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Throwable ex) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public interface Invoker<C, R> {
|
||||
} else if (returnType == void.class) {
|
||||
returnDesc = Type.getDescriptor(Void.class);
|
||||
}
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
StringBuilder sbpts = new StringBuilder();
|
||||
for (Class c : method.getParameterTypes()) {
|
||||
sbpts.append('_').append(c.getName().replace('.', '_').replace('$', '_'));
|
||||
@@ -99,8 +99,8 @@ public interface Invoker<C, R> {
|
||||
final String newDynName = "org/redkaledyn/invoker/_Dyn" + Invoker.class.getSimpleName() + "_"
|
||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + method.getName() + sbpts;
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Invoker<C, T>) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Invoker<C, T>) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -208,9 +208,9 @@ public interface Invoker<C, R> {
|
||||
Class<?> resultClazz = null;
|
||||
try {
|
||||
if (resultClazz == null) {
|
||||
resultClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
resultClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
}
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||
return (Invoker<C, T>) resultClazz.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -66,10 +66,14 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
"org.redkale.watch"
|
||||
};
|
||||
|
||||
// redkale里所有使用动态字节码生成的类都需要存于此处
|
||||
private static final ConcurrentHashMap<String, byte[]> dynClassBytesMap = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, byte[]> dynClassBytesMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ConcurrentHashMap<String, Class> dynClassTypeMap = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, Class> dynClassTypeMap = new ConcurrentHashMap<>();
|
||||
|
||||
// redkale里所有使用动态字节码生成的类都需要存于此处
|
||||
private static final ConcurrentHashMap<String, byte[]> allDynClassBytesMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ConcurrentHashMap<String, Class> allDynClassTypeMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static final CopyOnWriteArraySet<String> resourcePathSet = new CopyOnWriteArraySet<>();
|
||||
|
||||
@@ -171,20 +175,30 @@ public class RedkaleClassLoader extends URLClassLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] putDynClass(String name, byte[] bs, Class clazz) {
|
||||
static void putDynClass0(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public void putDynClass(String name, byte[] bs, Class clazz) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(bs);
|
||||
Objects.requireNonNull(clazz);
|
||||
dynClassTypeMap.put(name, clazz);
|
||||
return dynClassBytesMap.put(name, bs);
|
||||
dynClassBytesMap.put(name, bs);
|
||||
allDynClassTypeMap.put(name, clazz);
|
||||
allDynClassBytesMap.put(name, bs);
|
||||
}
|
||||
|
||||
public static Class findDynClass(String name) {
|
||||
public Class findDynClass(String name) {
|
||||
return dynClassTypeMap.get(name);
|
||||
}
|
||||
|
||||
public static void forEachDynClass(BiConsumer<String, byte[]> action) {
|
||||
dynClassBytesMap.forEach(action);
|
||||
allDynClassBytesMap.forEach(action);
|
||||
}
|
||||
|
||||
public static void putReflectionClass(String className) {
|
||||
|
||||
@@ -67,13 +67,13 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
||||
final String srcClassName = srcClass.getName().replace('.', '/');
|
||||
final String destDesc = Type.getDescriptor(destClass);
|
||||
final String srcDesc = Type.getDescriptor(srcClass);
|
||||
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
final String newDynName = "org/redkaledyn/reproduce/_Dyn" + Reproduce.class.getSimpleName()
|
||||
+ "__" + destClass.getName().replace('.', '_').replace('$', '_')
|
||||
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_');
|
||||
try {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Reproduce) (clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
Class clz = classLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
return (Reproduce) (clz == null ? classLoader.loadClass(newDynName.replace('/', '.')) : clz)
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
} catch (Throwable ex) {
|
||||
@@ -231,8 +231,8 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
||||
cw.visitEnd();
|
||||
// ------------------------------------------------------------------------------
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||
try {
|
||||
return (Reproduce) newClazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -662,7 +662,7 @@ public abstract class TypeToken<T> {
|
||||
|
||||
// 注意: RetResult<Map<String, Long>[]> 这种泛型带[]的尚未实现支持
|
||||
private static Type createParameterizedType0(final Class rawType, final Type... actualTypeArguments) {
|
||||
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||
StringBuilder tmpps = new StringBuilder(getClassTypeDescriptor(rawType));
|
||||
for (Type cz : actualTypeArguments) {
|
||||
tmpps.append(" ").append(getClassTypeDescriptor(cz));
|
||||
@@ -683,7 +683,7 @@ public abstract class TypeToken<T> {
|
||||
final String newDynName =
|
||||
"org/redkaledyn/typetoken/_Dyn" + TypeToken.class.getSimpleName() + "_" + nsb.toString();
|
||||
try {
|
||||
return loader.loadClass(newDynName.replace('/', '.'))
|
||||
return classLoader.loadClass(newDynName.replace('/', '.'))
|
||||
.getField("field")
|
||||
.getGenericType();
|
||||
} catch (Throwable ex) {
|
||||
@@ -715,8 +715,8 @@ public abstract class TypeToken<T> {
|
||||
}
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
Class<?> newClazz = classLoader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
classLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||
RedkaleClassLoader.putReflectionPublicFields(newDynName.replace('/', '.'));
|
||||
try {
|
||||
return newClazz.getField("field").getGenericType();
|
||||
|
||||
@@ -97,7 +97,7 @@ public final class Utility {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass(unsafeName, classBytes);
|
||||
RedkaleClassLoader.putDynClass(unsafeClazz1.getName(), classBytes, unsafeClazz1);
|
||||
RedkaleClassLoader.putDynClass0(unsafeClazz1.getName(), classBytes, unsafeClazz1);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(unsafeClazz1, unsafeClazz1.getName());
|
||||
}
|
||||
unsafe0 = unsafeClazz1.getDeclaredConstructor().newInstance();
|
||||
@@ -245,7 +245,7 @@ public final class Utility {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass("org.redkale.util.SignalShutDown", classBytes);
|
||||
RedkaleClassLoader.putDynClass(shutdownClazz1.getName(), classBytes, shutdownClazz1);
|
||||
RedkaleClassLoader.putDynClass0(shutdownClazz1.getName(), classBytes, shutdownClazz1);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(shutdownClazz1, shutdownClazz1.getName());
|
||||
}
|
||||
signalShutdownConsumer0 = shutdownClazz1.getDeclaredConstructor().newInstance();
|
||||
@@ -2226,12 +2226,11 @@ public final class Utility {
|
||||
/**
|
||||
* 将一个或多个新元素添加到数组结尾
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param array 原数组
|
||||
* @param objs 待追加数据
|
||||
* @return 新数组
|
||||
*/
|
||||
public static <T> Object[][] append(final Object[][] array, final Object[]... objs) {
|
||||
public static Object[][] append(final Object[][] array, final Object[]... objs) {
|
||||
if (array == null || array.length == 0) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
@@ -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