You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2018/04/10 08:36:45 UTC
[incubator-skywalking] branch master updated: fix #1055 and make
code more readable (#1057)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 8abb01d fix #1055 and make code more readable (#1057)
8abb01d is described below
commit 8abb01dce255ce4ef12a599eb43c5873f92fe851
Author: lican <29...@qq.com>
AuthorDate: Tue Apr 10 16:36:41 2018 +0800
fix #1055 and make code more readable (#1057)
---
.../skywalking/apm/agent/SkyWalkingAgent.java | 107 ++++++++++++---------
1 file changed, 63 insertions(+), 44 deletions(-)
diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
index f98a2b8..c224aa5 100644
--- a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
+++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
@@ -59,72 +59,91 @@ public class SkyWalkingAgent {
pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());
- ServiceManager.INSTANCE.boot();
} catch (Exception e) {
logger.error(e, "Skywalking agent initialized failure. Shutting down.");
return;
}
+ new AgentBuilder.Default()
+ .type(pluginFinder.buildMatch())
+ .transform(new Transformer(pluginFinder))
+ .with(new Listener())
+ .installOn(instrumentation);
+
+ try {
+ ServiceManager.INSTANCE.boot();
+ } catch (Exception e) {
+ logger.error(e, "Skywalking agent boot failure.");
+ }
+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override public void run() {
ServiceManager.INSTANCE.shutdown();
}
}, "skywalking service shutdown thread"));
+ }
- new AgentBuilder.Default().type(pluginFinder.buildMatch()).transform(new AgentBuilder.Transformer() {
- @Override
- public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription,
- ClassLoader classLoader, JavaModule module) {
- List<AbstractClassEnhancePluginDefine> pluginDefines = pluginFinder.find(typeDescription, classLoader);
- if (pluginDefines.size() > 0) {
- DynamicType.Builder<?> newBuilder = builder;
- EnhanceContext context = new EnhanceContext();
- for (AbstractClassEnhancePluginDefine define : pluginDefines) {
- DynamicType.Builder<?> possibleNewBuilder = define.define(typeDescription.getTypeName(), newBuilder, classLoader, context);
- if (possibleNewBuilder != null) {
- newBuilder = possibleNewBuilder;
- }
- }
- if (context.isEnhanced()) {
- logger.debug("Finish the prepare stage for {}.", typeDescription.getName());
- }
+ private static class Transformer implements AgentBuilder.Transformer {
+ private PluginFinder pluginFinder;
- return newBuilder;
+ Transformer(PluginFinder pluginFinder) {
+ this.pluginFinder = pluginFinder;
+ }
+
+ @Override
+ public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
+ List<AbstractClassEnhancePluginDefine> pluginDefines = pluginFinder.find(typeDescription, classLoader);
+ if (pluginDefines.size() > 0) {
+ DynamicType.Builder<?> newBuilder = builder;
+ EnhanceContext context = new EnhanceContext();
+ for (AbstractClassEnhancePluginDefine define : pluginDefines) {
+ DynamicType.Builder<?> possibleNewBuilder = define.define(typeDescription.getTypeName(), newBuilder, classLoader, context);
+ if (possibleNewBuilder != null) {
+ newBuilder = possibleNewBuilder;
+ }
+ }
+ if (context.isEnhanced()) {
+ logger.debug("Finish the prepare stage for {}.", typeDescription.getName());
}
- logger.debug("Matched class {}, but ignore by finding mechanism.", typeDescription.getTypeName());
- return builder;
+ return newBuilder;
}
- }).with(new AgentBuilder.Listener() {
- @Override
- public void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {
- }
+ logger.debug("Matched class {}, but ignore by finding mechanism.", typeDescription.getTypeName());
+ return builder;
+ }
+ }
- @Override
- public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
- boolean loaded, DynamicType dynamicType) {
- if (logger.isDebugEnable()) {
- logger.debug("On Transformation class {}.", typeDescription.getName());
- }
+ private static class Listener implements AgentBuilder.Listener {
+ @Override
+ public void onDiscovery(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {
- InstrumentDebuggingClass.INSTANCE.log(typeDescription, dynamicType);
+ }
+
+ @Override
+ public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
+ boolean loaded, DynamicType dynamicType) {
+ if (logger.isDebugEnable()) {
+ logger.debug("On Transformation class {}.", typeDescription.getName());
}
- @Override
- public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
- boolean loaded) {
+ InstrumentDebuggingClass.INSTANCE.log(typeDescription, dynamicType);
+ }
+
+ @Override
+ public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module,
+ boolean loaded) {
- }
+ }
- @Override public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded,
- Throwable throwable) {
- logger.error("Enhance class " + typeName + " error.", throwable);
- }
+ @Override
+ public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded,
+ Throwable throwable) {
+ logger.error("Enhance class " + typeName + " error.", throwable);
+ }
- @Override
- public void onComplete(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {
- }
- }).installOn(instrumentation);
+ @Override
+ public void onComplete(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {
+ }
}
}
--
To stop receiving notification emails like this one, please contact
wusheng@apache.org.