代码格式优化
This commit is contained in:
@@ -1644,9 +1644,9 @@ public final class Application {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//if ("SHUTDOWN".equalsIgnoreCase(cmd)) {
|
//if ("SHUTDOWN".equalsIgnoreCase(cmd)) {
|
||||||
// System.out.println("--- application not running ---");
|
// System.out .println("--- application not running ---");
|
||||||
//} else {
|
//} else {
|
||||||
System.err.println("--- application not running ---");
|
(System.err).println("--- application not running ---");
|
||||||
//}
|
//}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2083,7 +2083,7 @@ public final class Application {
|
|||||||
cmd = "shutdown";
|
cmd = "shutdown";
|
||||||
}
|
}
|
||||||
if ("help".equalsIgnoreCase(cmd) || "--help".equalsIgnoreCase(cmd) || "-h".equalsIgnoreCase(cmd)) {
|
if ("help".equalsIgnoreCase(cmd) || "--help".equalsIgnoreCase(cmd) || "-h".equalsIgnoreCase(cmd)) {
|
||||||
System.out.println(generateHelp());
|
(System.out).println(generateHelp());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean restart = "restart".equalsIgnoreCase(cmd);
|
boolean restart = "restart".equalsIgnoreCase(cmd);
|
||||||
@@ -2261,7 +2261,7 @@ public final class Application {
|
|||||||
//普通配置项的变更
|
//普通配置项的变更
|
||||||
if (!envRegisterProps.isEmpty()) {
|
if (!envRegisterProps.isEmpty()) {
|
||||||
this.envProperties.putAll(envChangedProps);
|
this.envProperties.putAll(envChangedProps);
|
||||||
envRemovedKeys.forEach(k -> this.envProperties.remove(k));
|
envRemovedKeys.forEach(this.envProperties::remove);
|
||||||
DefaultAnyValue oldConf = (DefaultAnyValue) this.config.getAnyValue("properties");
|
DefaultAnyValue oldConf = (DefaultAnyValue) this.config.getAnyValue("properties");
|
||||||
DefaultAnyValue newConf = new DefaultAnyValue();
|
DefaultAnyValue newConf = new DefaultAnyValue();
|
||||||
oldConf.forEach((k, v) -> newConf.addValue(k, v));
|
oldConf.forEach((k, v) -> newConf.addValue(k, v));
|
||||||
@@ -2604,6 +2604,32 @@ public final class Application {
|
|||||||
logger.log(Level.WARNING, listener.getClass() + " preShutdown erroneous", e);
|
logger.log(Level.WARNING, listener.getClass() + " preShutdown erroneous", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stopServers();
|
||||||
|
destroyMessageAgents();
|
||||||
|
destroyClusterAgent();
|
||||||
|
destroySources();
|
||||||
|
|
||||||
|
if (this.propertiesAgent != null) {
|
||||||
|
long s = System.currentTimeMillis();
|
||||||
|
this.propertiesAgent.destroy(config.getAnyValue("properties"));
|
||||||
|
logger.info(this.propertiesAgent.getClass().getSimpleName() + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
|
}
|
||||||
|
if (this.clientAsyncGroup != null) {
|
||||||
|
long s = System.currentTimeMillis();
|
||||||
|
this.clientAsyncGroup.dispose();
|
||||||
|
logger.info("AsyncGroup destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
|
}
|
||||||
|
if (this.workExecutor != null) {
|
||||||
|
this.workExecutor.shutdownNow();
|
||||||
|
}
|
||||||
|
long intms = System.currentTimeMillis() - f;
|
||||||
|
String ms = String.valueOf(intms);
|
||||||
|
int repeat = ms.length() > 7 ? 0 : (7 - ms.length()) / 2;
|
||||||
|
logger.info(colorMessage(logger, 36, 1, "-".repeat(repeat) + "------------------------ Redkale shutdown in " + ms + " ms " + (ms.length() / 2 == 0 ? " " : "") + "-".repeat(repeat) + "------------------------") + "\r\n" + "\r\n");
|
||||||
|
LoggingBaseHandler.traceEnable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopServers() {
|
||||||
List<NodeServer> localServers = new ArrayList<>(servers); //顺序sncps, others, watchs
|
List<NodeServer> localServers = new ArrayList<>(servers); //顺序sncps, others, watchs
|
||||||
Collections.reverse(localServers); //倒序, 必须让watchs先关闭,watch包含服务发现和注销逻辑
|
Collections.reverse(localServers); //倒序, 必须让watchs先关闭,watch包含服务发现和注销逻辑
|
||||||
if (isCompileMode() && this.messageAgents != null) {
|
if (isCompileMode() && this.messageAgents != null) {
|
||||||
@@ -2627,6 +2653,9 @@ public final class Application {
|
|||||||
shutdownLatch.countDown();
|
shutdownLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyMessageAgents() {
|
||||||
if (this.messageAgents != null) {
|
if (this.messageAgents != null) {
|
||||||
Set<String> names = new HashSet<>();
|
Set<String> names = new HashSet<>();
|
||||||
if (logger.isLoggable(Level.FINER)) {
|
if (logger.isLoggable(Level.FINER)) {
|
||||||
@@ -2639,6 +2668,9 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
logger.info("MessageAgent(names=" + JsonConvert.root().convertTo(names) + ") destroy in " + (System.currentTimeMillis() - s) + " ms");
|
logger.info("MessageAgent(names=" + JsonConvert.root().convertTo(names) + ") destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyClusterAgent() {
|
||||||
if (!isCompileMode() && clusterAgent != null) {
|
if (!isCompileMode() && clusterAgent != null) {
|
||||||
if (logger.isLoggable(Level.FINER)) {
|
if (logger.isLoggable(Level.FINER)) {
|
||||||
logger.log(Level.FINER, "ClusterAgent destroying");
|
logger.log(Level.FINER, "ClusterAgent destroying");
|
||||||
@@ -2648,6 +2680,9 @@ public final class Application {
|
|||||||
clusterAgent.destroy(clusterAgent.getConfig());
|
clusterAgent.destroy(clusterAgent.getConfig());
|
||||||
logger.info("ClusterAgent destroy in " + (System.currentTimeMillis() - s) + " ms");
|
logger.info("ClusterAgent destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroySources() {
|
||||||
for (DataSource source : dataSources) {
|
for (DataSource source : dataSources) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -2657,9 +2692,6 @@ public final class Application {
|
|||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
||||||
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
// } else {
|
|
||||||
// source.getClass().getMethod("close").invoke(source);
|
|
||||||
// RedkaleClassLoader.putReflectionMethod(source.getClass().getName(), source.getClass().getMethod("close"));
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.FINER, source.getClass() + " close DataSource erroneous", e);
|
logger.log(Level.FINER, source.getClass() + " close DataSource erroneous", e);
|
||||||
@@ -2674,32 +2706,11 @@ public final class Application {
|
|||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
||||||
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||||
// } else {
|
|
||||||
// source.getClass().getMethod("close").invoke(source);
|
|
||||||
// RedkaleClassLoader.putReflectionMethod(source.getClass().getName(), source.getClass().getMethod("close"));
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.FINER, source.getClass() + " close CacheSource erroneous", e);
|
logger.log(Level.FINER, source.getClass() + " close CacheSource erroneous", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.propertiesAgent != null) {
|
|
||||||
long s = System.currentTimeMillis();
|
|
||||||
this.propertiesAgent.destroy(config.getAnyValue("properties"));
|
|
||||||
logger.info(this.propertiesAgent.getClass().getSimpleName() + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
|
||||||
}
|
|
||||||
if (this.clientAsyncGroup != null) {
|
|
||||||
long s = System.currentTimeMillis();
|
|
||||||
this.clientAsyncGroup.dispose();
|
|
||||||
logger.info("AsyncGroup destroy in " + (System.currentTimeMillis() - s) + " ms");
|
|
||||||
}
|
|
||||||
if (this.workExecutor != null) {
|
|
||||||
this.workExecutor.shutdownNow();
|
|
||||||
}
|
|
||||||
long intms = System.currentTimeMillis() - f;
|
|
||||||
String ms = String.valueOf(intms);
|
|
||||||
int repeat = ms.length() > 7 ? 0 : (7 - ms.length()) / 2;
|
|
||||||
logger.info(colorMessage(logger, 36, 1, "-".repeat(repeat) + "------------------------ Redkale shutdown in " + ms + " ms " + (ms.length() / 2 == 0 ? " " : "") + "-".repeat(repeat) + "------------------------") + "\r\n" + "\r\n");
|
|
||||||
LoggingBaseHandler.traceEnable = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutorService getWorkExecutor() {
|
public ExecutorService getWorkExecutor() {
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
|
|||||||
Traces.currentTraceid(traceid);
|
Traces.currentTraceid(traceid);
|
||||||
C rs = (C) createClientConnection(connIndex, c).setMaxPipelines(maxPipelines);
|
C rs = (C) createClientConnection(connIndex, c).setMaxPipelines(maxPipelines);
|
||||||
// if (debug) {
|
// if (debug) {
|
||||||
// logger.log(Level.FINEST, Utility.nowMillis() + ": " + Thread.currentThread().getName() + ": " + rs
|
// logger.log(Level.FINEST, Times.nowMillis() + ": " + Thread.currentThread().getName() + ": " + rs
|
||||||
// + ", " + rs.channel + ", 创建TCP连接耗时: (" + (System.currentTimeMillis() - s) + "ms)");
|
// + ", " + rs.channel + ", 创建TCP连接耗时: (" + (System.currentTimeMillis() - s) + "ms)");
|
||||||
// }
|
// }
|
||||||
return rs;
|
return rs;
|
||||||
@@ -451,7 +451,7 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
|
|||||||
} else {
|
} else {
|
||||||
future = future.thenApply(conn -> {
|
future = future.thenApply(conn -> {
|
||||||
// if (debug) {
|
// if (debug) {
|
||||||
// logger.log(Level.FINEST, Utility.nowMillis() + ": " + Thread.currentThread().getName() + ": " + conn
|
// logger.log(Level.FINEST, Times.nowMillis() + ": " + Thread.currentThread().getName() + ": " + conn
|
||||||
// + ", 注册读操作: (" + (System.currentTimeMillis() - s) + "ms) " + conn.channel);
|
// + ", 注册读操作: (" + (System.currentTimeMillis() - s) + "ms) " + conn.channel);
|
||||||
// }
|
// }
|
||||||
conn.channel.readRegister(conn.getCodec()); //不用readRegisterInIOThread,因executeRead可能会异步
|
conn.channel.readRegister(conn.getCodec()); //不用readRegisterInIOThread,因executeRead可能会异步
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.util.TimeZone;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
* @since 2.8.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
public class Times {
|
public abstract class Times {
|
||||||
|
|
||||||
private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset();
|
private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user