This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new ab51ee2a08a Refactor agent-logging-base (#22940)
ab51ee2a08a is described below
commit ab51ee2a08a4c45d0b56ed07c5f97f404c6bb3da
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 18 00:14:20 2022 +0800
Refactor agent-logging-base (#22940)
* Refactor agent-logging-base
---
.../BaseLoggingAdvisorDefinitionService.java | 2 +-
.../BaseLoggingPluginBootService.java | 2 +-
.../LogTimeRecorder.java} | 33 ++++++++++------------
.../base/advice/MetaDataContextsFactoryAdvice.java | 13 +++------
...here.agent.spi.advisor.AdvisorDefinitionService | 2 +-
...ardingsphere.agent.spi.plugin.PluginBootService | 2 +-
6 files changed, 23 insertions(+), 31 deletions(-)
diff --git
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingAdvisorDefinitionService.java
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingAdvisorDefinitionService.java
similarity index 97%
rename from
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingAdvisorDefinitionService.java
rename to
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingAdvisorDefinitionService.java
index 9ea2aebc250..7da53d133ad 100644
---
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/definition/BaseLoggingAdvisorDefinitionService.java
+++
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingAdvisorDefinitionService.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.logging.base.definition;
+package org.apache.shardingsphere.agent.plugin.logging.base;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
diff --git
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingPluginBootService.java
similarity index 95%
rename from
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
rename to
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingPluginBootService.java
index 554cbb6d0c1..870fbf0eb36 100644
---
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/service/BaseLoggingPluginBootService.java
+++
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/BaseLoggingPluginBootService.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.logging.base.service;
+package org.apache.shardingsphere.agent.plugin.logging.base;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
import org.apache.shardingsphere.agent.spi.plugin.PluginBootService;
diff --git
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/threadlocal/ElapsedTimeThreadLocal.java
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/LogTimeRecorder.java
similarity index 61%
rename from
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/threadlocal/ElapsedTimeThreadLocal.java
rename to
agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/LogTimeRecorder.java
index 3141a8db237..538531a893f 100644
---
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/threadlocal/ElapsedTimeThreadLocal.java
+++
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/LogTimeRecorder.java
@@ -15,42 +15,39 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.plugin.logging.base.threadlocal;
+package org.apache.shardingsphere.agent.plugin.logging.base.advice;
/**
- * The enum Elapsed time thread local.
+ * Log time recorder.
*/
-public enum ElapsedTimeThreadLocal {
+public enum LogTimeRecorder {
- /**
- * Instance elapsed time thread local.
- */
INSTANCE;
- private static final ThreadLocal<Long> CURRENT_LOCAL = new ThreadLocal<>();
+ private static final ThreadLocal<Long> CURRENT_RECORDER = new
ThreadLocal<>();
/**
- * Set.
+ * Record time.
*
- * @param time the time
+ * @param time time
*/
- public void set(final long time) {
- CURRENT_LOCAL.set(time);
+ public void record(final long time) {
+ CURRENT_RECORDER.set(time);
}
/**
- * Get long.
+ * Get elapsed time.
*
- * @return the long
+ * @return elapsed time
*/
- public Long get() {
- return CURRENT_LOCAL.get();
+ public long getElapsedTime() {
+ return System.currentTimeMillis() - CURRENT_RECORDER.get();
}
/**
- * Remove.
+ * Clean recorded time.
*/
- public void remove() {
- CURRENT_LOCAL.remove();
+ public void cleanRecordedTime() {
+ CURRENT_RECORDER.remove();
}
}
diff --git
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/MetaDataContextsFactoryAdvice.java
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/MetaDataContextsFactoryAdvice.java
index 4bd08e0f8f7..4e85744ef87 100644
---
a/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/MetaDataContextsFactoryAdvice.java
+++
b/agent/plugins/logging/base/src/main/java/org/apache/shardingsphere/agent/plugin/logging/base/advice/MetaDataContextsFactoryAdvice.java
@@ -20,28 +20,23 @@ package
org.apache.shardingsphere.agent.plugin.logging.base.advice;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.advice.type.StaticMethodAdvice;
import org.apache.shardingsphere.agent.advice.MethodInvocationResult;
-import
org.apache.shardingsphere.agent.plugin.logging.base.threadlocal.ElapsedTimeThreadLocal;
import java.lang.reflect.Method;
/**
- * Schema meta data loader advice executor.
+ * Meta data contexts factory advice.
*/
@Slf4j
public final class MetaDataContextsFactoryAdvice implements StaticMethodAdvice
{
@Override
public void beforeMethod(final Class<?> clazz, final Method method, final
Object[] args, final MethodInvocationResult result) {
- ElapsedTimeThreadLocal.INSTANCE.set(System.currentTimeMillis());
+ LogTimeRecorder.INSTANCE.record(System.currentTimeMillis());
}
@Override
public void afterMethod(final Class<?> clazz, final Method method, final
Object[] args, final MethodInvocationResult result) {
- try {
- long elapsedTime = System.currentTimeMillis() -
ElapsedTimeThreadLocal.INSTANCE.get();
- log.info("Build meta data contexts finished, cost {}
milliseconds", elapsedTime);
- } finally {
- ElapsedTimeThreadLocal.INSTANCE.remove();
- }
+ log.info("Build meta data contexts finished, cost {} milliseconds.",
LogTimeRecorder.INSTANCE.getElapsedTime());
+ LogTimeRecorder.INSTANCE.cleanRecordedTime();
}
}
diff --git
a/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.advisor.AdvisorDefinitionService
b/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.advisor.AdvisorDefinitionService
index fee68b71e4d..65d08e2d764 100644
---
a/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.advisor.AdvisorDefinitionService
+++
b/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.advisor.AdvisorDefinitionService
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.agent.plugin.logging.base.definition.BaseLoggingAdvisorDefinitionService
+org.apache.shardingsphere.agent.plugin.logging.base.BaseLoggingAdvisorDefinitionService
diff --git
a/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.plugin.PluginBootService
b/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.plugin.PluginBootService
index 181b006c8a5..a8b7db5f850 100644
---
a/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.plugin.PluginBootService
+++
b/agent/plugins/logging/base/src/main/resources/META-INF/services/org.apache.shardingsphere.agent.spi.plugin.PluginBootService
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.agent.plugin.logging.base.service.BaseLoggingPluginBootService
+org.apache.shardingsphere.agent.plugin.logging.base.BaseLoggingPluginBootService