调整生成动态字节码时的ClassLoader
This commit is contained in:
@@ -29,7 +29,7 @@ import static org.redkale.asm.Opcodes.LLOAD;
|
|||||||
import static org.redkale.asm.Opcodes.LRETURN;
|
import static org.redkale.asm.Opcodes.LRETURN;
|
||||||
import static org.redkale.asm.Opcodes.RETURN;
|
import static org.redkale.asm.Opcodes.RETURN;
|
||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,7 +101,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
* @return 下一个新的方法名,不做任何处理应返回参数newMethodName
|
* @return 下一个新的方法名,不做任何处理应返回参数newMethodName
|
||||||
*/
|
*/
|
||||||
public abstract AsmNewMethod doMethod(
|
public abstract AsmNewMethod doMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
Class serviceImplClass,
|
Class serviceImplClass,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -119,7 +119,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
* @param fieldPrefix 动态字段的前缀
|
* @param fieldPrefix 动态字段的前缀
|
||||||
*/
|
*/
|
||||||
public void doAfterMethods(
|
public void doAfterMethods(
|
||||||
DynBytesClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {}
|
RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理所有动态方法后调用
|
* 处理所有动态方法后调用
|
||||||
@@ -132,7 +132,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
* @param remote 是否远程模式
|
* @param remote 是否远程模式
|
||||||
*/
|
*/
|
||||||
public void doConstructorMethod(
|
public void doConstructorMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
MethodVisitor mv,
|
MethodVisitor mv,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -145,7 +145,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
* @param resourceFactory ResourceFactory
|
* @param resourceFactory ResourceFactory
|
||||||
* @param service 实例对象
|
* @param service 实例对象
|
||||||
*/
|
*/
|
||||||
public abstract void doInstance(DynBytesClassLoader classLoader, ResourceFactory resourceFactory, T service);
|
public abstract void doInstance(RedkaleClassLoader classLoader, ResourceFactory resourceFactory, T service);
|
||||||
|
|
||||||
protected AsmMethodBean getMethodBean(Method method) {
|
protected AsmMethodBean getMethodBean(Method method) {
|
||||||
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(serviceType);
|
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(serviceType);
|
||||||
@@ -325,7 +325,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsmNewMethod doMethod(
|
public AsmNewMethod doMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
Class serviceImplClass,
|
Class serviceImplClass,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -345,7 +345,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAfterMethods(
|
public void doAfterMethods(
|
||||||
DynBytesClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
||||||
for (AsmMethodBoost item : items) {
|
for (AsmMethodBoost item : items) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.doAfterMethods(classLoader, cw, newDynName, fieldPrefix);
|
item.doAfterMethods(classLoader, cw, newDynName, fieldPrefix);
|
||||||
@@ -355,7 +355,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doConstructorMethod(
|
public void doConstructorMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
MethodVisitor mv,
|
MethodVisitor mv,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -369,7 +369,7 @@ public abstract class AsmMethodBoost<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doInstance(DynBytesClassLoader classLoader, ResourceFactory resourceFactory, T service) {
|
public void doInstance(RedkaleClassLoader classLoader, ResourceFactory resourceFactory, T service) {
|
||||||
for (AsmMethodBoost item : items) {
|
for (AsmMethodBoost item : items) {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
item.doInstance(classLoader, resourceFactory, service);
|
item.doInstance(classLoader, resourceFactory, service);
|
||||||
|
|||||||
@@ -143,7 +143,8 @@ class AppConfig {
|
|||||||
if (cacheClasses == null) {
|
if (cacheClasses == null) {
|
||||||
this.classLoader = new RedkaleClassLoader(currClassLoader);
|
this.classLoader = new RedkaleClassLoader(currClassLoader);
|
||||||
} else {
|
} else {
|
||||||
this.classLoader = new RedkaleClassLoader.RedkaleCacheClassLoader(currClassLoader, cacheClasses);
|
this.classLoader = new RedkaleClassLoader.RedkaleCacheClassLoader(
|
||||||
|
RedkaleClassLoader.getRedkaleClassLoader(currClassLoader), cacheClasses);
|
||||||
}
|
}
|
||||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public abstract class NodeServer {
|
|||||||
|| application.getServerClassLoader() instanceof RedkaleClassLoader.RedkaleCacheClassLoader) {
|
|| application.getServerClassLoader() instanceof RedkaleClassLoader.RedkaleCacheClassLoader) {
|
||||||
this.serverClassLoader = application.getServerClassLoader();
|
this.serverClassLoader = application.getServerClassLoader();
|
||||||
} else {
|
} else {
|
||||||
this.serverClassLoader = new RedkaleClassLoader(application.getServerClassLoader());
|
this.serverClassLoader = RedkaleClassLoader.getRedkaleClassLoader(application.getServerClassLoader());
|
||||||
}
|
}
|
||||||
Thread.currentThread().setContextClassLoader(this.serverClassLoader);
|
Thread.currentThread().setContextClassLoader(this.serverClassLoader);
|
||||||
this.serverThread = Thread.currentThread();
|
this.serverThread = Thread.currentThread();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.redkale.cached.Cached;
|
|||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.service.LoadMode;
|
import org.redkale.service.LoadMode;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.ThrowSupplier;
|
import org.redkale.util.ThrowSupplier;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
@@ -63,7 +62,7 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsmNewMethod doMethod(
|
public AsmNewMethod doMethod(
|
||||||
final DynBytesClassLoader classLoader,
|
final RedkaleClassLoader classLoader,
|
||||||
final ClassWriter cw,
|
final ClassWriter cw,
|
||||||
final Class serviceImplClass,
|
final Class serviceImplClass,
|
||||||
final String newDynName,
|
final String newDynName,
|
||||||
@@ -216,7 +215,7 @@ public class CachedAsmMethodBoost extends AsmMethodBoost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doInstance(DynBytesClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
public void doInstance(RedkaleClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
||||||
Class clazz = service.getClass();
|
Class clazz = service.getClass();
|
||||||
if (actionMap == null) { // 为null表示没有调用过doMethod, 动态类在编译是已经生成好了
|
if (actionMap == null) { // 为null表示没有调用过doMethod, 动态类在编译是已经生成好了
|
||||||
actionMap = new LinkedHashMap<>();
|
actionMap = new LinkedHashMap<>();
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ public final class DeMember<R extends Reader, T, F> {
|
|||||||
return new DeMember<>(attribute, factory.loadDecoder(fieldType), null, null);
|
return new DeMember<>(attribute, factory.loadDecoder(fieldType), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPositionToIndex() {
|
||||||
|
this.index = this.position;
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean accepts(String name) {
|
public final boolean accepts(String name) {
|
||||||
return attribute.field().equals(name);
|
return attribute.field().equals(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,10 @@ public final class EnMember<W extends Writer, T, F> {
|
|||||||
return new EnMember<>(attribute, factory.loadEncoder(fieldtype), null, null, null);
|
return new EnMember<>(attribute, factory.loadEncoder(fieldtype), null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPositionToIndex() {
|
||||||
|
this.index = this.position;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getFieldValue(T obj) {
|
public Object getFieldValue(T obj) {
|
||||||
F val = attribute.get(obj);
|
F val = attribute.get(obj);
|
||||||
if (fieldFunc != null) {
|
if (fieldFunc != null) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.redkale.convert.ext;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,33 +40,4 @@ public class BigDecimalSimpledCoder<R extends Reader, W extends Writer> extends
|
|||||||
return new BigDecimal(Utility.charArray(value));
|
return new BigDecimal(Utility.charArray(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* BigDecimal 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static class BigDecimalJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, BigDecimal> {
|
|
||||||
|
|
||||||
public static final BigDecimalJsonSimpledCoder instance = new BigDecimalJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final BigDecimal value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigDecimal convertFrom(R in) {
|
|
||||||
final String str = in.readString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new BigDecimal(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.redkale.convert.ext;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BigInteger 的SimpledCoder实现
|
* BigInteger 的SimpledCoder实现
|
||||||
@@ -50,74 +49,4 @@ public class BigIntegerSimpledCoder<R extends Reader, W extends Writer> extends
|
|||||||
return bytes == null ? null : new BigInteger(bytes);
|
return bytes == null ? null : new BigInteger(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* BigInteger 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static class BigIntegerJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, BigInteger> {
|
|
||||||
|
|
||||||
public static final BigIntegerJsonSimpledCoder instance = new BigIntegerJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final BigInteger value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigInteger convertFrom(R in) {
|
|
||||||
final String str = in.readString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new BigInteger(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BigInteger 的十六进制JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static class BigIntegerHexJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, BigInteger> {
|
|
||||||
|
|
||||||
public static final BigIntegerHexJsonSimpledCoder instance = new BigIntegerHexJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final BigInteger value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
String s = value.toString(16);
|
|
||||||
out.writeStandardString(s.charAt(0) == '-' ? ("-0x" + s.substring(1)) : ("0x" + s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigInteger convertFrom(R in) {
|
|
||||||
final String str = in.readString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (str.length() > 2) {
|
|
||||||
if (str.charAt(0) == '0' && (str.charAt(1) == 'x' || str.charAt(1) == 'X')) {
|
|
||||||
return new BigInteger(str.substring(2), 16);
|
|
||||||
} else if (str.charAt(0) == '-'
|
|
||||||
&& str.length() > 3
|
|
||||||
&& str.charAt(1) == '0'
|
|
||||||
&& (str.charAt(2) == 'x' || str.charAt(2) == 'X')) {
|
|
||||||
return new BigInteger("-" + str.substring(3), 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new BigInteger(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import java.net.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
import org.redkale.util.StringWrapper;
|
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,69 +106,4 @@ public class InetAddressSimpledCoder<R extends Reader, W extends Writer> extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* InetAddress 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static final class InetAddressJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, InetAddress> {
|
|
||||||
|
|
||||||
public static final InetAddressJsonSimpledCoder instance = new InetAddressJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(W out, InetAddress value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
out.writeWrapper(new StringWrapper(value.getHostAddress()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InetAddress convertFrom(R in) {
|
|
||||||
String str = in.readString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return InetAddress.getByName(str);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* InetSocketAddress 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static final class InetSocketAddressJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, InetSocketAddress> {
|
|
||||||
|
|
||||||
public static final InetSocketAddressJsonSimpledCoder instance = new InetSocketAddressJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(W out, InetSocketAddress value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
StringSimpledCoder.instance.convertTo(out, value.getHostString() + ":" + value.getPort());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InetSocketAddress convertFrom(R in) {
|
|
||||||
String str = in.readStringValue();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int pos = str.indexOf(':');
|
|
||||||
return new InetSocketAddress(str.substring(0, pos), Integer.parseInt(str.substring(pos + 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.redkale.convert.ext;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java.time.Instant 的SimpledCoder实现
|
* java.time.Instant 的SimpledCoder实现
|
||||||
@@ -33,27 +32,4 @@ public class InstantSimpledCoder<R extends Reader, W extends Writer> extends Sim
|
|||||||
return t == -1 ? null : Instant.ofEpochMilli(t);
|
return t == -1 ? null : Instant.ofEpochMilli(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class InstantJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, Instant> {
|
|
||||||
|
|
||||||
public static final InstantJsonSimpledCoder instance = new InstantJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final Instant value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Instant convertFrom(R in) {
|
|
||||||
final String str = in.readStandardString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Instant.parse(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.redkale.convert.ext;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java.time.LocalDate 的SimpledCoder实现
|
* java.time.LocalDate 的SimpledCoder实现
|
||||||
@@ -34,33 +33,4 @@ public class LocalDateSimpledCoder<R extends Reader, W extends Writer> extends S
|
|||||||
return t == 0 ? null : LocalDate.of(t / 100_00, t % 100_00 / 100, t % 100);
|
return t == 0 ? null : LocalDate.of(t / 100_00, t % 100_00 / 100, t % 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* java.time.LocalDate 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static final class LocalDateJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, LocalDate> {
|
|
||||||
|
|
||||||
public static final LocalDateJsonSimpledCoder instance = new LocalDateJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final LocalDate value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDate convertFrom(R in) {
|
|
||||||
final String str = in.readStandardString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return LocalDate.parse(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.redkale.convert.ext;
|
|||||||
import java.time.*;
|
import java.time.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java.time.LocalDateTime 的SimpledCoder实现
|
* java.time.LocalDateTime 的SimpledCoder实现
|
||||||
@@ -76,33 +75,4 @@ public class LocalDateTimeSimpledCoder<R extends Reader, W extends Writer> exten
|
|||||||
return LocalDateTime.ofEpochSecond(v1, v2, ZoneOffset.UTC);
|
return LocalDateTime.ofEpochSecond(v1, v2, ZoneOffset.UTC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* java.time.LocalDateTime 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static final class LocalDateTimeJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, LocalDateTime> {
|
|
||||||
|
|
||||||
public static final LocalDateTimeJsonSimpledCoder instance = new LocalDateTimeJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final LocalDateTime value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime convertFrom(R in) {
|
|
||||||
final String str = in.readStandardString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return LocalDateTime.parse(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.redkale.convert.ext;
|
|||||||
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java.time.LocalTime 的SimpledCoder实现
|
* java.time.LocalTime 的SimpledCoder实现
|
||||||
@@ -33,33 +32,4 @@ public class LocalTimeSimpledCoder<R extends Reader, W extends Writer> extends S
|
|||||||
return t == -1 ? null : LocalTime.ofNanoOfDay(t);
|
return t == -1 ? null : LocalTime.ofNanoOfDay(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* java.time.LocalTime 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static final class LocalTimeJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, LocalTime> {
|
|
||||||
|
|
||||||
public static final LocalTimeJsonSimpledCoder instance = new LocalTimeJsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final LocalTime value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalTime convertFrom(R in) {
|
|
||||||
final String str = in.readStandardString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return LocalTime.parse(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.redkale.convert.ext;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,33 +52,4 @@ public class Uint128SimpledCoder<R extends Reader, W extends Writer> extends Sim
|
|||||||
return Uint128.create(bs);
|
return Uint128.create(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Uint128 的JsonSimpledCoder实现
|
|
||||||
*
|
|
||||||
* @param <R> Reader输入的子类型
|
|
||||||
* @param <W> Writer输出的子类型
|
|
||||||
*/
|
|
||||||
public static class Uint128JsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
|
||||||
extends SimpledCoder<R, W, Uint128> {
|
|
||||||
|
|
||||||
public static final Uint128JsonSimpledCoder instance = new Uint128JsonSimpledCoder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void convertTo(final W out, final Uint128 value) {
|
|
||||||
if (value == null) {
|
|
||||||
out.writeNull();
|
|
||||||
} else {
|
|
||||||
out.writeStandardString(value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Uint128 convertFrom(R in) {
|
|
||||||
final String str = in.readStandardString();
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Uint128.create(Utility.hexToBin(str));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
339
src/main/java/org/redkale/convert/json/JsonCoders.java
Normal file
339
src/main/java/org/redkale/convert/json/JsonCoders.java
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2116 Redkale
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
package org.redkale.convert.json;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import org.redkale.convert.SimpledCoder;
|
||||||
|
import org.redkale.convert.ext.StringSimpledCoder;
|
||||||
|
import org.redkale.util.StringWrapper;
|
||||||
|
import org.redkale.util.Uint128;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
public abstract class JsonCoders {
|
||||||
|
|
||||||
|
private JsonCoders() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InetAddress 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static final class InetAddressJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, InetAddress> {
|
||||||
|
|
||||||
|
public static final InetAddressJsonSimpledCoder instance = new InetAddressJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(W out, InetAddress value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out.writeWrapper(new StringWrapper(value.getHostAddress()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InetAddress convertFrom(R in) {
|
||||||
|
String str = in.readString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return InetAddress.getByName(str);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InetSocketAddress 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static final class InetSocketAddressJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, InetSocketAddress> {
|
||||||
|
|
||||||
|
public static final InetSocketAddressJsonSimpledCoder instance = new InetSocketAddressJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(W out, InetSocketAddress value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringSimpledCoder.instance.convertTo(out, value.getHostString() + ":" + value.getPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InetSocketAddress convertFrom(R in) {
|
||||||
|
String str = in.readStringValue();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int pos = str.indexOf(':');
|
||||||
|
return new InetSocketAddress(str.substring(0, pos), Integer.parseInt(str.substring(pos + 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Uint128 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static class Uint128JsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, Uint128> {
|
||||||
|
|
||||||
|
public static final Uint128JsonSimpledCoder instance = new Uint128JsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final Uint128 value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uint128 convertFrom(R in) {
|
||||||
|
final String str = in.readStandardString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Uint128.create(Utility.hexToBin(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BigInteger 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static class BigIntegerJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, BigInteger> {
|
||||||
|
|
||||||
|
public static final BigIntegerJsonSimpledCoder instance = new BigIntegerJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final BigInteger value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigInteger convertFrom(R in) {
|
||||||
|
final String str = in.readString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new BigInteger(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BigInteger 的十六进制JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static class BigIntegerHexJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, BigInteger> {
|
||||||
|
|
||||||
|
public static final BigIntegerHexJsonSimpledCoder instance = new BigIntegerHexJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final BigInteger value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
String s = value.toString(16);
|
||||||
|
out.writeStandardString(s.charAt(0) == '-' ? ("-0x" + s.substring(1)) : ("0x" + s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigInteger convertFrom(R in) {
|
||||||
|
final String str = in.readString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (str.length() > 2) {
|
||||||
|
if (str.charAt(0) == '0' && (str.charAt(1) == 'x' || str.charAt(1) == 'X')) {
|
||||||
|
return new BigInteger(str.substring(2), 16);
|
||||||
|
} else if (str.charAt(0) == '-'
|
||||||
|
&& str.length() > 3
|
||||||
|
&& str.charAt(1) == '0'
|
||||||
|
&& (str.charAt(2) == 'x' || str.charAt(2) == 'X')) {
|
||||||
|
return new BigInteger("-" + str.substring(3), 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BigInteger(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BigDecimal 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static class BigDecimalJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, BigDecimal> {
|
||||||
|
|
||||||
|
public static final BigDecimalJsonSimpledCoder instance = new BigDecimalJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final BigDecimal value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigDecimal convertFrom(R in) {
|
||||||
|
final String str = in.readString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new BigDecimal(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class InstantJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, Instant> {
|
||||||
|
|
||||||
|
public static final InstantJsonSimpledCoder instance = new InstantJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final Instant value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instant convertFrom(R in) {
|
||||||
|
final String str = in.readStandardString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Instant.parse(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.time.LocalDate 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static final class LocalDateJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, LocalDate> {
|
||||||
|
|
||||||
|
public static final LocalDateJsonSimpledCoder instance = new LocalDateJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final LocalDate value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate convertFrom(R in) {
|
||||||
|
final String str = in.readStandardString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalDate.parse(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.time.LocalTime 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static final class LocalTimeJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, LocalTime> {
|
||||||
|
|
||||||
|
public static final LocalTimeJsonSimpledCoder instance = new LocalTimeJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final LocalTime value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalTime convertFrom(R in) {
|
||||||
|
final String str = in.readStandardString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalTime.parse(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.time.LocalDateTime 的JsonSimpledCoder实现
|
||||||
|
*
|
||||||
|
* @param <R> Reader输入的子类型
|
||||||
|
* @param <W> Writer输出的子类型
|
||||||
|
*/
|
||||||
|
public static final class LocalDateTimeJsonSimpledCoder<R extends JsonReader, W extends JsonWriter>
|
||||||
|
extends SimpledCoder<R, W, LocalDateTime> {
|
||||||
|
|
||||||
|
public static final LocalDateTimeJsonSimpledCoder instance = new LocalDateTimeJsonSimpledCoder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(final W out, final LocalDateTime value) {
|
||||||
|
if (value == null) {
|
||||||
|
out.writeNull();
|
||||||
|
} else {
|
||||||
|
out.writeStandardString(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDateTime convertFrom(R in) {
|
||||||
|
final String str = in.readStandardString();
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return LocalDateTime.parse(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,10 +66,7 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Map<String, AccessibleObject> mixedNames = mixedNames0;
|
final Map<String, AccessibleObject> mixedNames = mixedNames0;
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
if (String.class.getClassLoader() != clazz.getClassLoader()) {
|
|
||||||
loader = clazz.getClassLoader();
|
|
||||||
}
|
|
||||||
final String newDynName = "org/redkaledyn/convert/json/_Dyn" + JsonDynEncoder.class.getSimpleName() + "__"
|
final String newDynName = "org/redkaledyn/convert/json/_Dyn" + JsonDynEncoder.class.getSimpleName() + "__"
|
||||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||||
@@ -683,11 +680,7 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(loader) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(
|
RedkaleClassLoader.putReflectionDeclaredConstructors(
|
||||||
newClazz, newDynName.replace('/', '.'), JsonFactory.class, Type.class);
|
newClazz, newDynName.replace('/', '.'), JsonFactory.class, Type.class);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.lang.reflect.Type;
|
|||||||
import java.math.*;
|
import java.math.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.ext.*;
|
|
||||||
import org.redkale.util.Uint128;
|
import org.redkale.util.Uint128;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,16 +41,15 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
|||||||
private JsonFactory(JsonFactory parent, int features) {
|
private JsonFactory(JsonFactory parent, int features) {
|
||||||
super(parent, features);
|
super(parent, features);
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
this.register(InetAddress.class, InetAddressSimpledCoder.InetAddressJsonSimpledCoder.instance);
|
this.register(InetAddress.class, JsonCoders.InetAddressJsonSimpledCoder.instance);
|
||||||
this.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressJsonSimpledCoder.instance);
|
this.register(InetSocketAddress.class, JsonCoders.InetSocketAddressJsonSimpledCoder.instance);
|
||||||
this.register(Uint128.class, Uint128SimpledCoder.Uint128JsonSimpledCoder.instance);
|
this.register(Uint128.class, JsonCoders.Uint128JsonSimpledCoder.instance);
|
||||||
this.register(BigInteger.class, BigIntegerSimpledCoder.BigIntegerJsonSimpledCoder.instance);
|
this.register(BigInteger.class, JsonCoders.BigIntegerJsonSimpledCoder.instance);
|
||||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.BigDecimalJsonSimpledCoder.instance);
|
this.register(BigDecimal.class, JsonCoders.BigDecimalJsonSimpledCoder.instance);
|
||||||
this.register(java.time.Instant.class, InstantSimpledCoder.InstantJsonSimpledCoder.instance);
|
this.register(java.time.Instant.class, JsonCoders.InstantJsonSimpledCoder.instance);
|
||||||
this.register(java.time.LocalDate.class, LocalDateSimpledCoder.LocalDateJsonSimpledCoder.instance);
|
this.register(java.time.LocalDate.class, JsonCoders.LocalDateJsonSimpledCoder.instance);
|
||||||
this.register(java.time.LocalTime.class, LocalTimeSimpledCoder.LocalTimeJsonSimpledCoder.instance);
|
this.register(java.time.LocalTime.class, JsonCoders.LocalTimeJsonSimpledCoder.instance);
|
||||||
this.register(
|
this.register(java.time.LocalDateTime.class, JsonCoders.LocalDateTimeJsonSimpledCoder.instance);
|
||||||
java.time.LocalDateTime.class, LocalDateTimeSimpledCoder.LocalDateTimeJsonSimpledCoder.instance);
|
|
||||||
|
|
||||||
this.register(JsonElement.class, (Decodeable) JsonElementDecoder.instance);
|
this.register(JsonElement.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
this.register(JsonString.class, (Decodeable) JsonElementDecoder.instance);
|
this.register(JsonString.class, (Decodeable) JsonElementDecoder.instance);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
|||||||
|
|
||||||
protected static ProtobufDynEncoder generateDyncEncoder(final ProtobufFactory factory, final Class clazz) {
|
protected static ProtobufDynEncoder generateDyncEncoder(final ProtobufFactory factory, final Class clazz) {
|
||||||
final ObjectEncoder selfObjEncoder = factory.createObjectEncoder(clazz);
|
final ObjectEncoder selfObjEncoder = factory.createObjectEncoder(clazz);
|
||||||
|
factory.register(clazz, selfObjEncoder);
|
||||||
selfObjEncoder.init(factory); // 必须执行,初始化EnMember内部信息
|
selfObjEncoder.init(factory); // 必须执行,初始化EnMember内部信息
|
||||||
|
|
||||||
final Map<String, SimpledCoder> simpledCoders = new HashMap<>();
|
final Map<String, SimpledCoder> simpledCoders = new HashMap<>();
|
||||||
@@ -68,10 +69,7 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
if (String.class.getClassLoader() != clazz.getClassLoader()) {
|
|
||||||
loader = clazz.getClassLoader();
|
|
||||||
}
|
|
||||||
final String newDynName = "org/redkaledyn/convert/pb/_Dyn" + ProtobufDynEncoder.class.getSimpleName() + "__"
|
final String newDynName = "org/redkaledyn/convert/pb/_Dyn" + ProtobufDynEncoder.class.getSimpleName() + "__"
|
||||||
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
+ clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_"
|
||||||
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
+ Utility.md5Hex(elementb.toString()); // tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||||
@@ -323,12 +321,7 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<ProtobufDynEncoder> newClazz = (Class<ProtobufDynEncoder>)
|
Class<ProtobufDynEncoder> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
new ClassLoader(loader) {
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ import org.redkale.util.*;
|
|||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWriter> {
|
public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWriter> {
|
||||||
|
|
||||||
|
static final boolean INDEX_CHECK =
|
||||||
|
"true".equalsIgnoreCase(System.getProperty("redkale.convert.protobuf.indexcheck", "false"));
|
||||||
|
|
||||||
private static final ProtobufFactory instance = new ProtobufFactory(
|
private static final ProtobufFactory instance = new ProtobufFactory(
|
||||||
null,
|
null,
|
||||||
getSystemPropertyInt("redkale.convert.protobuf.tiny", "redkale.convert.tiny", true, Convert.FEATURE_TINY)
|
getSystemPropertyInt("redkale.convert.protobuf.tiny", "redkale.convert.tiny", true, Convert.FEATURE_TINY)
|
||||||
|
|||||||
@@ -37,8 +37,12 @@ public class ProtobufObjectDecoder<T> extends ObjectDecoder<ProtobufReader, T>
|
|||||||
@Override
|
@Override
|
||||||
protected void initForEachDeMember(ConvertFactory factory, DeMember member) {
|
protected void initForEachDeMember(ConvertFactory factory, DeMember member) {
|
||||||
if (member.getIndex() < 1) {
|
if (member.getIndex() < 1) {
|
||||||
throw new ConvertException(Utility.orElse(member.getField(), member.getMethod()) + " not found @"
|
if (ProtobufFactory.INDEX_CHECK) {
|
||||||
+ ConvertColumn.class.getSimpleName() + ".index");
|
throw new ConvertException(Utility.orElse(member.getField(), member.getMethod()) + " not found @"
|
||||||
|
+ ConvertColumn.class.getSimpleName() + ".index");
|
||||||
|
} else {
|
||||||
|
member.setPositionToIndex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Attribute attr = member.getAttribute();
|
Attribute attr = member.getAttribute();
|
||||||
boolean enumtostring = ((ProtobufFactory) factory).enumtostring;
|
boolean enumtostring = ((ProtobufFactory) factory).enumtostring;
|
||||||
|
|||||||
@@ -85,8 +85,12 @@ public class ProtobufObjectEncoder<T> extends ObjectEncoder<ProtobufWriter, T>
|
|||||||
@Override
|
@Override
|
||||||
protected void initForEachEnMember(ConvertFactory factory, EnMember member) {
|
protected void initForEachEnMember(ConvertFactory factory, EnMember member) {
|
||||||
if (member.getIndex() < 1) {
|
if (member.getIndex() < 1) {
|
||||||
throw new ConvertException(Utility.orElse(member.getField(), member.getMethod()) + " not found @"
|
if (ProtobufFactory.INDEX_CHECK) {
|
||||||
+ ConvertColumn.class.getSimpleName() + ".index");
|
throw new ConvertException(Utility.orElse(member.getField(), member.getMethod()) + " not found @"
|
||||||
|
+ ConvertColumn.class.getSimpleName() + ".index");
|
||||||
|
} else {
|
||||||
|
member.setPositionToIndex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Attribute attr = member.getAttribute();
|
Attribute attr = member.getAttribute();
|
||||||
boolean enumtostring = ((ProtobufFactory) factory).enumtostring;
|
boolean enumtostring = ((ProtobufFactory) factory).enumtostring;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.redkale.asm.Type;
|
|||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.locked.Locked;
|
import org.redkale.locked.Locked;
|
||||||
import org.redkale.service.LoadMode;
|
import org.redkale.service.LoadMode;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
|
|
||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
@@ -39,7 +39,7 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsmNewMethod doMethod(
|
public AsmNewMethod doMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
Class serviceImplClass,
|
Class serviceImplClass,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -91,12 +91,12 @@ public class LockedAsmMethodBoost extends AsmMethodBoost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAfterMethods(DynBytesClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
public void doAfterMethods(RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doInstance(DynBytesClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
public void doInstance(RedkaleClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import org.redkale.mq.ResourceConsumer;
|
|||||||
import org.redkale.mq.spi.DynForMessaged.DynForMessageds;
|
import org.redkale.mq.spi.DynForMessaged.DynForMessageds;
|
||||||
import org.redkale.service.LoadMode;
|
import org.redkale.service.LoadMode;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
@@ -83,7 +82,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsmNewMethod doMethod(
|
public AsmNewMethod doMethod(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
ClassWriter cw,
|
ClassWriter cw,
|
||||||
Class serviceImplClass,
|
Class serviceImplClass,
|
||||||
String newDynName,
|
String newDynName,
|
||||||
@@ -322,7 +321,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAfterMethods(DynBytesClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
public void doAfterMethods(RedkaleClassLoader classLoader, ClassWriter cw, String newDynName, String fieldPrefix) {
|
||||||
if (Utility.isNotEmpty(consumerBytes)) {
|
if (Utility.isNotEmpty(consumerBytes)) {
|
||||||
AnnotationVisitor av0 = cw.visitAnnotation(org.redkale.asm.Type.getDescriptor(DynForMessageds.class), true);
|
AnnotationVisitor av0 = cw.visitAnnotation(org.redkale.asm.Type.getDescriptor(DynForMessageds.class), true);
|
||||||
AnnotationVisitor av1 = av0.visitArray("value");
|
AnnotationVisitor av1 = av0.visitArray("value");
|
||||||
@@ -342,7 +341,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doInstance(DynBytesClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
public void doInstance(RedkaleClassLoader classLoader, ResourceFactory resourceFactory, Object service) {
|
||||||
DynForMessaged[] dyns = service.getClass().getAnnotationsByType(DynForMessaged.class);
|
DynForMessaged[] dyns = service.getClass().getAnnotationsByType(DynForMessaged.class);
|
||||||
if (Utility.isNotEmpty(dyns)) {
|
if (Utility.isNotEmpty(dyns)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import org.redkale.service.Service;
|
|||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.AnyValueWriter;
|
import org.redkale.util.AnyValueWriter;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
@@ -455,11 +454,11 @@ public class MessageModuleEngine extends ModuleEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (boost != null && Utility.isNotEmpty(boost.consumerBytes)) {
|
if (boost != null && Utility.isNotEmpty(boost.consumerBytes)) {
|
||||||
DynBytesClassLoader classLoader = DynBytesClassLoader.create(null);
|
RedkaleClassLoader classLoader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
boost.consumerBytes.forEach((innerFullName, bytes) -> {
|
boost.consumerBytes.forEach((innerFullName, bytes) -> {
|
||||||
try {
|
try {
|
||||||
String clzName = innerFullName.replace('/', '.');
|
String clzName = innerFullName.replace('/', '.');
|
||||||
Class<? extends MessageConsumer> clazz = (Class) classLoader.loadClass(clzName, bytes);
|
Class<? extends MessageConsumer> clazz = classLoader.loadClass(clzName, bytes);
|
||||||
RedkaleClassLoader.putDynClass(clzName, bytes, clazz);
|
RedkaleClassLoader.putDynClass(clzName, bytes, clazz);
|
||||||
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
RedkaleClassLoader.putReflectionPublicConstructors(clazz, clzName);
|
||||||
MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service);
|
MessageConsumer consumer = (MessageConsumer) clazz.getConstructors()[0].newInstance(service);
|
||||||
|
|||||||
@@ -108,11 +108,10 @@ public class HttpContext extends Context {
|
|||||||
final String handlerDesc = Type.getDescriptor(CompletionHandler.class);
|
final String handlerDesc = Type.getDescriptor(CompletionHandler.class);
|
||||||
final String newDynName = "org/redkaledyn/http/handler/_DynHttpAsyncHandler__"
|
final String newDynName = "org/redkaledyn/http/handler/_DynHttpAsyncHandler__"
|
||||||
+ handlerClass.getName().replace('.', '/').replace('$', '_');
|
+ handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||||
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
try {
|
try {
|
||||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||||
Class newHandlerClazz = clz == null
|
Class newHandlerClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||||
? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.'))
|
|
||||||
: clz;
|
|
||||||
return Creator.create(newHandlerClazz);
|
return Creator.create(newHandlerClazz);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
// do nothing
|
// do nothing
|
||||||
@@ -214,12 +213,7 @@ public class HttpContext extends Context {
|
|||||||
}
|
}
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<CompletionHandler> newClazz = (Class<CompletionHandler>)
|
Class<CompletionHandler> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
new ClassLoader(handlerClass.getClassLoader()) {
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
return (Creator<H>) Creator.create(newClazz);
|
return (Creator<H>) Creator.create(newClazz);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -560,13 +560,12 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
|||||||
for (Class cz : method.getParameterTypes()) {
|
for (Class cz : method.getParameterTypes()) {
|
||||||
tmpps.append("__").append(cz.getName().replace('.', '_'));
|
tmpps.append("__").append(cz.getName().replace('.', '_'));
|
||||||
}
|
}
|
||||||
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
final String newDynName = "org/redkaledyn/http/servlet/action/_DynHttpActionServlet__"
|
final String newDynName = "org/redkaledyn/http/servlet/action/_DynHttpActionServlet__"
|
||||||
+ this.getClass().getName().replace('.', '_').replace('$', '_') + "__" + method.getName() + tmpps;
|
+ this.getClass().getName().replace('.', '_').replace('$', '_') + "__" + method.getName() + tmpps;
|
||||||
try {
|
try {
|
||||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||||
Class newClazz = clz == null
|
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||||
? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.'))
|
|
||||||
: clz;
|
|
||||||
HttpServlet instance =
|
HttpServlet instance =
|
||||||
(HttpServlet) newClazz.getDeclaredConstructor().newInstance();
|
(HttpServlet) newClazz.getDeclaredConstructor().newInstance();
|
||||||
instance.getClass().getField("_factServlet").set(instance, this);
|
instance.getClass().getField("_factServlet").set(instance, this);
|
||||||
@@ -627,11 +626,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(this.getClass().getClassLoader()) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.redkale.net.sncp.Sncp;
|
|||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.source.Flipper;
|
import org.redkale.source.Flipper;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
|
||||||
import static org.redkale.util.Utility.isEmpty;
|
import static org.redkale.util.Utility.isEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -661,7 +660,7 @@ public final class Rest {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
DynBytesClassLoader newLoader = new DynBytesClassLoader(loader);
|
RedkaleClassLoader newLoader = RedkaleClassLoader.getRedkaleClassLoader(loader);
|
||||||
Map<String, Annotation[]> msgclassToAnnotations = new HashMap<>();
|
Map<String, Annotation[]> msgclassToAnnotations = new HashMap<>();
|
||||||
for (int i = 0; i < messageMethods.size(); i++) { // _DyncXXXWebSocketMessage 子消息List
|
for (int i = 0; i < messageMethods.size(); i++) { // _DyncXXXWebSocketMessage 子消息List
|
||||||
final Method method = messageMethods.get(i);
|
final Method method = messageMethods.get(i);
|
||||||
@@ -1990,7 +1989,7 @@ public final class Rest {
|
|||||||
return null; // 没有可HttpMapping的方法
|
return null; // 没有可HttpMapping的方法
|
||||||
}
|
}
|
||||||
Collections.sort(entrys);
|
Collections.sort(entrys);
|
||||||
DynBytesClassLoader newLoader = new DynBytesClassLoader(loader);
|
RedkaleClassLoader newLoader = RedkaleClassLoader.getRedkaleClassLoader(loader);
|
||||||
final int moduleid = controller == null ? 0 : controller.moduleid();
|
final int moduleid = controller == null ? 0 : controller.moduleid();
|
||||||
{ // 注入 @WebServlet 注解
|
{ // 注入 @WebServlet 注解
|
||||||
String urlpath = "";
|
String urlpath = "";
|
||||||
@@ -4073,7 +4072,7 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
cw2.visitEnd();
|
cw2.visitEnd();
|
||||||
byte[] bytes = cw2.toByteArray();
|
byte[] bytes = cw2.toByteArray();
|
||||||
newLoader.addClass((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
newLoader.addDynClass((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
||||||
innerClassBytesMap.put((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
innerClassBytesMap.put((newDynName + "$" + entry.newActionClassName).replace('/', '.'), bytes);
|
||||||
}
|
}
|
||||||
} // end for each
|
} // end for each
|
||||||
@@ -4237,7 +4236,7 @@ public final class Rest {
|
|||||||
|
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
newLoader.addClass(newDynName.replace('/', '.'), bytes);
|
newLoader.addDynClass(newDynName.replace('/', '.'), bytes);
|
||||||
try {
|
try {
|
||||||
Class<?> newClazz = newLoader.findClass(newDynName.replace('/', '.'));
|
Class<?> newClazz = newLoader.findClass(newDynName.replace('/', '.'));
|
||||||
innerClassBytesMap.forEach((n, bs) -> {
|
innerClassBytesMap.forEach((n, bs) -> {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.redkale.scheduled.Scheduled;
|
|||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleClassLoader.DynBytesClassLoader;
|
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
import org.redkale.util.Uint128;
|
import org.redkale.util.Uint128;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
@@ -492,7 +491,7 @@ public abstract class Sncp {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected static <T extends Service> Class<? extends T> createLocalServiceClass(
|
protected static <T extends Service> Class<? extends T> createLocalServiceClass(
|
||||||
DynBytesClassLoader dynLoader,
|
RedkaleClassLoader dynLoader,
|
||||||
final String name,
|
final String name,
|
||||||
final Class<T> serviceImplClass,
|
final Class<T> serviceImplClass,
|
||||||
final AsmMethodBoost methodBoost) {
|
final AsmMethodBoost methodBoost) {
|
||||||
@@ -626,7 +625,7 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void createNewMethods(
|
private static void createNewMethods(
|
||||||
DynBytesClassLoader classLoader,
|
RedkaleClassLoader classLoader,
|
||||||
Class clazz,
|
Class clazz,
|
||||||
final AsmMethodBoost methodBoost,
|
final AsmMethodBoost methodBoost,
|
||||||
Set<String> methodKeys,
|
Set<String> methodKeys,
|
||||||
@@ -766,7 +765,7 @@ public abstract class Sncp {
|
|||||||
final String remoteGroup,
|
final String remoteGroup,
|
||||||
final AnyValue conf) {
|
final AnyValue conf) {
|
||||||
try {
|
try {
|
||||||
final DynBytesClassLoader dynLoader = DynBytesClassLoader.create(classLoader);
|
final RedkaleClassLoader dynLoader = RedkaleClassLoader.getRedkaleClassLoader(classLoader);
|
||||||
final Class newClazz = createLocalServiceClass(dynLoader, name, serviceImplClass, methodBoost);
|
final Class newClazz = createLocalServiceClass(dynLoader, name, serviceImplClass, methodBoost);
|
||||||
T service = (T) newClazz.getDeclaredConstructor().newInstance();
|
T service = (T) newClazz.getDeclaredConstructor().newInstance();
|
||||||
// --------------------------------------
|
// --------------------------------------
|
||||||
@@ -939,7 +938,7 @@ public abstract class Sncp {
|
|||||||
final String sncpInfoDesc = Type.getDescriptor(SncpRemoteInfo.class);
|
final String sncpInfoDesc = Type.getDescriptor(SncpRemoteInfo.class);
|
||||||
final String sncpDynDesc = Type.getDescriptor(SncpDyn.class);
|
final String sncpDynDesc = Type.getDescriptor(SncpDyn.class);
|
||||||
final String anyValueDesc = Type.getDescriptor(AnyValue.class);
|
final String anyValueDesc = Type.getDescriptor(AnyValue.class);
|
||||||
final DynBytesClassLoader dynLoader = DynBytesClassLoader.create(classLoader);
|
final RedkaleClassLoader dynLoader = RedkaleClassLoader.getRedkaleClassLoader(classLoader);
|
||||||
String newDynName = "org/redkaledyn/service/remote/_DynRemoteService__"
|
String newDynName = "org/redkaledyn/service/remote/_DynRemoteService__"
|
||||||
+ serviceTypeOrImplClass.getName().replace('.', '_').replace('$', '_');
|
+ serviceTypeOrImplClass.getName().replace('.', '_').replace('$', '_');
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public abstract class SncpActionServlet extends SncpServlet {
|
|||||||
this.actionid = actionid;
|
this.actionid = actionid;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.paramComposeBeanType = SncpRemoteAction.createParamComposeBeanType(
|
this.paramComposeBeanType = SncpRemoteAction.createParamComposeBeanType(
|
||||||
Thread.currentThread().getContextClassLoader(),
|
RedkaleClassLoader.getRedkaleClassLoader(),
|
||||||
Sncp.getServiceType(service),
|
Sncp.getServiceType(service),
|
||||||
method,
|
method,
|
||||||
actionid,
|
actionid,
|
||||||
@@ -356,10 +356,7 @@ public abstract class SncpActionServlet extends SncpServlet {
|
|||||||
final boolean boolReturnTypeFuture = Future.class.isAssignableFrom(method.getReturnType());
|
final boolean boolReturnTypeFuture = Future.class.isAssignableFrom(method.getReturnType());
|
||||||
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionServlet__"
|
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionServlet__"
|
||||||
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
if (String.class.getClassLoader() != serviceClass.getClassLoader()) {
|
|
||||||
loader = serviceClass.getClassLoader();
|
|
||||||
}
|
|
||||||
Class<?> newClazz = null;
|
Class<?> newClazz = null;
|
||||||
try {
|
try {
|
||||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||||
@@ -630,11 +627,13 @@ public abstract class SncpActionServlet extends SncpServlet {
|
|||||||
mv.visitVarInsn(ASTORE, 5); // paramBean
|
mv.visitVarInsn(ASTORE, 5); // paramBean
|
||||||
|
|
||||||
// 给CompletionHandler参数赋值
|
// 给CompletionHandler参数赋值
|
||||||
mv.visitVarInsn(ALOAD, 5);
|
if (handlerFuncIndex >= 0) {
|
||||||
mv.visitVarInsn(ALOAD, 2);
|
mv.visitVarInsn(ALOAD, 5);
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, responseName, "getParamAsyncHandler", "()" + handlerDesc, false);
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
mv.visitFieldInsn(PUTFIELD, paramComposeBeanName, "arg3", handlerDesc);
|
mv.visitMethodInsn(
|
||||||
|
INVOKEVIRTUAL, responseName, "getParamAsyncHandler", "()" + handlerDesc, false);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, paramComposeBeanName, "arg" + (handlerFuncIndex + 1), handlerDesc);
|
||||||
|
}
|
||||||
// 调用service()
|
// 调用service()
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "service", "()" + serviceDesc, false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "service", "()" + serviceDesc, false);
|
||||||
@@ -713,13 +712,10 @@ public abstract class SncpActionServlet extends SncpServlet {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
newClazz = new ClassLoader(loader) {
|
newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), newClazz.getField("service"));
|
RedkaleClassLoader.putReflectionField(newDynName.replace('/', '.'), newClazz.getField("service"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.net.sncp;
|
package org.redkale.net.sncp;
|
||||||
|
|
||||||
import static org.redkale.asm.Opcodes.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.nio.channels.CompletionHandler;
|
import java.nio.channels.CompletionHandler;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.redkale.asm.*;
|
import org.redkale.asm.*;
|
||||||
|
import static org.redkale.asm.Opcodes.*;
|
||||||
import org.redkale.asm.Type;
|
import org.redkale.asm.Type;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
@@ -55,11 +54,10 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
|||||||
final String realHandlerDesc = Type.getDescriptor(CompletionHandler.class);
|
final String realHandlerDesc = Type.getDescriptor(CompletionHandler.class);
|
||||||
final String newDynName = "org/redkaledyn/sncp/handler/_Dyn" + sncpHandlerClass.getSimpleName()
|
final String newDynName = "org/redkaledyn/sncp/handler/_Dyn" + sncpHandlerClass.getSimpleName()
|
||||||
+ "__" + handlerClass.getName().replace('.', '/').replace('$', '_');
|
+ "__" + handlerClass.getName().replace('.', '/').replace('$', '_');
|
||||||
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
try {
|
try {
|
||||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||||
Class newHandlerClazz = clz == null
|
Class newHandlerClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||||
? Thread.currentThread().getContextClassLoader().loadClass(newDynName.replace('/', '.'))
|
|
||||||
: clz;
|
|
||||||
return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz);
|
return (Creator<SncpAsyncHandler>) Creator.create(newHandlerClazz);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
// do nothing
|
// do nothing
|
||||||
@@ -208,13 +206,7 @@ public interface SncpAsyncHandler<V, A> extends CompletionHandler<V, A> {
|
|||||||
}
|
}
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class newClazz =
|
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
new ClassLoader((handlerClass != CompletionHandler.class ? handlerClass : sncpHandlerClass)
|
|
||||||
.getClassLoader()) {
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
return (Creator<SncpAsyncHandler>) Creator.create(newClazz);
|
return (Creator<SncpAsyncHandler>) Creator.create(newClazz);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import org.redkale.asm.FieldVisitor;
|
|||||||
import org.redkale.asm.MethodDebugVisitor;
|
import org.redkale.asm.MethodDebugVisitor;
|
||||||
import static org.redkale.asm.Opcodes.*;
|
import static org.redkale.asm.Opcodes.*;
|
||||||
import org.redkale.convert.ConvertColumn;
|
import org.redkale.convert.ConvertColumn;
|
||||||
|
import org.redkale.convert.Encodeable;
|
||||||
import org.redkale.convert.ObjectEncoder;
|
import org.redkale.convert.ObjectEncoder;
|
||||||
|
import org.redkale.convert.SimpledCoder;
|
||||||
import org.redkale.convert.pb.ProtobufFactory;
|
import org.redkale.convert.pb.ProtobufFactory;
|
||||||
import org.redkale.service.RpcAttachment;
|
import org.redkale.service.RpcAttachment;
|
||||||
import org.redkale.service.RpcSourceAddress;
|
import org.redkale.service.RpcSourceAddress;
|
||||||
@@ -99,7 +101,12 @@ public final class SncpRemoteAction {
|
|||||||
this.paramTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), serviceImplClass);
|
this.paramTypes = TypeToken.getGenericType(method.getGenericParameterTypes(), serviceImplClass);
|
||||||
this.paramClasses = method.getParameterTypes();
|
this.paramClasses = method.getParameterTypes();
|
||||||
Type pt = createParamComposeBeanType(
|
Type pt = createParamComposeBeanType(
|
||||||
serviceImplClass.getClassLoader(), serviceImplClass, method, actionid, paramTypes, paramClasses);
|
RedkaleClassLoader.getRedkaleClassLoader(),
|
||||||
|
serviceImplClass,
|
||||||
|
method,
|
||||||
|
actionid,
|
||||||
|
paramTypes,
|
||||||
|
paramClasses);
|
||||||
this.paramComposeBeanType = pt;
|
this.paramComposeBeanType = pt;
|
||||||
this.paramComposeBeanCreator =
|
this.paramComposeBeanCreator =
|
||||||
(pt == null || pt == paramTypes[0]) ? null : Creator.load(TypeToken.typeToClass(pt), 1);
|
(pt == null || pt == paramTypes[0]) ? null : Creator.load(TypeToken.typeToClass(pt), 1);
|
||||||
@@ -242,7 +249,7 @@ public final class SncpRemoteAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Type createParamComposeBeanType(
|
public static Type createParamComposeBeanType(
|
||||||
ClassLoader loader,
|
RedkaleClassLoader loader,
|
||||||
Class resourceType,
|
Class resourceType,
|
||||||
Method method,
|
Method method,
|
||||||
Uint128 actionid,
|
Uint128 actionid,
|
||||||
@@ -251,17 +258,17 @@ public final class SncpRemoteAction {
|
|||||||
if (paramTypes == null || paramTypes.length == 0) {
|
if (paramTypes == null || paramTypes.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (paramTypes.length == 1 && ProtobufFactory.root().createEncoder(paramTypes[0]) instanceof ObjectEncoder) {
|
if (paramTypes.length == 1) {
|
||||||
return paramTypes[0];
|
Encodeable encodeable = ProtobufFactory.root().findEncoder(paramTypes[0]);
|
||||||
|
if (encodeable == null) { // java.io.Serializable会预置,直接调用createEncoder会提示不支持的Type
|
||||||
|
ProtobufFactory.root().createEncoder(paramTypes[0]);
|
||||||
|
}
|
||||||
|
if (encodeable instanceof ObjectEncoder || encodeable instanceof SimpledCoder) {
|
||||||
|
return paramTypes[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态生成组合JavaBean类
|
// 动态生成组合JavaBean类
|
||||||
if (loader == null) {
|
|
||||||
loader = Thread.currentThread().getContextClassLoader();
|
|
||||||
if (String.class.getClassLoader() != resourceType.getClassLoader()) {
|
|
||||||
loader = resourceType.getClassLoader();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final String columnDesc = org.redkale.asm.Type.getDescriptor(ConvertColumn.class);
|
final String columnDesc = org.redkale.asm.Type.getDescriptor(ConvertColumn.class);
|
||||||
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionParamBean_"
|
final String newDynName = "org/redkaledyn/sncp/servlet/action/_DynSncpActionParamBean_"
|
||||||
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
+ resourceType.getSimpleName() + "_" + method.getName() + "_" + actionid;
|
||||||
@@ -320,11 +327,7 @@ public final class SncpRemoteAction {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class newClazz = new ClassLoader(loader) {
|
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
Creator.load(newClazz, 1); // 只一个Object[]参数
|
Creator.load(newClazz, 1); // 只一个Object[]参数
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
|||||||
protected final CompletionHandler realHandler = new CompletionHandler() {
|
protected final CompletionHandler realHandler = new CompletionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void completed(Object result, Object attachment) {
|
public void completed(Object result, Object attachment) {
|
||||||
finish(paramHandlerResultType, result);
|
finish(paramHandlerType, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,7 +50,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected Type paramHandlerResultType;
|
protected Type paramHandlerType;
|
||||||
|
|
||||||
protected CompletionHandler paramAsyncHandler;
|
protected CompletionHandler paramAsyncHandler;
|
||||||
|
|
||||||
@@ -80,11 +80,11 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SncpResponse paramAsyncHandler(
|
public SncpResponse paramAsyncHandler(
|
||||||
Class<? extends CompletionHandler> paramHandlerType, Type paramHandlerResultType) {
|
Class<? extends CompletionHandler> paramHandlerClass, Type paramHandlerType) {
|
||||||
this.paramHandlerResultType = paramHandlerResultType;
|
this.paramHandlerType = paramHandlerType;
|
||||||
this.paramAsyncHandler = paramHandlerType == CompletionHandler.class
|
this.paramAsyncHandler = paramHandlerClass == CompletionHandler.class
|
||||||
? realHandler
|
? realHandler
|
||||||
: SncpAsyncHandler.createHandler(paramHandlerType, realHandler);
|
: SncpAsyncHandler.createHandler(paramHandlerClass, realHandler);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean recycle() {
|
protected boolean recycle() {
|
||||||
writer.clear();
|
writer.clear();
|
||||||
this.paramHandlerResultType = null;
|
this.paramHandlerType = null;
|
||||||
this.paramAsyncHandler = null;
|
this.paramAsyncHandler = null;
|
||||||
return super.recycle();
|
return super.recycle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,10 +80,7 @@ public abstract class EntityFullFunc<T> {
|
|||||||
final String objectDesc = Type.getDescriptor(Object.class);
|
final String objectDesc = Type.getDescriptor(Object.class);
|
||||||
final String serisDesc = Type.getDescriptor(Serializable[].class);
|
final String serisDesc = Type.getDescriptor(Serializable[].class);
|
||||||
|
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
if (String.class.getClassLoader() != entityType.getClassLoader()) {
|
|
||||||
loader = entityType.getClassLoader();
|
|
||||||
}
|
|
||||||
final String newDynName = "org/redkaledyn/source/_Dyn" + EntityFullFunc.class.getSimpleName() + "__"
|
final String newDynName = "org/redkaledyn/source/_Dyn" + EntityFullFunc.class.getSimpleName() + "__"
|
||||||
+ entityType.getName().replace('.', '_').replace('$', '_');
|
+ entityType.getName().replace('.', '_').replace('$', '_');
|
||||||
try {
|
try {
|
||||||
@@ -796,12 +793,7 @@ public abstract class EntityFullFunc<T> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<EntityFullFunc> newClazz = (Class<EntityFullFunc>)
|
Class<EntityFullFunc> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
new ClassLoader(loader) {
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public final class DataSqlMapperBuilder {
|
|||||||
if (!mapperType.isInterface()) {
|
if (!mapperType.isInterface()) {
|
||||||
throw new SourceException(mapperType + " is not interface");
|
throw new SourceException(mapperType + " is not interface");
|
||||||
}
|
}
|
||||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
final Class entityType = entityType(mapperType);
|
final Class entityType = entityType(mapperType);
|
||||||
final String supDynName = mapperType.getName().replace('.', '/');
|
final String supDynName = mapperType.getName().replace('.', '/');
|
||||||
final String newDynName = "org/redkaledyn/source/mapper/_DynDataSqlMapper_"
|
final String newDynName = "org/redkaledyn/source/mapper/_DynDataSqlMapper_"
|
||||||
@@ -363,11 +363,7 @@ public final class DataSqlMapperBuilder {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(loader) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionPublicConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
|
|||||||
@@ -1002,11 +1002,11 @@ public interface Attribute<T, F> {
|
|||||||
final String interDesc = Type.getDescriptor(TypeToken.typeToClass(subclass));
|
final String interDesc = Type.getDescriptor(TypeToken.typeToClass(subclass));
|
||||||
final String columnDesc = Type.getDescriptor(column);
|
final String columnDesc = Type.getDescriptor(column);
|
||||||
Class realclz = TypeToken.typeToClass(subclass);
|
Class realclz = TypeToken.typeToClass(subclass);
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
try {
|
try {
|
||||||
loader.loadClass(realclz.getName());
|
loader.loadClass(realclz.getName());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
loader = realclz.getClassLoader();
|
// do nothing
|
||||||
}
|
}
|
||||||
String pkgname = "";
|
String pkgname = "";
|
||||||
String clzname = newsubname.toString();
|
String clzname = newsubname.toString();
|
||||||
@@ -1233,12 +1233,7 @@ public interface Attribute<T, F> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<Attribute> newClazz = (Class<Attribute>)
|
Class<Attribute> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
new ClassLoader(loader) {
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -679,7 +679,7 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
|||||||
final String srcClassName = srcClass.getName().replace('.', '/');
|
final String srcClassName = srcClass.getName().replace('.', '/');
|
||||||
final String destDesc = Type.getDescriptor(destClass);
|
final String destDesc = Type.getDescriptor(destClass);
|
||||||
final String srcDesc = Type.getDescriptor(srcClass);
|
final String srcDesc = Type.getDescriptor(srcClass);
|
||||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
final String utilClassName = Utility.class.getName().replace('.', '/');
|
final String utilClassName = Utility.class.getName().replace('.', '/');
|
||||||
final String newDynName = "org/redkaledyn/copier/_Dyn" + Copier.class.getSimpleName() + "_" + options
|
final String newDynName = "org/redkaledyn/copier/_Dyn" + Copier.class.getSimpleName() + "_" + options
|
||||||
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_')
|
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_')
|
||||||
@@ -1337,11 +1337,7 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(loader) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -292,10 +292,8 @@ public interface Creator<T> {
|
|||||||
final String supDynName = Creator.class.getName().replace('.', '/');
|
final String supDynName = Creator.class.getName().replace('.', '/');
|
||||||
final String interName = clazz.getName().replace('.', '/');
|
final String interName = clazz.getName().replace('.', '/');
|
||||||
final String interDesc = Type.getDescriptor(clazz);
|
final String interDesc = Type.getDescriptor(clazz);
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader =
|
||||||
if (String.class.getClassLoader() != clazz.getClassLoader()) {
|
RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
loader = clazz.getClassLoader();
|
|
||||||
}
|
|
||||||
final String newDynName = "org/redkaledyn/creator/_Dyn" + Creator.class.getSimpleName() + "__"
|
final String newDynName = "org/redkaledyn/creator/_Dyn" + Creator.class.getSimpleName() + "__"
|
||||||
+ clazz.getName().replace('.', '_').replace('$', '_') + (paramCount < 0 ? "" : ("_" + paramCount));
|
+ clazz.getName().replace('.', '_').replace('$', '_') + (paramCount < 0 ? "" : ("_" + paramCount));
|
||||||
try {
|
try {
|
||||||
@@ -571,11 +569,7 @@ public interface Creator<T> {
|
|||||||
|
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
try {
|
try {
|
||||||
Class newClazz = new ClassLoader(loader) {
|
Class newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
return (Creator) newClazz.getDeclaredConstructor().newInstance();
|
return (Creator) newClazz.getDeclaredConstructor().newInstance();
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ class Inners {
|
|||||||
}
|
}
|
||||||
final String interName = clazz.getName().replace('.', '/');
|
final String interName = clazz.getName().replace('.', '/');
|
||||||
final String interDesc = org.redkale.asm.Type.getDescriptor(clazz);
|
final String interDesc = org.redkale.asm.Type.getDescriptor(clazz);
|
||||||
final ClassLoader loader = clazz.getClassLoader();
|
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
final String newDynName = "org/redkaledyn/creator/_DynArrayFunction__"
|
final String newDynName = "org/redkaledyn/creator/_DynArrayFunction__"
|
||||||
+ clazz.getName().replace('.', '_').replace('$', '_');
|
+ clazz.getName().replace('.', '_').replace('$', '_');
|
||||||
try {
|
try {
|
||||||
@@ -283,11 +283,7 @@ class Inners {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
final byte[] bytes = cw.toByteArray();
|
final byte[] bytes = cw.toByteArray();
|
||||||
try {
|
try {
|
||||||
Class<?> resultClazz = new ClassLoader(loader) {
|
Class<?> resultClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||||
return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance();
|
return (IntFunction<T[]>) resultClazz.getDeclaredConstructor().newInstance();
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.util;
|
package org.redkale.util;
|
||||||
|
|
||||||
import static org.redkale.asm.Opcodes.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.redkale.asm.*;
|
import org.redkale.asm.*;
|
||||||
|
import static org.redkale.asm.Opcodes.*;
|
||||||
import org.redkale.asm.Type;
|
import org.redkale.asm.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +91,7 @@ public interface Invoker<C, R> {
|
|||||||
} else if (returnType == void.class) {
|
} else if (returnType == void.class) {
|
||||||
returnDesc = Type.getDescriptor(Void.class);
|
returnDesc = Type.getDescriptor(Void.class);
|
||||||
}
|
}
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
StringBuilder sbpts = new StringBuilder();
|
StringBuilder sbpts = new StringBuilder();
|
||||||
for (Class c : method.getParameterTypes()) {
|
for (Class c : method.getParameterTypes()) {
|
||||||
sbpts.append('_').append(c.getName().replace('.', '_').replace('$', '_'));
|
sbpts.append('_').append(c.getName().replace('.', '_').replace('$', '_'));
|
||||||
@@ -209,11 +208,7 @@ public interface Invoker<C, R> {
|
|||||||
Class<?> resultClazz = null;
|
Class<?> resultClazz = null;
|
||||||
try {
|
try {
|
||||||
if (resultClazz == null) {
|
if (resultClazz == null) {
|
||||||
resultClazz = new ClassLoader(loader) {
|
resultClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
}
|
}
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, resultClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(resultClazz, newDynName.replace('/', '.'));
|
||||||
|
|||||||
@@ -89,6 +89,26 @@ public class RedkaleClassLoader extends URLClassLoader {
|
|||||||
super(urls, parent);
|
super(urls, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RedkaleClassLoader getRedkaleClassLoader(ClassLoader loader) {
|
||||||
|
if (loader == null) {
|
||||||
|
loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
}
|
||||||
|
if (loader instanceof RedkaleClassLoader) {
|
||||||
|
return (RedkaleClassLoader) loader;
|
||||||
|
}
|
||||||
|
ClassLoader c = loader;
|
||||||
|
while ((c = c.getParent()) != null) {
|
||||||
|
if (c instanceof RedkaleClassLoader) {
|
||||||
|
return (RedkaleClassLoader) c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new RedkaleClassLoader(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RedkaleClassLoader getRedkaleClassLoader() {
|
||||||
|
return getRedkaleClassLoader(Thread.currentThread().getContextClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
public static URI getConfResourceAsURI(String confURI, String file) {
|
public static URI getConfResourceAsURI(String confURI, String file) {
|
||||||
if (file.startsWith("http:") || file.startsWith("https:") || file.startsWith("ftp:")) {
|
if (file.startsWith("http:") || file.startsWith("https:") || file.startsWith("ftp:")) {
|
||||||
return URI.create(file);
|
return URI.create(file);
|
||||||
@@ -461,7 +481,20 @@ public class RedkaleClassLoader extends URLClassLoader {
|
|||||||
reflectionMap.forEach(action);
|
reflectionMap.forEach(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> loadClass(String name, byte[] b) {
|
@Override
|
||||||
|
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
byte[] classData = dynClassBytesMap.get(name);
|
||||||
|
if (classData == null) {
|
||||||
|
Class clazz = dynClassTypeMap.get(name);
|
||||||
|
if (clazz != null) {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
return super.findClass(name);
|
||||||
|
}
|
||||||
|
return super.defineClass(name, classData, 0, classData.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class loadClass(String name, byte[] b) {
|
||||||
return defineClass(name, b, 0, b.length);
|
return defineClass(name, b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,6 +504,10 @@ public class RedkaleClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void addDynClass(String name, byte[] bs) {
|
||||||
|
dynClassBytesMap.put(name, bs);
|
||||||
|
}
|
||||||
|
|
||||||
public void addURI(URI uri) {
|
public void addURI(URI uri) {
|
||||||
try {
|
try {
|
||||||
super.addURL(uri.toURL());
|
super.addURL(uri.toURL());
|
||||||
@@ -577,39 +614,4 @@ public class RedkaleClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DynBytesClassLoader extends ClassLoader {
|
|
||||||
|
|
||||||
private final Map<String, byte[]> classes = new HashMap<>();
|
|
||||||
|
|
||||||
public DynBytesClassLoader(ClassLoader parent) {
|
|
||||||
super(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DynBytesClassLoader create(ClassLoader parent) {
|
|
||||||
if (parent == null) {
|
|
||||||
parent = Thread.currentThread().getContextClassLoader();
|
|
||||||
}
|
|
||||||
return parent instanceof DynBytesClassLoader
|
|
||||||
? (DynBytesClassLoader) parent
|
|
||||||
: new DynBytesClassLoader(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
byte[] classData = classes.get(name);
|
|
||||||
if (classData == null) {
|
|
||||||
return super.findClass(name);
|
|
||||||
}
|
|
||||||
return super.defineClass(name, classData, 0, classData.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void addClass(String name, byte[] b) {
|
|
||||||
classes.put(name, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package org.redkale.util;
|
package org.redkale.util;
|
||||||
|
|
||||||
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
|
|
||||||
import static org.redkale.asm.Opcodes.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import org.redkale.asm.*;
|
import org.redkale.asm.*;
|
||||||
|
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
|
||||||
|
import static org.redkale.asm.Opcodes.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaBean类对象的拷贝,相同的字段名会被拷贝 <br>
|
* JavaBean类对象的拷贝,相同的字段名会被拷贝 <br>
|
||||||
@@ -68,7 +67,7 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
|||||||
final String srcClassName = srcClass.getName().replace('.', '/');
|
final String srcClassName = srcClass.getName().replace('.', '/');
|
||||||
final String destDesc = Type.getDescriptor(destClass);
|
final String destDesc = Type.getDescriptor(destClass);
|
||||||
final String srcDesc = Type.getDescriptor(srcClass);
|
final String srcDesc = Type.getDescriptor(srcClass);
|
||||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
final RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
final String newDynName = "org/redkaledyn/reproduce/_Dyn" + Reproduce.class.getSimpleName()
|
final String newDynName = "org/redkaledyn/reproduce/_Dyn" + Reproduce.class.getSimpleName()
|
||||||
+ "__" + destClass.getName().replace('.', '_').replace('$', '_')
|
+ "__" + destClass.getName().replace('.', '_').replace('$', '_')
|
||||||
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_');
|
+ "__" + srcClass.getName().replace('.', '_').replace('$', '_');
|
||||||
@@ -232,11 +231,7 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
|||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(loader) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionDeclaredConstructors(newClazz, newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -662,7 +662,7 @@ public abstract class TypeToken<T> {
|
|||||||
|
|
||||||
// 注意: RetResult<Map<String, Long>[]> 这种泛型带[]的尚未实现支持
|
// 注意: RetResult<Map<String, Long>[]> 这种泛型带[]的尚未实现支持
|
||||||
private static Type createParameterizedType0(final Class rawType, final Type... actualTypeArguments) {
|
private static Type createParameterizedType0(final Class rawType, final Type... actualTypeArguments) {
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
RedkaleClassLoader loader = RedkaleClassLoader.getRedkaleClassLoader();
|
||||||
StringBuilder tmpps = new StringBuilder(getClassTypeDescriptor(rawType));
|
StringBuilder tmpps = new StringBuilder(getClassTypeDescriptor(rawType));
|
||||||
for (Type cz : actualTypeArguments) {
|
for (Type cz : actualTypeArguments) {
|
||||||
tmpps.append(" ").append(getClassTypeDescriptor(cz));
|
tmpps.append(" ").append(getClassTypeDescriptor(cz));
|
||||||
@@ -715,11 +715,7 @@ public abstract class TypeToken<T> {
|
|||||||
}
|
}
|
||||||
cw.visitEnd();
|
cw.visitEnd();
|
||||||
byte[] bytes = cw.toByteArray();
|
byte[] bytes = cw.toByteArray();
|
||||||
Class<?> newClazz = new ClassLoader(loader) {
|
Class<?> newClazz = loader.loadClass(newDynName.replace('/', '.'), bytes);
|
||||||
public final Class<?> loadClass(String name, byte[] b) {
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
|
||||||
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
RedkaleClassLoader.putDynClass(newDynName.replace('/', '.'), bytes, newClazz);
|
||||||
RedkaleClassLoader.putReflectionPublicFields(newDynName.replace('/', '.'));
|
RedkaleClassLoader.putReflectionPublicFields(newDynName.replace('/', '.'));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.*;
|
|||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.redkale.convert.ConvertCoder;
|
import org.redkale.convert.ConvertCoder;
|
||||||
import org.redkale.convert.ConvertColumn;
|
import org.redkale.convert.ConvertColumn;
|
||||||
import org.redkale.convert.ext.BigIntegerSimpledCoder.BigIntegerHexJsonSimpledCoder;
|
import org.redkale.convert.json.JsonCoders.BigIntegerHexJsonSimpledCoder;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.convert.pb.ProtobufConvert;
|
import org.redkale.convert.pb.ProtobufConvert;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.function.Supplier;
|
|||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.redkale.convert.ConvertColumn;
|
import org.redkale.convert.ConvertColumn;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
import org.redkale.convert.json.JsonFactory;
|
||||||
import org.redkale.convert.pb.ProtobufConvert;
|
import org.redkale.convert.pb.ProtobufConvert;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
@@ -43,6 +44,8 @@ public class GenericEntityTest {
|
|||||||
@Test
|
@Test
|
||||||
public void runJson1() throws Exception {
|
public void runJson1() throws Exception {
|
||||||
System.out.println("-------------------- runJson1 ---------------------------------");
|
System.out.println("-------------------- runJson1 ---------------------------------");
|
||||||
|
JsonFactory.root().loadEncoder(TreeNode.class);
|
||||||
|
JsonFactory.root().loadEncoder(TreeNode2.class);
|
||||||
JsonConvert convert = JsonConvert.root();
|
JsonConvert convert = JsonConvert.root();
|
||||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||||
String json = convert.convertTo(ENTITY_TYPE, bean);
|
String json = convert.convertTo(ENTITY_TYPE, bean);
|
||||||
@@ -76,6 +79,8 @@ public class GenericEntityTest {
|
|||||||
@Test
|
@Test
|
||||||
public void runPb1() throws Exception {
|
public void runPb1() throws Exception {
|
||||||
System.out.println("-------------------- runPb1 ---------------------------------");
|
System.out.println("-------------------- runPb1 ---------------------------------");
|
||||||
|
JsonFactory.root().loadEncoder(TreeNode.class);
|
||||||
|
JsonFactory.root().loadEncoder(TreeNode2.class);
|
||||||
ProtobufConvert convert = ProtobufConvert.root();
|
ProtobufConvert convert = ProtobufConvert.root();
|
||||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||||
byte[] bs = convert.convertTo(ENTITY_TYPE, bean);
|
byte[] bs = convert.convertTo(ENTITY_TYPE, bean);
|
||||||
@@ -137,6 +142,22 @@ public class GenericEntityTest {
|
|||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TreeNode {
|
||||||
|
@ConvertColumn(index = 1)
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@ConvertColumn(index = 2)
|
||||||
|
public TreeNode next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TreeNode2 {
|
||||||
|
@ConvertColumn(index = 1)
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@ConvertColumn(index = 2)
|
||||||
|
public List<TreeNode2> next;
|
||||||
|
}
|
||||||
|
|
||||||
public static class GenericEntity<T, K, V> {
|
public static class GenericEntity<T, K, V> {
|
||||||
|
|
||||||
@ConvertColumn(index = 1)
|
@ConvertColumn(index = 1)
|
||||||
|
|||||||
@@ -53,4 +53,6 @@ public class TinyTest {
|
|||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class SncpSleepService extends AbstractService {
|
|||||||
getExecutor());
|
getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String test(Serializable id, String[] names, Collection<File> files) {
|
public String test(Serializable id, String[] names, Collection<File> files, int time) {
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class SncpSleepTest {
|
|||||||
CompletableFuture.allOf(futures).join();
|
CompletableFuture.allOf(futures).join();
|
||||||
long e = System.currentTimeMillis() - s;
|
long e = System.currentTimeMillis() - s;
|
||||||
System.out.println("耗时: " + e + " ms");
|
System.out.println("耗时: " + e + " ms");
|
||||||
remoteCService.test(333L, new String[] {"aaa", "bbb"}, List.of(new File("D:/a.txt"), new File("D:/b.txt")));
|
remoteCService.test(333L, new String[] {"aaa", "bbb"}, List.of(new File("D:/a.txt"), new File("D:/b.txt")), 2);
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
workExecutor.shutdown();
|
workExecutor.shutdown();
|
||||||
Assertions.assertTrue(e < 600);
|
Assertions.assertTrue(e < 600);
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ public class DynActionTestService_insert extends SncpActionServlet {
|
|||||||
Convert<Reader, Writer> convert = request.getConvert();
|
Convert<Reader, Writer> convert = request.getConvert();
|
||||||
Reader in = request.getReader();
|
Reader in = request.getReader();
|
||||||
DynSncpActionParamBean_TestService_insert bean = convert.convertFrom(paramComposeBeanType, in);
|
DynSncpActionParamBean_TestService_insert bean = convert.convertFrom(paramComposeBeanType, in);
|
||||||
bean.arg0 = response.getParamAsyncHandler();
|
bean.arg1 = response.getParamAsyncHandler();
|
||||||
TestService serviceObj = (TestService) service();
|
TestService serviceObj = (TestService) service();
|
||||||
serviceObj.insert(bean.arg0, bean.arg1, bean.arg2, bean.arg3);
|
serviceObj.insert(bean.arg1, bean.arg2, bean.arg3, bean.arg4);
|
||||||
response.finishVoid();
|
response.finishVoid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,22 +48,22 @@ public class DynActionTestService_insert extends SncpActionServlet {
|
|||||||
public DynSncpActionParamBean_TestService_insert() {}
|
public DynSncpActionParamBean_TestService_insert() {}
|
||||||
|
|
||||||
public DynSncpActionParamBean_TestService_insert(Object[] params) {
|
public DynSncpActionParamBean_TestService_insert(Object[] params) {
|
||||||
this.arg0 = (BooleanHandler) params[0];
|
this.arg1 = (BooleanHandler) params[0];
|
||||||
this.arg1 = (TestBean) params[1];
|
this.arg2 = (TestBean) params[1];
|
||||||
this.arg2 = (String) params[2];
|
this.arg3 = (String) params[2];
|
||||||
this.arg3 = (int) params[3];
|
this.arg4 = (int) params[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConvertColumn(index = 1)
|
@ConvertColumn(index = 1)
|
||||||
public BooleanHandler arg0;
|
public BooleanHandler arg1;
|
||||||
|
|
||||||
@ConvertColumn(index = 2)
|
@ConvertColumn(index = 2)
|
||||||
public TestBean arg1;
|
public TestBean arg2;
|
||||||
|
|
||||||
@ConvertColumn(index = 3)
|
@ConvertColumn(index = 3)
|
||||||
public String arg2;
|
public String arg3;
|
||||||
|
|
||||||
@ConvertColumn(index = 4)
|
@ConvertColumn(index = 4)
|
||||||
public int arg3;
|
public int arg4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user