diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index 9a0f24a51..1cdf3fe04 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -58,15 +58,15 @@ public final class Application { //当前进程节点的IP地址, 类型:InetAddress、String public static final String RESNAME_APP_ADDR = "APP_ADDR"; - //当前SNCP Server的IP地址+端口集合 类型: Map、 Map> - public static final String RESNAME_APP_NODES = "APP_NODES"; - //当前Service的IP地址+端口 类型: SocketAddress、InetSocketAddress、String public static final String RESNAME_SERVER_ADDR = "SERVER_ADDR"; //当前SNCP Server所属的组 类型: String public static final String RESNAME_SERVER_GROUP = "SERVER_GROUP"; + //当前Server的ROOt目录 类型:String、File、Path + public static final String RESNAME_SERVER_ROOT = Server.RESNAME_SERVER_ROOT; + final Map globalNodes = new HashMap<>(); final Map> globalGroups = new HashMap<>(); @@ -438,16 +438,6 @@ public final class Application { } if (!sncps.isEmpty() && globalNodes.isEmpty()) throw new RuntimeException("found SNCP Server node but not found node info."); - factory.register(RESNAME_APP_NODES, new TypeToken>() { - }.getType(), globalNodes); - factory.register(RESNAME_APP_NODES, new TypeToken>() { - }.getType(), globalNodes); - - factory.register(RESNAME_APP_NODES, new TypeToken>>() { - }.getType(), globalGroups); - factory.register(RESNAME_APP_NODES, new TypeToken>>() { - }.getType(), globalGroups); - runServers(timecd, sncps); //必须确保sncp都启动后再启动其他协议 runServers(timecd, others); timecd.await(); diff --git a/src/org/redkale/boot/NodeServer.java b/src/org/redkale/boot/NodeServer.java index ed00a0a7b..deeb6ecfc 100644 --- a/src/org/redkale/boot/NodeServer.java +++ b/src/org/redkale/boot/NodeServer.java @@ -17,6 +17,7 @@ import java.io.*; import java.lang.annotation.Annotation; import java.lang.reflect.*; import java.net.*; +import java.nio.file.*; import java.util.*; import java.util.concurrent.*; import java.util.function.Consumer; @@ -129,6 +130,11 @@ public abstract class NodeServer { if (!webroot.contains(":") && !webroot.startsWith("/")) { myroot = new File(System.getProperty(Application.RESNAME_APP_HOME), webroot); } + + factory.register(Server.RESNAME_SERVER_ROOT, String.class, myroot.getCanonicalPath()); + factory.register(Server.RESNAME_SERVER_ROOT, File.class, myroot.getCanonicalFile()); + factory.register(Server.RESNAME_SERVER_ROOT, Path.class, myroot.toPath()); + final String homepath = myroot.getCanonicalPath(); Server.loadLib(logger, config.getValue("lib", "") + ";" + homepath + "/lib/*;" + homepath + "/classes"); if (server != null) server.init(config); diff --git a/src/org/redkale/convert/ext/BigIntegerSimpledCoder.java b/src/org/redkale/convert/ext/BigIntegerSimpledCoder.java index c2772e24c..4723235e8 100644 --- a/src/org/redkale/convert/ext/BigIntegerSimpledCoder.java +++ b/src/org/redkale/convert/ext/BigIntegerSimpledCoder.java @@ -39,4 +39,30 @@ public final class BigIntegerSimpledCoder ex return bytes == null ? null : new BigInteger(bytes); } + /** + * BigInteger 的JsonSimpledCoder实现 + * + * @param Reader输入的子类型 + * @param Writer输出的子类型 + */ + public static class BigIntegerJsonSimpledCoder extends SimpledCoder { + + public static final BigIntegerJsonSimpledCoder instance = new BigIntegerJsonSimpledCoder(); + + @Override + public void convertTo(final Writer out, final BigInteger value) { + if (value == null) { + out.writeNull(); + } else { + out.writeString(value.toString()); + } + } + + @Override + public BigInteger convertFrom(Reader in) { + final String str = in.readString(); + if (str == null) return null; + return new BigInteger(str); + } + } } diff --git a/src/org/redkale/convert/ext/DLongSimpledCoder.java b/src/org/redkale/convert/ext/DLongSimpledCoder.java index d33e376e5..9dbd7eb22 100644 --- a/src/org/redkale/convert/ext/DLongSimpledCoder.java +++ b/src/org/redkale/convert/ext/DLongSimpledCoder.java @@ -63,7 +63,7 @@ public final class DLongSimpledCoder extends @Override public DLong convertFrom(Reader in) { - final String str = in.readString(); + final String str = in.readSmallString(); if (str == null) return null; return DLong.create(Utility.hexToBin(str)); } diff --git a/src/org/redkale/convert/json/JsonFactory.java b/src/org/redkale/convert/json/JsonFactory.java index ad4c43ca9..b6f380324 100644 --- a/src/org/redkale/convert/json/JsonFactory.java +++ b/src/org/redkale/convert/json/JsonFactory.java @@ -8,6 +8,7 @@ package org.redkale.convert.json; import org.redkale.convert.ConvertType; import org.redkale.convert.Factory; import java.io.Serializable; +import java.math.*; import java.net.*; import org.redkale.convert.ext.*; import org.redkale.util.*; @@ -27,6 +28,7 @@ public final class JsonFactory extends Factory { instance.register(InetAddress.class, InetAddressSimpledCoder.InetAddressJsonSimpledCoder.instance); instance.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressJsonSimpledCoder.instance); instance.register(DLong.class, DLongSimpledCoder.DLongJsonSimpledCoder.instance); + instance.register(BigInteger.class, BigIntegerSimpledCoder.BigIntegerJsonSimpledCoder.instance); instance.register(Serializable.class, instance.loadEncoder(Object.class)); } diff --git a/src/org/redkale/net/Server.java b/src/org/redkale/net/Server.java index 72081c1be..512fba766 100644 --- a/src/org/redkale/net/Server.java +++ b/src/org/redkale/net/Server.java @@ -26,7 +26,7 @@ import org.redkale.watch.*; */ public abstract class Server { - public static final String RESNAME_ROOT = "SERVER_ROOT"; + public static final String RESNAME_SERVER_ROOT = "SERVER_ROOT"; protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName()); diff --git a/src/org/redkale/util/ResourceFactory.java b/src/org/redkale/util/ResourceFactory.java index 2ab578df6..9c2c1dfc0 100644 --- a/src/org/redkale/util/ResourceFactory.java +++ b/src/org/redkale/util/ResourceFactory.java @@ -75,6 +75,62 @@ public final class ResourceFactory { loadermap.put(clazz, rs); } + public void register(final String name, final boolean value) { + register(true, name, boolean.class, value); + } + + public void register(final boolean autoSync, final String name, final boolean value) { + register(autoSync, name, boolean.class, value); + } + + public void register(final String name, final byte value) { + register(true, name, byte.class, value); + } + + public void register(final boolean autoSync, final String name, final byte value) { + register(autoSync, name, byte.class, value); + } + + public void register(final String name, final short value) { + register(true, name, short.class, value); + } + + public void register(final boolean autoSync, final String name, final short value) { + register(autoSync, name, short.class, value); + } + + public void register(final String name, final int value) { + register(true, name, int.class, value); + } + + public void register(final boolean autoSync, final String name, final int value) { + register(autoSync, name, int.class, value); + } + + public void register(final String name, final float value) { + register(true, name, float.class, value); + } + + public void register(final boolean autoSync, final String name, final float value) { + register(autoSync, name, float.class, value); + } + + public void register(final String name, final long value) { + register(true, name, long.class, value); + } + + public void register(final boolean autoSync, final String name, final long value) { + register(autoSync, name, long.class, value); + } + + public void register(final String name, final double value) { + register(true, name, double.class, value); + } + + public void register(final boolean autoSync, final String name, final double value) { + register(autoSync, name, double.class, value); + } + public void register(final String name, final Object rs) { register(true, name, rs); } @@ -268,9 +324,16 @@ public final class ResourceFactory { re = genctype == classtype ? findEntry(rcname, classtype) : findEntry(rcname, genctype); } } + if (re == null) { + register(rcname, genctype, null); //自动注入null的值 + re = genctype == classtype ? findEntry(rcname, classtype) : findEntry(rcname, genctype); + System.out.println(field + "-----------" + genctype + "---------" + rcname + "--------" + re); + } if (re == null) continue; + re.elements.add(new ResourceElement<>(src, field)); + Object rs = re.value; - if (!re.value.getClass().isPrimitive() && classtype.isPrimitive()) { + if (rs != null && !rs.getClass().isPrimitive() && classtype.isPrimitive()) { if (classtype == int.class) { rs = Integer.decode(rs.toString()); } else if (classtype == long.class) { @@ -287,13 +350,12 @@ public final class ResourceFactory { rs = Double.parseDouble(rs.toString()); } } - field.set(src, rs); - re.elements.add(new ResourceElement<>(src, field)); + if (rs != null) field.set(src, rs); } } while ((clazz = clazz.getSuperclass()) != Object.class); return true; } catch (Exception ex) { - logger.log(Level.FINER, "inject " + src + " error", ex); + logger.log(Level.SEVERE, "inject " + src + " error", ex); return false; } } @@ -348,6 +410,7 @@ public final class ResourceFactory { rs = Double.parseDouble(rs.toString()); } } + if (rs == null && classtype.isPrimitive()) rs = Array.get(Array.newInstance(classtype, 1), 0); try { element.field.set(dest, rs); } catch (Exception e) {