optimize: fix StyleCheck errors for hippo4j-agent-bootstrap

pull/1292/head
DDDreame 2 years ago
parent 86f5815682
commit 429e2adaba

@ -58,7 +58,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
*/ */
public class Hippo4jAgent { public class Hippo4jAgent {
private static ILog logger = LogManager.getLogger(Hippo4jAgent.class); private static ILog LOGGER = LogManager.getLogger(Hippo4jAgent.class);
/** /**
* Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins. * Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins.
@ -74,16 +74,16 @@ public class Hippo4jAgent {
return; return;
} finally { } finally {
// refresh logger again after initialization finishes // refresh logger again after initialization finishes
logger = LogManager.getLogger(Hippo4jAgent.class); LOGGER = LogManager.getLogger(Hippo4jAgent.class);
} }
try { try {
pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins()); pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());
} catch (AgentPackageNotFoundException ape) { } catch (AgentPackageNotFoundException ape) {
logger.error(ape, "Locate agent.jar failure. Shutting down."); LOGGER.error(ape, "Locate agent.jar failure. Shutting down.");
return; return;
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Hippo4j agent initialized failure. Shutting down."); LOGGER.error(e, "Hippo4j agent initialized failure. Shutting down.");
return; return;
} }
@ -104,23 +104,23 @@ public class Hippo4jAgent {
try { try {
agentBuilder = BootstrapInstrumentBoost.inject(pluginFinder, instrumentation, agentBuilder, edgeClasses); agentBuilder = BootstrapInstrumentBoost.inject(pluginFinder, instrumentation, agentBuilder, edgeClasses);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Hippo4j agent inject bootstrap instrumentation failure. Shutting down."); LOGGER.error(e, "Hippo4j agent inject bootstrap instrumentation failure. Shutting down.");
return; return;
} }
try { try {
agentBuilder = JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses); agentBuilder = JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Hippo4j agent open read edge in JDK 9+ failure. Shutting down."); LOGGER.error(e, "Hippo4j agent open read edge in JDK 9+ failure. Shutting down.");
return; return;
} }
if (Config.Agent.IS_CACHE_ENHANCED_CLASS) { if (Config.Agent.IS_CACHE_ENHANCED_CLASS) {
try { try {
agentBuilder = agentBuilder.with(new CacheableTransformerDecorator(Config.Agent.CLASS_CACHE_MODE)); agentBuilder = agentBuilder.with(new CacheableTransformerDecorator(Config.Agent.CLASS_CACHE_MODE));
logger.info("Hippo4j agent class cache [{}] activated.", Config.Agent.CLASS_CACHE_MODE); LOGGER.info("Hippo4j agent class cache [{}] activated.", Config.Agent.CLASS_CACHE_MODE);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Hippo4j agent can't active class cache."); LOGGER.error(e, "Hippo4j agent can't active class cache.");
} }
} }
@ -136,13 +136,13 @@ public class Hippo4jAgent {
try { try {
ServiceManager.INSTANCE.boot(); ServiceManager.INSTANCE.boot();
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Hippo4j agent boot failure."); LOGGER.error(e, "Hippo4j agent boot failure.");
} }
try { try {
Class.forName("java.util.concurrent.ThreadPoolExecutor"); Class.forName("java.util.concurrent.ThreadPoolExecutor");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
logger.error(e, "Hippo4j agent boot failure."); LOGGER.error(e, "Hippo4j agent boot failure.");
} }
Runtime.getRuntime() Runtime.getRuntime()
@ -179,13 +179,13 @@ public class Hippo4jAgent {
} }
} }
if (context.isEnhanced()) { if (context.isEnhanced()) {
logger.debug("Finish the prepare stage for {}.", typeDescription.getName()); LOGGER.debug("Finish the prepare stage for {}.", typeDescription.getName());
} }
return newBuilder; return newBuilder;
} }
logger.debug("Matched class {}, but ignore by finding mechanism.", typeDescription.getTypeName()); LOGGER.debug("Matched class {}, but ignore by finding mechanism.", typeDescription.getTypeName());
return builder; return builder;
} }
} }
@ -210,8 +210,8 @@ public class Hippo4jAgent {
final JavaModule module, final JavaModule module,
final boolean loaded, final boolean loaded,
final DynamicType dynamicType) { final DynamicType dynamicType) {
if (logger.isDebugEnable()) { if (LOGGER.isDebugEnable()) {
logger.debug("On Transformation class {}.", typeDescription.getName()); LOGGER.debug("On Transformation class {}.", typeDescription.getName());
} }
InstrumentDebuggingClass.INSTANCE.log(dynamicType); InstrumentDebuggingClass.INSTANCE.log(dynamicType);
@ -231,7 +231,7 @@ public class Hippo4jAgent {
final JavaModule module, final JavaModule module,
final boolean loaded, final boolean loaded,
final Throwable throwable) { final Throwable throwable) {
logger.error("Enhance class " + typeName + " error.", throwable); LOGGER.error("Enhance class " + typeName + " error.", throwable);
} }
@Override @Override
@ -251,7 +251,7 @@ public class Hippo4jAgent {
@Override @Override
public Iterable<? extends List<Class<?>>> onError(int index, List<Class<?>> batch, Throwable throwable, List<Class<?>> types) { public Iterable<? extends List<Class<?>>> onError(int index, List<Class<?>> batch, Throwable throwable, List<Class<?>> types) {
logger.error(throwable, "index={}, batch={}, types={}", index, batch, types); LOGGER.error(throwable, "index={}, batch={}, types={}", index, batch, types);
return Collections.emptyList(); return Collections.emptyList();
} }

@ -31,4 +31,5 @@
<suppress checks="MagicNumber" files="DefaultThreadPoolCheckAlarmHandler.java"/> <suppress checks="MagicNumber" files="DefaultThreadPoolCheckAlarmHandler.java"/>
<suppress checks="TypeName" files="SpringBootConfig.java"/> <suppress checks="TypeName" files="SpringBootConfig.java"/>
<suppress checks="ReturnCount" files="Hippo4jAgent.java"/> <suppress checks="ReturnCount" files="Hippo4jAgent.java"/>
<suppress checks="StaticVariableName" files="Hippo4jAgent.java"/>
</suppressions> </suppressions>

Loading…
Cancel
Save