This commit is contained in:
Redkale
2017-05-29 09:17:54 +08:00
parent 1d1b732a74
commit 0da74be2fa
2 changed files with 12 additions and 13 deletions

View File

@@ -232,7 +232,7 @@ public final class Application {
} }
this.logger = Logger.getLogger(this.getClass().getSimpleName()); this.logger = Logger.getLogger(this.getClass().getSimpleName());
this.serversLatch = new CountDownLatch(config.getAnyValues("server").length + 1); this.serversLatch = new CountDownLatch(config.getAnyValues("server").length + 1);
logger.log(Level.INFO, "------------------------------- Redkale -------------------------------"); logger.log(Level.INFO, "------------------------------- Redkale 1.8 -------------------------------");
//------------------配置 <transport> 节点 ------------------ //------------------配置 <transport> 节点 ------------------
ObjectPool<ByteBuffer> transportPool = null; ObjectPool<ByteBuffer> transportPool = null;
ExecutorService transportExec = null; ExecutorService transportExec = null;
@@ -295,10 +295,6 @@ public final class Application {
return startTime; return startTime;
} }
private void initLogging() {
}
public void init() throws Exception { public void init() throws Exception {
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "" + Runtime.getRuntime().availableProcessors() * 4); System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "" + Runtime.getRuntime().availableProcessors() * 4);
System.setProperty("convert.bson.tiny", "true"); System.setProperty("convert.bson.tiny", "true");
@@ -315,7 +311,7 @@ public final class Application {
String lib = config.getValue("lib", "").trim().replace("${APP_HOME}", homepath); String lib = config.getValue("lib", "").trim().replace("${APP_HOME}", homepath);
lib = lib.isEmpty() ? (homepath + "/conf") : (lib + ";" + homepath + "/conf"); lib = lib.isEmpty() ? (homepath + "/conf") : (lib + ";" + homepath + "/conf");
Server.loadLib(logger, lib); Server.loadLib(logger, lib);
initLogging();
//------------------------------------------------------------------------ //------------------------------------------------------------------------
final AnyValue resources = config.getAnyValue("resources"); final AnyValue resources = config.getAnyValue("resources");
if (resources != null) { if (resources != null) {
@@ -569,7 +565,7 @@ public final class Application {
runServers(timecd, others); runServers(timecd, others);
runServers(timecd, watchs); //必须在所有server都启动后再启动 runServers(timecd, watchs); //必须在所有server都启动后再启动
timecd.await(); timecd.await();
logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms"); logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms\r\n");
if (!singletonrun) this.serversLatch.await(); if (!singletonrun) this.serversLatch.await();
} }

View File

@@ -499,7 +499,7 @@ public final class ResourceFactory {
private static class ResourceElement<T> { private static class ResourceElement<T> {
private static final HashMap<Class, Method> listenerMethods = new HashMap<>(); //不使用ConcurrentHashMap是因为value不能存null private static final HashMap<String, Method> listenerMethods = new HashMap<>(); //不使用ConcurrentHashMap是因为value不能存null
public final WeakReference<T> dest; public final WeakReference<T> dest;
@@ -515,24 +515,27 @@ public final class ResourceFactory {
this.fieldType = field.getType(); this.fieldType = field.getType();
Class t = dest.getClass(); Class t = dest.getClass();
String tn = t.getName(); String tn = t.getName();
this.listener = tn.startsWith("java.") || tn.startsWith("javax.") ? null : findListener(t); this.listener = tn.startsWith("java.") || tn.startsWith("javax.") ? null : findListener(t, field.getType());
} }
private static synchronized Method findListener(Class clazz) { private static synchronized Method findListener(Class clazz, Class fieldType) {
Class loop = clazz; Class loop = clazz;
Method m = null; Method m = listenerMethods.get(clazz.getName() + "-" + fieldType.getName());
if (m != null) return m;
do { do {
for (Method method : loop.getDeclaredMethods()) { for (Method method : loop.getDeclaredMethods()) {
if (method.getAnnotation(ResourceListener.class) != null if (method.getAnnotation(ResourceListener.class) != null
&& method.getParameterCount() == 3 && method.getParameterCount() == 3
&& String.class.isAssignableFrom(method.getParameterTypes()[0])) { && String.class.isAssignableFrom(method.getParameterTypes()[0])
&& method.getParameterTypes()[1] == method.getParameterTypes()[2]
&& method.getParameterTypes()[1].isAssignableFrom(fieldType)) {
m = method; m = method;
m.setAccessible(true); m.setAccessible(true);
break; break;
} }
} }
} while ((loop = loop.getSuperclass()) != Object.class); } while ((loop = loop.getSuperclass()) != Object.class);
listenerMethods.put(clazz, m); listenerMethods.put(clazz.getName() + "-" + fieldType.getName(), m);
return m; return m;
} }
} }