This commit is contained in:
Redkale
2020-06-04 21:32:18 +08:00
parent 06b7274364
commit 681e389f19
2 changed files with 22 additions and 21 deletions

View File

@@ -496,7 +496,7 @@ public final class Application {
pidstr = "APP_PID = " + pid + "\r\n";
} catch (Throwable t) {
}
logger.log(Level.INFO, pidstr + "APP_JAVA = " + System.getProperty("java.version") + "\r\n" + RESNAME_APP_ADDR + " = " + this.localAddress.getHostAddress() + "\r\n" + RESNAME_APP_HOME + " = " + homepath + "\r\n" + RESNAME_APP_CONF + " = " + confpath);
logger.log(Level.INFO, pidstr + "APP_JAVA = " + System.getProperty("java.version") + "\r\n" + RESNAME_APP_NODEID + " = " + this.nodeid + "\r\n" + RESNAME_APP_ADDR + " = " + this.localAddress.getHostAddress() + "\r\n" + RESNAME_APP_HOME + " = " + homepath + "\r\n" + RESNAME_APP_CONF + " = " + confpath);
String lib = config.getValue("lib", "${APP_HOME}/libs/*").trim().replace("${APP_HOME}", homepath);
lib = lib.isEmpty() ? confpath : (lib + ";" + confpath);
Server.loadLib(classLoader, logger, lib);
@@ -782,7 +782,13 @@ public final class Application {
long s = System.currentTimeMillis();
final StringBuffer sb = new StringBuffer();
for (MessageAgent agent : this.messageAgents) {
agent.start(sb).join();
Map<String, Long> map = agent.start().join();
AtomicInteger maxlen = new AtomicInteger();
map.keySet().forEach(str -> {
if (str.length() > maxlen.get()) maxlen.set(str.length());
});
map.forEach((topic, ms) -> sb.append("MessageConsumer(topic=").append(alignString(topic, maxlen.get())).append(") init and start in ").append(ms).append(" ms\r\n")
);
}
if (sb.length() > 0) logger.info(sb.toString().trim());
logger.info(this.getClass().getSimpleName() + " MessageAgent init in " + (System.currentTimeMillis() - s) + " ms");
@@ -793,6 +799,15 @@ public final class Application {
if (!singletonrun) this.serversLatch.await();
}
private static String alignString(String value, int maxlen) {
StringBuilder sb = new StringBuilder(maxlen);
sb.append(value);
for (int i = 0; i < maxlen - value.length(); i++) {
sb.append(' ');
}
return sb.toString();
}
// private void clearPersistData() {
// File cachedir = new File(home, "cache");
// if (!cachedir.isDirectory()) return;

View File

@@ -70,20 +70,15 @@ public abstract class MessageAgent {
this.sncpRespStartms = System.currentTimeMillis() - s;
}
public CompletableFuture<Void> start(final StringBuffer sb) {
AtomicInteger maxlen = new AtomicInteger(sncpRespConsumer == null ? 0 : sncpRespConsumer.topic.length());
this.messageNodes.values().forEach(node -> {
if (node.consumer.topic.length() > maxlen.get()) maxlen.set(node.consumer.topic.length());
});
if (this.sncpRespStartms >= 0) {
if (sb != null) sb.append("MessageConsumer(topic=").append(fillString(this.sncpRespConsumer.topic, maxlen.get())).append(") init and start in ").append(this.sncpRespStartms).append(" ms\r\n");
}
public CompletableFuture<Map<String, Long>> start() {
final LinkedHashMap<String, Long> map = new LinkedHashMap<>();
if (this.sncpRespStartms >= 0) map.put(this.sncpRespConsumer.topic, this.sncpRespStartms);
this.messageNodes.values().forEach(node -> {
long s = System.currentTimeMillis();
node.consumer.startup().join();
if (sb != null) sb.append("MessageConsumer(topic=").append(fillString(node.consumer.topic, maxlen.get())).append(") init and start in ").append(System.currentTimeMillis() - s).append(" ms\r\n");
map.put(node.consumer.topic, System.currentTimeMillis() - s);
});
return CompletableFuture.completedFuture(null);
return CompletableFuture.completedFuture(map);
}
public CompletableFuture<Void> stop() {
@@ -217,15 +212,6 @@ public abstract class MessageAgent {
return protocol + ".resp.node" + nodeid;
}
protected static String fillString(String value, int maxlen) {
StringBuilder sb = new StringBuilder(maxlen);
sb.append(value);
for (int i = 0; i < maxlen - value.length(); i++) {
sb.append(' ');
}
return sb.toString();
}
protected static class MessageNode {
public final NodeServer server;