This commit is contained in:
@@ -58,15 +58,15 @@ public final class Application {
|
||||
//当前进程节点的IP地址, 类型:InetAddress、String
|
||||
public static final String RESNAME_APP_ADDR = "APP_ADDR";
|
||||
|
||||
//当前SNCP Server的IP地址+端口集合 类型: Map<InetSocketAddress, String>、 Map<String, Set<InetSocketAddress>>
|
||||
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<InetSocketAddress, String> globalNodes = new HashMap<>();
|
||||
|
||||
final Map<String, Set<InetSocketAddress>> 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 <group> node info.");
|
||||
|
||||
factory.register(RESNAME_APP_NODES, new TypeToken<Map<InetSocketAddress, String>>() {
|
||||
}.getType(), globalNodes);
|
||||
factory.register(RESNAME_APP_NODES, new TypeToken<HashMap<InetSocketAddress, String>>() {
|
||||
}.getType(), globalNodes);
|
||||
|
||||
factory.register(RESNAME_APP_NODES, new TypeToken<Map<String, Set<InetSocketAddress>>>() {
|
||||
}.getType(), globalGroups);
|
||||
factory.register(RESNAME_APP_NODES, new TypeToken<HashMap<String, Set<InetSocketAddress>>>() {
|
||||
}.getType(), globalGroups);
|
||||
|
||||
runServers(timecd, sncps); //必须确保sncp都启动后再启动其他协议
|
||||
runServers(timecd, others);
|
||||
timecd.await();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -39,4 +39,30 @@ public final class BigIntegerSimpledCoder<R extends Reader, W extends Writer> ex
|
||||
return bytes == null ? null : new BigInteger(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* BigInteger 的JsonSimpledCoder实现
|
||||
*
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
*/
|
||||
public static class BigIntegerJsonSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, BigInteger> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> 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));
|
||||
}
|
||||
|
||||
@@ -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<JsonReader, JsonWriter> {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user