mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-09 04:46:06 +10:00
Merge branch 'master' of http://yobi.navercorp.com/pinpoint/pinpoint
Conflicts: bootstrap/src/main/java/com/nhn/pinpoint/bootstrap/config/ProfilerConfig.java bootstrap/src/main/java/com/nhn/pinpoint/bootstrap/interceptor/InterceptorRegistry.java profiler/src/main/java/com/nhn/pinpoint/profiler/modifier/DefaultModifierRegistry.java testweb/src/main/resources/applicationContext-testweb.xml
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
/.settings/
|
||||
/.idea
|
||||
/*.iml
|
||||
/deploy
|
||||
|
||||
+49
-49
@@ -1,50 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project name="pinpoint-bootstrap-build" basedir="." default="deploy">
|
||||
<property environment="env"/>
|
||||
|
||||
<property name="pinpoint.version" value="1.0.2"/>
|
||||
|
||||
<property name="pinpoint.bootstrap.jar" value="pinpoint-bootstrap-${pinpoint.version}.jar"/>
|
||||
|
||||
|
||||
<property name="maven.dir" value="${env.M2_HOME}"/>
|
||||
<property name="agent.dir" value="${basedir}/../deploy/pinpoint-agent/"/>
|
||||
<property name="target.dir" value="${basedir}/target/"/>
|
||||
|
||||
|
||||
<target name="deploy" depends="mvn.build.install, copy.agent">
|
||||
</target>
|
||||
|
||||
<target name="copy.agent">
|
||||
<copy file="${target.dir}/${pinpoint.bootstrap.jar}" tofile="${agent.dir}/${pinpoint.bootstrap.jar}" overwrite="true">
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="mvn.build.install">
|
||||
<exec executable="${maven.dir}/bin/mvn.bat ">
|
||||
<arg value="-Dmaven.test.skip=true"/>
|
||||
<arg value="clean"/>
|
||||
<arg value="install"/>
|
||||
<!--<arg value="compile"/>-->
|
||||
<!--<arg value="jar:jar"/>-->
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="mvn.build.package">
|
||||
<exec executable="${maven.dir}/bin/mvn.bat ">
|
||||
<arg value="-Dmaven.test.skip=true"/>
|
||||
<arg value="package"/>
|
||||
<!--<arg value="compile"/>-->
|
||||
<!--<arg value="jar:jar"/>-->
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
|
||||
<!--<target name="clean" >-->
|
||||
<!--<delete dir="${class.dir}/class/*"/>-->
|
||||
<!--<delete dir="${jar.dir}/jar/*"/>-->
|
||||
<!--<delete dir="${javadoc.dir}/doc/*"/>-->
|
||||
<!--</target>-->
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project name="pinpoint-bootstrap-build" basedir="." default="deploy">
|
||||
<property environment="env"/>
|
||||
|
||||
<property name="pinpoint.version" value="1.0.2"/>
|
||||
|
||||
<property name="pinpoint.bootstrap.jar" value="pinpoint-bootstrap-${pinpoint.version}.jar"/>
|
||||
|
||||
|
||||
<property name="maven.dir" value="${env.M2_HOME}"/>
|
||||
<property name="agent.dir" value="${basedir}/../deploy/pinpoint-agent/"/>
|
||||
<property name="target.dir" value="${basedir}/target/"/>
|
||||
|
||||
|
||||
<target name="deploy" depends="mvn.build.install, copy.agent">
|
||||
</target>
|
||||
|
||||
<target name="copy.agent">
|
||||
<copy file="${target.dir}/${pinpoint.bootstrap.jar}" tofile="${agent.dir}/${pinpoint.bootstrap.jar}" overwrite="true">
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="mvn.build.install">
|
||||
<exec executable="${maven.dir}/bin/mvn.bat ">
|
||||
<arg value="-Dmaven.test.skip=true"/>
|
||||
<arg value="clean"/>
|
||||
<arg value="install"/>
|
||||
<!--<arg value="compile"/>-->
|
||||
<!--<arg value="jar:jar"/>-->
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="mvn.build.package">
|
||||
<exec executable="${maven.dir}/bin/mvn.bat ">
|
||||
<arg value="-Dmaven.test.skip=true"/>
|
||||
<arg value="package"/>
|
||||
<!--<arg value="compile"/>-->
|
||||
<!--<arg value="jar:jar"/>-->
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
|
||||
<!--<target name="clean" >-->
|
||||
<!--<delete dir="${class.dir}/class/*"/>-->
|
||||
<!--<delete dir="${jar.dir}/jar/*"/>-->
|
||||
<!--<delete dir="${javadoc.dir}/doc/*"/>-->
|
||||
<!--</target>-->
|
||||
|
||||
</project>
|
||||
@@ -1,13 +1,13 @@
|
||||
<FindBugsFilter>
|
||||
<!--
|
||||
<Match> <Class name="com.foobar.ClassWithSomeBugsMatched" /> <Bug
|
||||
code="DE,UrF,SIC" /> </Match>
|
||||
-->
|
||||
<!--<Match>-->
|
||||
<!--<Class name="com.nhncorp.usf.core.result.RedirectResult" />-->
|
||||
<!--<Bug pattern="DM_CONVERT_CASE" />-->
|
||||
<!--</Match>-->
|
||||
<!--
|
||||
Match all XYZ violations. <Match> <Bug code="XYZ" /> </Match>
|
||||
-->
|
||||
<FindBugsFilter>
|
||||
<!--
|
||||
<Match> <Class name="com.foobar.ClassWithSomeBugsMatched" /> <Bug
|
||||
code="DE,UrF,SIC" /> </Match>
|
||||
-->
|
||||
<!--<Match>-->
|
||||
<!--<Class name="com.nhncorp.usf.core.result.RedirectResult" />-->
|
||||
<!--<Bug pattern="DM_CONVERT_CASE" />-->
|
||||
<!--</Match>-->
|
||||
<!--
|
||||
Match all XYZ violations. <Match> <Bug code="XYZ" /> </Match>
|
||||
-->
|
||||
</FindBugsFilter>
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.nhn.pinpoint;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class ProductInfo {
|
||||
public static final String NAME = "pinpoint";
|
||||
public static final String CAMEL_NAME = "Pinpoint";
|
||||
}
|
||||
package com.nhn.pinpoint;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class ProductInfo {
|
||||
public static final String NAME = "pinpoint";
|
||||
public static final String CAMEL_NAME = "Pinpoint";
|
||||
}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Agent {
|
||||
// TODO 필요없을것 같음 started를 start로 바꿔도 될 듯...
|
||||
void start();
|
||||
|
||||
void started();
|
||||
|
||||
void stop();
|
||||
|
||||
void addConnector(String protocol, int port);
|
||||
|
||||
TraceContext getTraceContext();
|
||||
|
||||
ProfilerConfig getProfilerConfig();
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public interface Agent {
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
void addConnector(String protocol, int port);
|
||||
|
||||
TraceContext getTraceContext();
|
||||
|
||||
ProfilerConfig getProfilerConfig();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,101 +1,101 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class AgentClassLoader {
|
||||
|
||||
private URLClassLoader classLoader;
|
||||
|
||||
private String bootClass;
|
||||
|
||||
private Agent agentBootStrap;
|
||||
private ContextClassLoaderExecuteTemplate executeTemplate;
|
||||
|
||||
public AgentClassLoader(URL[] urls) {
|
||||
if (urls == null) {
|
||||
throw new NullPointerException("urls");
|
||||
}
|
||||
|
||||
ClassLoader bootStrapClassLoader = AgentClassLoader.class.getClassLoader();
|
||||
this.classLoader = new PinpointURLClassLoader(urls, bootStrapClassLoader);
|
||||
|
||||
this.executeTemplate = new ContextClassLoaderExecuteTemplate(classLoader);
|
||||
}
|
||||
|
||||
public void setBootClass(String bootClass) {
|
||||
this.bootClass = bootClass;
|
||||
}
|
||||
|
||||
public void boot(final String agentArgs, final Instrumentation instrumentation, final ProfilerConfig profilerConfig) {
|
||||
|
||||
final Class<?> bootStrapClazz = getBootStrapClass();
|
||||
|
||||
agentBootStrap = (Agent) executeTemplate.execute(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
Constructor<?> constructor = bootStrapClazz.getConstructor(String.class, Instrumentation.class, ProfilerConfig.class);
|
||||
return constructor.newInstance(agentArgs, instrumentation, profilerConfig);
|
||||
} catch (InstantiationException e) {
|
||||
throw new BootStrapException("boot create fail. Caused:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BootStrapException("boot method invoke fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Class<?> getBootStrapClass() {
|
||||
try {
|
||||
return this.classLoader.loadClass(bootClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new BootStrapException("boot class not found. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Object initializeLoggerBinder() {
|
||||
if (agentBootStrap != null) {
|
||||
return reflectionInvoke(this.agentBootStrap, "initializeLogger", null, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object reflectionInvoke(Object target, String method, Class[] type, final Object[] args) {
|
||||
final Method findMethod = findMethod(target.getClass(), method, type);
|
||||
return executeTemplate.execute(new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
try {
|
||||
return findMethod.invoke(agentBootStrap, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new BootStrapException(findMethod.getName() + "() fail. Caused:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BootStrapException("boot method invoke fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Method findMethod(Class<?> clazz, String method, Class[] type) {
|
||||
try {
|
||||
return clazz.getDeclaredMethod(method, type);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new BootStrapException("(" + method + ") boot method not found. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class AgentClassLoader {
|
||||
|
||||
private URLClassLoader classLoader;
|
||||
|
||||
private String bootClass;
|
||||
|
||||
private Agent agentBootStrap;
|
||||
private ContextClassLoaderExecuteTemplate executeTemplate;
|
||||
|
||||
public AgentClassLoader(URL[] urls) {
|
||||
if (urls == null) {
|
||||
throw new NullPointerException("urls");
|
||||
}
|
||||
|
||||
ClassLoader bootStrapClassLoader = AgentClassLoader.class.getClassLoader();
|
||||
this.classLoader = new PinpointURLClassLoader(urls, bootStrapClassLoader);
|
||||
|
||||
this.executeTemplate = new ContextClassLoaderExecuteTemplate(classLoader);
|
||||
}
|
||||
|
||||
public void setBootClass(String bootClass) {
|
||||
this.bootClass = bootClass;
|
||||
}
|
||||
|
||||
public void boot(final String agentArgs, final Instrumentation instrumentation, final ProfilerConfig profilerConfig) {
|
||||
|
||||
final Class<?> bootStrapClazz = getBootStrapClass();
|
||||
|
||||
agentBootStrap = (Agent) executeTemplate.execute(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
Constructor<?> constructor = bootStrapClazz.getConstructor(String.class, Instrumentation.class, ProfilerConfig.class);
|
||||
return constructor.newInstance(agentArgs, instrumentation, profilerConfig);
|
||||
} catch (InstantiationException e) {
|
||||
throw new BootStrapException("boot create fail. Caused:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BootStrapException("boot method invoke fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Class<?> getBootStrapClass() {
|
||||
try {
|
||||
return this.classLoader.loadClass(bootClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new BootStrapException("boot class not found. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Object initializeLoggerBinder() {
|
||||
if (agentBootStrap != null) {
|
||||
return reflectionInvoke(this.agentBootStrap, "initializeLogger", null, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object reflectionInvoke(Object target, String method, Class[] type, final Object[] args) {
|
||||
final Method findMethod = findMethod(target.getClass(), method, type);
|
||||
return executeTemplate.execute(new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
try {
|
||||
return findMethod.invoke(agentBootStrap, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new BootStrapException(findMethod.getName() + "() fail. Caused:" + e.getMessage(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BootStrapException("boot method invoke fail. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Method findMethod(Class<?> clazz, String method, Class[] type) {
|
||||
try {
|
||||
return clazz.getDeclaredMethod(method, type);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new BootStrapException("(" + method + ") boot method not found. Caused:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class BootStrapException extends PinpointException {
|
||||
|
||||
public BootStrapException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BootStrapException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.exception.PinpointException;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class BootStrapException extends PinpointException {
|
||||
|
||||
public BootStrapException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BootStrapException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ClassPathResolver {
|
||||
|
||||
private final Logger logger = Logger.getLogger(this.getClass().getName());
|
||||
|
||||
private static final Pattern DEFAULT_AGENT_PATTERN = Pattern.compile("pinpoint-bootstrap(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar");
|
||||
|
||||
private String classPath;
|
||||
|
||||
private String agentJarName;
|
||||
private String agentJarFullPath;
|
||||
private String agentDirPath;
|
||||
private Pattern agentPattern;
|
||||
private List<String> fileExtensionList;
|
||||
|
||||
public ClassPathResolver() {
|
||||
this(getClassPathFromSystemProperty());
|
||||
}
|
||||
|
||||
|
||||
public ClassPathResolver(String classPath) {
|
||||
this.classPath = classPath;
|
||||
this.agentPattern = DEFAULT_AGENT_PATTERN;
|
||||
this.fileExtensionList = getDefaultFileExtensionList();
|
||||
}
|
||||
|
||||
public List<String> getDefaultFileExtensionList() {
|
||||
List<String> extensionList = new ArrayList<String>();
|
||||
extensionList.add("jar");
|
||||
extensionList.add("xml");
|
||||
extensionList.add("properties");
|
||||
return extensionList;
|
||||
}
|
||||
|
||||
public ClassPathResolver(String classPath, String agentPattern) {
|
||||
this.classPath = classPath;
|
||||
this.agentPattern = Pattern.compile(agentPattern);
|
||||
}
|
||||
|
||||
public void setClassPath(String classPath) {
|
||||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
public void setClassPathFromSystemProperty() {
|
||||
this.classPath = getClassPathFromSystemProperty();
|
||||
}
|
||||
|
||||
public static String getClassPathFromSystemProperty() {
|
||||
return System.getProperty("java.class.path");
|
||||
}
|
||||
|
||||
public boolean findAgentJar() {
|
||||
Matcher matcher = agentPattern.matcher(classPath);
|
||||
if (!matcher.find()) {
|
||||
return false;
|
||||
}
|
||||
this.agentJarName = parseAgentJar(matcher);
|
||||
this.agentJarFullPath = parseAgentJarPath(classPath, agentJarName);
|
||||
if (agentJarFullPath == null) {
|
||||
return false;
|
||||
}
|
||||
this.agentDirPath = parseAgentDirPath(agentJarFullPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String parseAgentJar(Matcher matcher) {
|
||||
int start = matcher.start();
|
||||
int end = matcher.end();
|
||||
return this.classPath.substring(start, end);
|
||||
}
|
||||
|
||||
|
||||
public String getAgentJarName() {
|
||||
return this.agentJarName;
|
||||
}
|
||||
|
||||
|
||||
private String parseAgentJarPath(String classPath, String agentJar) {
|
||||
String[] classPathList = classPath.split(File.pathSeparator);
|
||||
for (String findPath : classPathList) {
|
||||
boolean find = findPath.contains(agentJar);
|
||||
if (find) {
|
||||
return findPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAgentJarFullPath() {
|
||||
return agentJarFullPath;
|
||||
}
|
||||
|
||||
public String getAgentLibPath() {
|
||||
return this.agentDirPath + File.separator + "lib";
|
||||
}
|
||||
|
||||
public String getAgentLogFilePath() {
|
||||
return this.agentDirPath + File.separator + "log";
|
||||
}
|
||||
|
||||
public List<URL> resolveLib() {
|
||||
String agentLibPath = getAgentLibPath();
|
||||
File libDir = new File(agentLibPath);
|
||||
if (!libDir.exists()) {
|
||||
logger.warning(agentLibPath + " not found");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (!libDir.isDirectory()) {
|
||||
logger.warning(agentLibPath + " not Directory");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<URL> jarURLList = new ArrayList<URL>();
|
||||
|
||||
final File[] findJarList = findjar(libDir);
|
||||
if (findJarList != null) {
|
||||
for (File file : findJarList) {
|
||||
URL url = toURI(file);
|
||||
if (url != null) {
|
||||
jarURLList.add(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// agentDir 패스도 넣어야 xml을 찾을 때 해당 패스에서 찾음.
|
||||
URL agentDirUri = toURI(new File(agentLibPath));
|
||||
if (agentDirUri != null) {
|
||||
jarURLList.add(agentDirUri);
|
||||
}
|
||||
|
||||
return jarURLList;
|
||||
}
|
||||
|
||||
private URL toURI(File file) {
|
||||
URI uri = file.toURI();
|
||||
try {
|
||||
return uri.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
logger.log(Level.WARNING, file.getName() + ".toURL() fail. Caused:" + e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private File[] findjar(File libDir) {
|
||||
return libDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
String path = pathname.getName();
|
||||
for (String extension : fileExtensionList) {
|
||||
if (path.lastIndexOf("." + extension) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String parseAgentDirPath(String agentJarFullPath) {
|
||||
int index1 = agentJarFullPath.lastIndexOf("/");
|
||||
int index2 = agentJarFullPath.lastIndexOf("\\");
|
||||
int max = Math.max(index1, index2);
|
||||
if (max == -1) {
|
||||
return null;
|
||||
}
|
||||
return agentJarFullPath.substring(0, max);
|
||||
}
|
||||
|
||||
public String getAgentDirPath() {
|
||||
return agentDirPath;
|
||||
}
|
||||
|
||||
public String getAgentConfigPath() {
|
||||
return agentDirPath + File.separator + "pinpoint.config";
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ClassPathResolver {
|
||||
|
||||
private final Logger logger = Logger.getLogger(this.getClass().getName());
|
||||
|
||||
private static final Pattern DEFAULT_AGENT_PATTERN = Pattern.compile("pinpoint-bootstrap(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar");
|
||||
|
||||
private String classPath;
|
||||
|
||||
private String agentJarName;
|
||||
private String agentJarFullPath;
|
||||
private String agentDirPath;
|
||||
private Pattern agentPattern;
|
||||
private List<String> fileExtensionList;
|
||||
|
||||
public ClassPathResolver() {
|
||||
this(getClassPathFromSystemProperty());
|
||||
}
|
||||
|
||||
|
||||
public ClassPathResolver(String classPath) {
|
||||
this.classPath = classPath;
|
||||
this.agentPattern = DEFAULT_AGENT_PATTERN;
|
||||
this.fileExtensionList = getDefaultFileExtensionList();
|
||||
}
|
||||
|
||||
public List<String> getDefaultFileExtensionList() {
|
||||
List<String> extensionList = new ArrayList<String>();
|
||||
extensionList.add("jar");
|
||||
extensionList.add("xml");
|
||||
extensionList.add("properties");
|
||||
return extensionList;
|
||||
}
|
||||
|
||||
public ClassPathResolver(String classPath, String agentPattern) {
|
||||
this.classPath = classPath;
|
||||
this.agentPattern = Pattern.compile(agentPattern);
|
||||
}
|
||||
|
||||
public void setClassPath(String classPath) {
|
||||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
public void setClassPathFromSystemProperty() {
|
||||
this.classPath = getClassPathFromSystemProperty();
|
||||
}
|
||||
|
||||
public static String getClassPathFromSystemProperty() {
|
||||
return System.getProperty("java.class.path");
|
||||
}
|
||||
|
||||
public boolean findAgentJar() {
|
||||
Matcher matcher = agentPattern.matcher(classPath);
|
||||
if (!matcher.find()) {
|
||||
return false;
|
||||
}
|
||||
this.agentJarName = parseAgentJar(matcher);
|
||||
this.agentJarFullPath = parseAgentJarPath(classPath, agentJarName);
|
||||
if (agentJarFullPath == null) {
|
||||
return false;
|
||||
}
|
||||
this.agentDirPath = parseAgentDirPath(agentJarFullPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String parseAgentJar(Matcher matcher) {
|
||||
int start = matcher.start();
|
||||
int end = matcher.end();
|
||||
return this.classPath.substring(start, end);
|
||||
}
|
||||
|
||||
|
||||
public String getAgentJarName() {
|
||||
return this.agentJarName;
|
||||
}
|
||||
|
||||
|
||||
private String parseAgentJarPath(String classPath, String agentJar) {
|
||||
String[] classPathList = classPath.split(File.pathSeparator);
|
||||
for (String findPath : classPathList) {
|
||||
boolean find = findPath.contains(agentJar);
|
||||
if (find) {
|
||||
return findPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAgentJarFullPath() {
|
||||
return agentJarFullPath;
|
||||
}
|
||||
|
||||
public String getAgentLibPath() {
|
||||
return this.agentDirPath + File.separator + "lib";
|
||||
}
|
||||
|
||||
public String getAgentLogFilePath() {
|
||||
return this.agentDirPath + File.separator + "log";
|
||||
}
|
||||
|
||||
public List<URL> resolveLib() {
|
||||
String agentLibPath = getAgentLibPath();
|
||||
File libDir = new File(agentLibPath);
|
||||
if (!libDir.exists()) {
|
||||
logger.warning(agentLibPath + " not found");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (!libDir.isDirectory()) {
|
||||
logger.warning(agentLibPath + " not Directory");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<URL> jarURLList = new ArrayList<URL>();
|
||||
|
||||
final File[] findJarList = findjar(libDir);
|
||||
if (findJarList != null) {
|
||||
for (File file : findJarList) {
|
||||
URL url = toURI(file);
|
||||
if (url != null) {
|
||||
jarURLList.add(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// agentDir 패스도 넣어야 xml을 찾을 때 해당 패스에서 찾음.
|
||||
URL agentDirUri = toURI(new File(agentLibPath));
|
||||
if (agentDirUri != null) {
|
||||
jarURLList.add(agentDirUri);
|
||||
}
|
||||
|
||||
return jarURLList;
|
||||
}
|
||||
|
||||
private URL toURI(File file) {
|
||||
URI uri = file.toURI();
|
||||
try {
|
||||
return uri.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
logger.log(Level.WARNING, file.getName() + ".toURL() fail. Caused:" + e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private File[] findjar(File libDir) {
|
||||
return libDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
String path = pathname.getName();
|
||||
for (String extension : fileExtensionList) {
|
||||
if (path.lastIndexOf("." + extension) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String parseAgentDirPath(String agentJarFullPath) {
|
||||
int index1 = agentJarFullPath.lastIndexOf("/");
|
||||
int index2 = agentJarFullPath.lastIndexOf("\\");
|
||||
int max = Math.max(index1, index2);
|
||||
if (max == -1) {
|
||||
return null;
|
||||
}
|
||||
return agentJarFullPath.substring(0, max);
|
||||
}
|
||||
|
||||
public String getAgentDirPath() {
|
||||
return agentDirPath;
|
||||
}
|
||||
|
||||
public String getAgentConfigPath() {
|
||||
return agentDirPath + File.separator + "pinpoint.config";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* contextClassLoader에 별도의 classLoader를 세팅하고 실행하는 template
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ContextClassLoaderExecuteTemplate<V> {
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public ContextClassLoaderExecuteTemplate(ClassLoader classLoader) {
|
||||
if (classLoader == null) {
|
||||
throw new NullPointerException("classLoader must not be null");
|
||||
}
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public V execute(Callable<V> callable) throws BootStrapException {
|
||||
try {
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
final ClassLoader before = currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(ContextClassLoaderExecuteTemplate.this.classLoader);
|
||||
try {
|
||||
return callable.call();
|
||||
} finally {
|
||||
// null일 경우도 다시 원복하는게 맞음.
|
||||
// getContextClassLoader 호출시 에러가 발생하였을 경우 여기서 호출당하지 않으므로 이부분에서 원복하는게 맞음.
|
||||
currentThread.setContextClassLoader(before);
|
||||
}
|
||||
} catch (BootStrapException ex){
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw new BootStrapException("execute fail. Caused:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* contextClassLoader에 별도의 classLoader를 세팅하고 실행하는 template
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ContextClassLoaderExecuteTemplate<V> {
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public ContextClassLoaderExecuteTemplate(ClassLoader classLoader) {
|
||||
if (classLoader == null) {
|
||||
throw new NullPointerException("classLoader must not be null");
|
||||
}
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public V execute(Callable<V> callable) throws BootStrapException {
|
||||
try {
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
final ClassLoader before = currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(ContextClassLoaderExecuteTemplate.this.classLoader);
|
||||
try {
|
||||
return callable.call();
|
||||
} finally {
|
||||
// null일 경우도 다시 원복하는게 맞음.
|
||||
// getContextClassLoader 호출시 에러가 발생하였을 경우 여기서 호출당하지 않으므로 이부분에서 원복하는게 맞음.
|
||||
currentThread.setContextClassLoader(before);
|
||||
}
|
||||
} catch (BootStrapException ex){
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw new BootStrapException("execute fail. Caused:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,196 +1,196 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.ProductInfo;
|
||||
import com.nhn.pinpoint.common.PinpointConstants;
|
||||
import com.nhn.pinpoint.common.util.TransactionIdUtils;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author netspider
|
||||
*/
|
||||
public class PinpointBootStrap {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PinpointBootStrap.class.getName());
|
||||
|
||||
private static final int LIMIT_LENGTH = 24;
|
||||
private static final String DELIMITER = TransactionIdUtils.TRANSACTION_ID_DELIMITER;
|
||||
|
||||
public static final String BOOT_CLASS = "com.nhn.pinpoint.profiler.DefaultAgent";
|
||||
|
||||
public static final String BOOT_STRAP_LOAD_STATE = "com.nhn.pinpoint.bootstrap.load.state";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_LOADING = "LOADING";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_COMPLETE = "COMPLETE";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_ERROR = "ERROR";
|
||||
|
||||
private static final Pattern validIdPattern = Pattern.compile("[^a-zA-Z0-9._(\\-)]");
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) {
|
||||
if (agentArgs != null) {
|
||||
logger.info(ProductInfo.CAMEL_NAME + " agentArgs:" + agentArgs);
|
||||
}
|
||||
final boolean duplicated = checkDuplicateLoadState();
|
||||
if (duplicated) {
|
||||
// 중복 케이스는 내가 처리하면 안됨. 아래와 같은 코드는 없어야 한다.
|
||||
//loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver();
|
||||
boolean agentJarNotFound = classPathResolver.findAgentJar();
|
||||
if (!agentJarNotFound) {
|
||||
// TODO 이거 변경해야 함.
|
||||
logger.severe("pinpoint-bootstrap-x.x.x.jar not found.");
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidId("pinpoint.agentId", PinpointConstants.AGENT_NAME_MAX_LEN)) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
if (!isValidId("pinpoint.applicationName", PinpointConstants.APPLICATION_NAME_MAX_LEN)) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
String configPath = getConfigPath(classPathResolver);
|
||||
if (configPath == null ) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
// 설정파일을 못찾으므로 종료.
|
||||
return;
|
||||
}
|
||||
// 로그가 저장될 위치를 시스템 properties로 저장한다.
|
||||
saveLogFilePath(classPathResolver);
|
||||
|
||||
try {
|
||||
// 설정파일 로드 이게 bootstrap에 있어야 되나는게 맞나?
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
profilerConfig.readConfigFile(configPath);
|
||||
|
||||
// 이게 로드할 lib List임.
|
||||
List<URL> libUrlList = resolveLib(classPathResolver);
|
||||
AgentClassLoader agentClassLoader = new AgentClassLoader(libUrlList.toArray(new URL[libUrlList.size()]));
|
||||
agentClassLoader.setBootClass(BOOT_CLASS);
|
||||
logger.info("pinpoint agent start.");
|
||||
agentClassLoader.boot(agentArgs, instrumentation, profilerConfig);
|
||||
logger.info("pinpoint agent start success.");
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_COMPLETE);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, ProductInfo.CAMEL_NAME + " start fail. Caused:" + e.getMessage(), e);
|
||||
// 위에서 리턴하는거에서 세는게 이
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void loadStateChange(String loadState) {
|
||||
System.setProperty(BOOT_STRAP_LOAD_STATE, loadState);
|
||||
}
|
||||
|
||||
private static boolean checkDuplicateLoadState() {
|
||||
final String exist = System.getProperty(BOOT_STRAP_LOAD_STATE);
|
||||
if (exist == null) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_LOADING);
|
||||
} else {
|
||||
if (logger.isLoggable(Level.SEVERE)) {
|
||||
logger.severe("pinpoint-bootstrap already started. skip agent loading. loadState:" + exist);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isValidId(String propertyName, int maxSize) {
|
||||
logger.info("check -D" + propertyName);
|
||||
String value = System.getProperty(propertyName);
|
||||
if (value != null) {
|
||||
// 문자열 앞뒤에 공백은 허용되지 않음.
|
||||
value = value.trim();
|
||||
|
||||
if (validIdPattern.matcher(value).find()) {
|
||||
logger.severe("invalid Id. " + propertyName + " can only contain alphanumeric, dot, dash and underscore. value:" + value);
|
||||
return false;
|
||||
}
|
||||
|
||||
final byte[] bytes;
|
||||
try {
|
||||
bytes = toBytes(value);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.severe("toBytes() fail. propertyName:" + propertyName + " propertyValue:" + value);
|
||||
return false;
|
||||
}
|
||||
if (bytes.length == 0) {
|
||||
logger.severe("invalid " + propertyName + ". agentId is empty. length:" + bytes.length + " value:" + value);
|
||||
return false;
|
||||
}
|
||||
if (bytes.length > maxSize) {
|
||||
logger.severe("invalid " + propertyName + ". too large bytes. length:" + bytes.length + " value:" + value);
|
||||
return false;
|
||||
}
|
||||
logger.info("check success. -D" + propertyName + ":" + value + " length:" + bytes.length);
|
||||
return true;
|
||||
} else {
|
||||
logger.severe("-D" + propertyName + " is null.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] toBytes(String property) throws UnsupportedEncodingException {
|
||||
return property.getBytes("UTF-8");
|
||||
}
|
||||
|
||||
private static void saveLogFilePath(ClassPathResolver classPathResolver) {
|
||||
String agentLogFilePath = classPathResolver.getAgentLogFilePath();
|
||||
logger.info("logPath:" + agentLogFilePath);
|
||||
|
||||
System.setProperty(ProductInfo.NAME + ".log", agentLogFilePath);
|
||||
}
|
||||
|
||||
private static String getConfigPath(ClassPathResolver classPathResolver) {
|
||||
final String configName = ProductInfo.NAME + ".config";
|
||||
String pinpointConfigFormSystemProperty = System.getProperty(configName);
|
||||
if (pinpointConfigFormSystemProperty != null) {
|
||||
logger.info(configName + " systemProperty found. " + pinpointConfigFormSystemProperty);
|
||||
return pinpointConfigFormSystemProperty;
|
||||
}
|
||||
|
||||
String classPathAgentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
if (classPathAgentConfigPath != null) {
|
||||
logger.info("classpath " + configName + " found. " + classPathAgentConfigPath);
|
||||
return classPathAgentConfigPath;
|
||||
}
|
||||
|
||||
logger.severe(configName + " file not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static List<URL> resolveLib(ClassPathResolver classPathResolver) {
|
||||
// 절대경로만 처리되지 않나함. 상대 경로(./../agentlib/lib등)일 경우의 처리가 있어야 될것 같음.
|
||||
String agentJarFullPath = classPathResolver.getAgentJarFullPath();
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
List<URL> urlList = classPathResolver.resolveLib();
|
||||
String agentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("agentJarPath:" + agentJarFullPath);
|
||||
logger.info("agentLibPath:" + agentLibPath);
|
||||
logger.info("agent lib list:" + urlList);
|
||||
logger.info("agent config:" + agentConfigPath);
|
||||
}
|
||||
|
||||
return urlList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.ProductInfo;
|
||||
import com.nhn.pinpoint.common.PinpointConstants;
|
||||
import com.nhn.pinpoint.common.util.TransactionIdUtils;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author netspider
|
||||
*/
|
||||
public class PinpointBootStrap {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(PinpointBootStrap.class.getName());
|
||||
|
||||
private static final int LIMIT_LENGTH = 24;
|
||||
private static final String DELIMITER = TransactionIdUtils.TRANSACTION_ID_DELIMITER;
|
||||
|
||||
public static final String BOOT_CLASS = "com.nhn.pinpoint.profiler.DefaultAgent";
|
||||
|
||||
public static final String BOOT_STRAP_LOAD_STATE = "com.nhn.pinpoint.bootstrap.load.state";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_LOADING = "LOADING";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_COMPLETE = "COMPLETE";
|
||||
public static final String BOOT_STRAP_LOAD_STATE_ERROR = "ERROR";
|
||||
|
||||
private static final Pattern validIdPattern = Pattern.compile("[^a-zA-Z0-9._(\\-)]");
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) {
|
||||
if (agentArgs != null) {
|
||||
logger.info(ProductInfo.CAMEL_NAME + " agentArgs:" + agentArgs);
|
||||
}
|
||||
final boolean duplicated = checkDuplicateLoadState();
|
||||
if (duplicated) {
|
||||
// 중복 케이스는 내가 처리하면 안됨. 아래와 같은 코드는 없어야 한다.
|
||||
//loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver();
|
||||
boolean agentJarNotFound = classPathResolver.findAgentJar();
|
||||
if (!agentJarNotFound) {
|
||||
// TODO 이거 변경해야 함.
|
||||
logger.severe("pinpoint-bootstrap-x.x.x.jar not found.");
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidId("pinpoint.agentId", PinpointConstants.AGENT_NAME_MAX_LEN)) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
if (!isValidId("pinpoint.applicationName", PinpointConstants.APPLICATION_NAME_MAX_LEN)) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
String configPath = getConfigPath(classPathResolver);
|
||||
if (configPath == null ) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
// 설정파일을 못찾으므로 종료.
|
||||
return;
|
||||
}
|
||||
// 로그가 저장될 위치를 시스템 properties로 저장한다.
|
||||
saveLogFilePath(classPathResolver);
|
||||
|
||||
try {
|
||||
// 설정파일 로드 이게 bootstrap에 있어야 되나는게 맞나?
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
profilerConfig.readConfigFile(configPath);
|
||||
|
||||
// 이게 로드할 lib List임.
|
||||
List<URL> libUrlList = resolveLib(classPathResolver);
|
||||
AgentClassLoader agentClassLoader = new AgentClassLoader(libUrlList.toArray(new URL[libUrlList.size()]));
|
||||
agentClassLoader.setBootClass(BOOT_CLASS);
|
||||
logger.info("pinpoint agent start.");
|
||||
agentClassLoader.boot(agentArgs, instrumentation, profilerConfig);
|
||||
logger.info("pinpoint agent start success.");
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_COMPLETE);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, ProductInfo.CAMEL_NAME + " start fail. Caused:" + e.getMessage(), e);
|
||||
// 위에서 리턴하는거에서 세는게 이
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void loadStateChange(String loadState) {
|
||||
System.setProperty(BOOT_STRAP_LOAD_STATE, loadState);
|
||||
}
|
||||
|
||||
private static boolean checkDuplicateLoadState() {
|
||||
final String exist = System.getProperty(BOOT_STRAP_LOAD_STATE);
|
||||
if (exist == null) {
|
||||
loadStateChange(BOOT_STRAP_LOAD_STATE_LOADING);
|
||||
} else {
|
||||
if (logger.isLoggable(Level.SEVERE)) {
|
||||
logger.severe("pinpoint-bootstrap already started. skip agent loading. loadState:" + exist);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isValidId(String propertyName, int maxSize) {
|
||||
logger.info("check -D" + propertyName);
|
||||
String value = System.getProperty(propertyName);
|
||||
if (value != null) {
|
||||
// 문자열 앞뒤에 공백은 허용되지 않음.
|
||||
value = value.trim();
|
||||
|
||||
if (validIdPattern.matcher(value).find()) {
|
||||
logger.severe("invalid Id. " + propertyName + " can only contain alphanumeric, dot, dash and underscore. value:" + value);
|
||||
return false;
|
||||
}
|
||||
|
||||
final byte[] bytes;
|
||||
try {
|
||||
bytes = toBytes(value);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.severe("toBytes() fail. propertyName:" + propertyName + " propertyValue:" + value);
|
||||
return false;
|
||||
}
|
||||
if (bytes.length == 0) {
|
||||
logger.severe("invalid " + propertyName + ". agentId is empty. length:" + bytes.length + " value:" + value);
|
||||
return false;
|
||||
}
|
||||
if (bytes.length > maxSize) {
|
||||
logger.severe("invalid " + propertyName + ". too large bytes. length:" + bytes.length + " value:" + value);
|
||||
return false;
|
||||
}
|
||||
logger.info("check success. -D" + propertyName + ":" + value + " length:" + bytes.length);
|
||||
return true;
|
||||
} else {
|
||||
logger.severe("-D" + propertyName + " is null.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] toBytes(String property) throws UnsupportedEncodingException {
|
||||
return property.getBytes("UTF-8");
|
||||
}
|
||||
|
||||
private static void saveLogFilePath(ClassPathResolver classPathResolver) {
|
||||
String agentLogFilePath = classPathResolver.getAgentLogFilePath();
|
||||
logger.info("logPath:" + agentLogFilePath);
|
||||
|
||||
System.setProperty(ProductInfo.NAME + ".log", agentLogFilePath);
|
||||
}
|
||||
|
||||
private static String getConfigPath(ClassPathResolver classPathResolver) {
|
||||
final String configName = ProductInfo.NAME + ".config";
|
||||
String pinpointConfigFormSystemProperty = System.getProperty(configName);
|
||||
if (pinpointConfigFormSystemProperty != null) {
|
||||
logger.info(configName + " systemProperty found. " + pinpointConfigFormSystemProperty);
|
||||
return pinpointConfigFormSystemProperty;
|
||||
}
|
||||
|
||||
String classPathAgentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
if (classPathAgentConfigPath != null) {
|
||||
logger.info("classpath " + configName + " found. " + classPathAgentConfigPath);
|
||||
return classPathAgentConfigPath;
|
||||
}
|
||||
|
||||
logger.severe(configName + " file not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static List<URL> resolveLib(ClassPathResolver classPathResolver) {
|
||||
// 절대경로만 처리되지 않나함. 상대 경로(./../agentlib/lib등)일 경우의 처리가 있어야 될것 같음.
|
||||
String agentJarFullPath = classPathResolver.getAgentJarFullPath();
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
List<URL> urlList = classPathResolver.resolveLib();
|
||||
String agentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
logger.info("agentJarPath:" + agentJarFullPath);
|
||||
logger.info("agentLibPath:" + agentLibPath);
|
||||
logger.info("agent lib list:" + urlList);
|
||||
logger.info("agent config:" + agentConfigPath);
|
||||
}
|
||||
|
||||
return urlList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+60
-60
@@ -1,60 +1,60 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* profiler lib 디렉토리의 jar의 경우 delegation하지 않고 자기 자신에게 로드하도록 함.
|
||||
* standalone java 일 경우 dead lock문제가 발생할수 있어, 자기자신이 load할 class일 경우 parent로 넘기지 않음.
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointURLClassLoader extends URLClassLoader {
|
||||
|
||||
|
||||
private final ClassLoader parent;
|
||||
|
||||
private final ProfilerLibClass profilerLibClass = new ProfilerLibClass();
|
||||
|
||||
public PinpointURLClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
if (parent == null) {
|
||||
throw new NullPointerException("parent must not be null");
|
||||
}
|
||||
// parent가 null인 케이스는 지원하지 않는다.
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
// First, check if the class has already been loaded
|
||||
Class clazz = findLoadedClass(name);
|
||||
if (clazz == null) {
|
||||
if (onLoadClass(name)) {
|
||||
// 나한테 있어야 하는 class의 경우 그냥 로드.
|
||||
clazz = findClass(name);
|
||||
} else {
|
||||
try {
|
||||
// 부모를 찾고.
|
||||
clazz = parent.loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// class를 못찾음.
|
||||
}
|
||||
if (clazz == null) {
|
||||
// 없으면 나한테 로드 시도.
|
||||
clazz = findClass(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resolve) {
|
||||
resolveClass(clazz);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
// for test
|
||||
boolean onLoadClass(String name) {
|
||||
return profilerLibClass.onLoadClass(name);
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* profiler lib 디렉토리의 jar의 경우 delegation하지 않고 자기 자신에게 로드하도록 함.
|
||||
* standalone java 일 경우 dead lock문제가 발생할수 있어, 자기자신이 load할 class일 경우 parent로 넘기지 않음.
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointURLClassLoader extends URLClassLoader {
|
||||
|
||||
|
||||
private final ClassLoader parent;
|
||||
|
||||
private final ProfilerLibClass profilerLibClass = new ProfilerLibClass();
|
||||
|
||||
public PinpointURLClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
if (parent == null) {
|
||||
throw new NullPointerException("parent must not be null");
|
||||
}
|
||||
// parent가 null인 케이스는 지원하지 않는다.
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
// First, check if the class has already been loaded
|
||||
Class clazz = findLoadedClass(name);
|
||||
if (clazz == null) {
|
||||
if (onLoadClass(name)) {
|
||||
// 나한테 있어야 하는 class의 경우 그냥 로드.
|
||||
clazz = findClass(name);
|
||||
} else {
|
||||
try {
|
||||
// 부모를 찾고.
|
||||
clazz = parent.loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// class를 못찾음.
|
||||
}
|
||||
if (clazz == null) {
|
||||
// 없으면 나한테 로드 시도.
|
||||
clazz = findClass(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resolve) {
|
||||
resolveClass(clazz);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
// for test
|
||||
boolean onLoadClass(String name) {
|
||||
return profilerLibClass.onLoadClass(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ProfilerLibClass {
|
||||
|
||||
private static final String[] PINPOINT_PROFILER_CLASS = new String[] {
|
||||
"com.nhn.pinpoint.profiler",
|
||||
"com.nhn.pinpoint.thrift",
|
||||
"com.nhn.pinpoint.rpc",
|
||||
"javassist",
|
||||
"org.slf4j",
|
||||
"org.apache.thrift",
|
||||
"org.jboss.netty",
|
||||
"com.google.common",
|
||||
"org.apache.commons.lang",
|
||||
"org.apache.log4j",
|
||||
"com.codahale.metrics"
|
||||
};
|
||||
|
||||
public boolean onLoadClass(String clazzName) {
|
||||
final int length = PINPOINT_PROFILER_CLASS.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (clazzName.startsWith(PINPOINT_PROFILER_CLASS[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class ProfilerLibClass {
|
||||
|
||||
private static final String[] PINPOINT_PROFILER_CLASS = new String[] {
|
||||
"com.nhn.pinpoint.profiler",
|
||||
"com.nhn.pinpoint.thrift",
|
||||
"com.nhn.pinpoint.rpc",
|
||||
"javassist",
|
||||
"org.slf4j",
|
||||
"org.apache.thrift",
|
||||
"org.jboss.netty",
|
||||
"com.google.common",
|
||||
"org.apache.commons.lang",
|
||||
"org.apache.log4j",
|
||||
"com.codahale.metrics"
|
||||
};
|
||||
|
||||
public boolean onLoadClass(String clazzName) {
|
||||
final int length = PINPOINT_PROFILER_CLASS.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (clazzName.startsWith(PINPOINT_PROFILER_CLASS[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package com.nhn.pinpoint.bootstrap.config;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public enum DumpType {
|
||||
// NONE(-1), 의 경우 이미 더 앞단에서 할지 말지를 결정하므로 중복설정이라 주석처리함.
|
||||
ALWAYS(0), EXCEPTION(1);
|
||||
|
||||
private int code;
|
||||
private DumpType(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.config;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public enum DumpType {
|
||||
// NONE(-1), 의 경우 이미 더 앞단에서 할지 말지를 결정하므로 중복설정이라 주석처리함.
|
||||
ALWAYS(0), EXCEPTION(1);
|
||||
|
||||
private int code;
|
||||
private DumpType(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+98
-94
@@ -44,7 +44,10 @@ public class ProfilerConfig {
|
||||
private boolean jdbcProfileMySqlCommit = false;
|
||||
private boolean jdbcProfileMySqlRollback = false;
|
||||
|
||||
private boolean jdbcProfileMsSql = true;
|
||||
private boolean jdbcProfileJtds = true;
|
||||
private boolean jdbcProfileJtdsSetAutoCommit = false;
|
||||
private boolean jdbcProfileJtdsCommit = false;
|
||||
private boolean jdbcProfileJtdsRollback = false;
|
||||
|
||||
private boolean jdbcProfileOracle = true;
|
||||
private boolean jdbcProfileOracleSetAutoCommit = false;
|
||||
@@ -68,9 +71,6 @@ public class ProfilerConfig {
|
||||
|
||||
private boolean mybatis = true;
|
||||
|
||||
private boolean redis = true;
|
||||
private boolean nBaseArc = true;
|
||||
|
||||
/**
|
||||
* apache http client
|
||||
*/
|
||||
@@ -253,10 +253,22 @@ public class ProfilerConfig {
|
||||
}
|
||||
// mysql end-----------------------------------------------------
|
||||
|
||||
public boolean isJdbcProfileMsSql() {
|
||||
return jdbcProfileMsSql;
|
||||
public boolean isJdbcProfileJtds() {
|
||||
return jdbcProfileJtds;
|
||||
}
|
||||
|
||||
public boolean isJdbcProfileJtdsSetAutoCommit() {
|
||||
return jdbcProfileJtdsSetAutoCommit;
|
||||
}
|
||||
|
||||
public boolean isJdbcProfileJtdsCommit() {
|
||||
return jdbcProfileJtdsCommit;
|
||||
}
|
||||
|
||||
public boolean isJdbcProfileJtdsRollback() {
|
||||
return jdbcProfileJtdsRollback;
|
||||
}
|
||||
|
||||
// oracle start -----------------------------------------------------
|
||||
public boolean isJdbcProfileOracle() {
|
||||
return jdbcProfileOracle;
|
||||
@@ -306,7 +318,7 @@ public class ProfilerConfig {
|
||||
return ioBufferingEnable;
|
||||
}
|
||||
|
||||
public int getIoBufferingBufferBufferSize() {
|
||||
public int getIoBufferingBufferSize() {
|
||||
return ioBufferingBufferSize;
|
||||
}
|
||||
|
||||
@@ -449,15 +461,7 @@ public class ProfilerConfig {
|
||||
return mybatis;
|
||||
}
|
||||
|
||||
public boolean isRedisEnabled() {
|
||||
return redis;
|
||||
}
|
||||
|
||||
public boolean isNBaseArcEnabled() {
|
||||
return nBaseArc;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* TODO remove this. 테스트 장비에서 call stack view가 잘 보이는지 테스트 하려고 추가함.
|
||||
*
|
||||
* @param className
|
||||
@@ -517,7 +521,10 @@ public class ProfilerConfig {
|
||||
this.jdbcProfileMySqlRollback = readBoolean(prop, "profiler.jdbc.mysql.rollback", false);
|
||||
|
||||
|
||||
this.jdbcProfileMsSql = readBoolean(prop, "profiler.jdbc.mssql", true);
|
||||
this.jdbcProfileJtds = readBoolean(prop, "profiler.jdbc.jtds", true);
|
||||
this.jdbcProfileJtdsSetAutoCommit = readBoolean(prop, "profiler.jdbc.jtds.setautocommit", false);
|
||||
this.jdbcProfileJtdsCommit = readBoolean(prop, "profiler.jdbc.jtds.commit", false);
|
||||
this.jdbcProfileJtdsRollback = readBoolean(prop, "profiler.jdbc.jtds.rollback", false);
|
||||
|
||||
|
||||
this.jdbcProfileOracle = readBoolean(prop, "profiler.jdbc.oracle", true);
|
||||
@@ -576,11 +583,6 @@ public class ProfilerConfig {
|
||||
this.ningAsyncHttpClientProfileParamDumpSize = readInt(prop, "profiler.ning.asynchttpclient.param.dumpsize", 1024);
|
||||
this.ningAsyncHttpClientProfileParamSamplingRate = readInt(prop, "profiler.asynchttpclient.param.sampling.rate", 1);
|
||||
|
||||
// redis & nBase-ARC
|
||||
this.redis = readBoolean(prop, "profiler.redis", true);
|
||||
this.nBaseArc = readBoolean(prop, "profiler.nBaseArc", true);
|
||||
|
||||
|
||||
//
|
||||
// FIXME 임시용, line game netty configuration
|
||||
//
|
||||
@@ -708,83 +710,85 @@ public class ProfilerConfig {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("ProfilerConfig{");
|
||||
final StringBuilder sb = new StringBuilder("ProfilerConfig{");
|
||||
sb.append("profileEnable=").append(profileEnable);
|
||||
sb.append("\n collectorServerIp='").append(collectorServerIp).append('\'');
|
||||
sb.append("\n collectorUdpSpanServerPort=").append(collectorUdpSpanServerPort);
|
||||
sb.append("\n collectorUdpServerPort=").append(collectorUdpServerPort);
|
||||
sb.append("\n collectorTcpServerPort=").append(collectorTcpServerPort);
|
||||
sb.append("\n spanDataSenderWriteQueueSize=").append(spanDataSenderWriteQueueSize);
|
||||
sb.append("\n spanDataSenderSocketSendBufferSize=").append(spanDataSenderSocketSendBufferSize);
|
||||
sb.append("\n spanDataSenderSocketTimeout=").append(spanDataSenderSocketTimeout);
|
||||
sb.append("\n statDataSenderWriteQueueSize=").append(statDataSenderWriteQueueSize);
|
||||
sb.append("\n statDataSenderSocketSendBufferSize=").append(statDataSenderSocketSendBufferSize);
|
||||
sb.append("\n statDataSenderSocketTimeout=").append(statDataSenderSocketTimeout);
|
||||
sb.append("\n tcpCommandAcceptEnable=").append(tcpDataSenderCommandAcceptEnable);
|
||||
sb.append("\n jdbcSqlCacheSize=").append(jdbcSqlCacheSize);
|
||||
sb.append("\n jdbcProfile=").append(jdbcProfile);
|
||||
sb.append("\n jdbcProfileMySql=").append(jdbcProfileMySql);
|
||||
sb.append("\n jdbcProfileMySqlSetAutoCommit=").append(jdbcProfileMySqlSetAutoCommit);
|
||||
sb.append("\n jdbcProfileMySqlCommit=").append(jdbcProfileMySqlCommit);
|
||||
sb.append("\n jdbcProfileMySqlRollback=").append(jdbcProfileMySqlRollback);
|
||||
sb.append("\n jdbcProfileMsSql=").append(jdbcProfileMsSql);
|
||||
sb.append("\n jdbcProfileOracle=").append(jdbcProfileOracle);
|
||||
sb.append("\n jdbcProfileOracleSetAutoCommit=").append(jdbcProfileOracleSetAutoCommit);
|
||||
sb.append("\n jdbcProfileOracleCommit=").append(jdbcProfileOracleCommit);
|
||||
sb.append("\n jdbcProfileOracleRollback=").append(jdbcProfileOracleRollback);
|
||||
sb.append("\n jdbcProfileCubrid=").append(jdbcProfileCubrid);
|
||||
sb.append("\n jdbcProfileCubridSetAutoCommit=").append(jdbcProfileCubridSetAutoCommit);
|
||||
sb.append("\n jdbcProfileCubridCommit=").append(jdbcProfileCubridCommit);
|
||||
sb.append("\n jdbcProfileCubridRollback=").append(jdbcProfileCubridRollback);
|
||||
sb.append("\n jdbcProfileDbcp=").append(jdbcProfileDbcp);
|
||||
sb.append("\n jdbcProfileDbcpConnectionClose=").append(jdbcProfileDbcpConnectionClose);
|
||||
sb.append("\n arucs=").append(arucs);
|
||||
sb.append("\n arucsKeyTrace=").append(arucsKeyTrace);
|
||||
sb.append("\n memcached=").append(memcached);
|
||||
sb.append("\n memcachedKeyTrace=").append(memcachedKeyTrace);
|
||||
sb.append("\n redis=").append(redis);
|
||||
sb.append("\n nBaseArc=").append(nBaseArc);
|
||||
sb.append("\n ibatis=").append(ibatis);
|
||||
sb.append("\n mybatis=").append(mybatis);
|
||||
sb.append("\n apacheHttpClient4Profile=").append(apacheHttpClient4Profile);
|
||||
sb.append("\n apacheHttpClient4ProfileCookie=").append(apacheHttpClient4ProfileCookie);
|
||||
sb.append("\n apacheHttpClient4ProfileCookieDumpType=").append(apacheHttpClient4ProfileCookieDumpType);
|
||||
sb.append("\n apacheHttpClient4ProfileCookieSamplingRate=").append(apacheHttpClient4ProfileCookieSamplingRate);
|
||||
sb.append("\n apacheHttpClient4ProfileEntity=").append(apacheHttpClient4ProfileEntity);
|
||||
sb.append("\n apacheHttpClient4ProfileEntityDumpType=").append(apacheHttpClient4ProfileEntityDumpType);
|
||||
sb.append("\n apacheHttpClient4ProfileEntitySamplingRate=").append(apacheHttpClient4ProfileEntitySamplingRate);
|
||||
sb.append("\n apacheNIOHttpClient4Profile=").append(apacheNIOHttpClient4Profile);
|
||||
sb.append("\n ningAsyncHttpClientProfile=").append(ningAsyncHttpClientProfile);
|
||||
sb.append("\n ningAsyncHttpClientProfileCookie=").append(ningAsyncHttpClientProfileCookie);
|
||||
sb.append("\n ningAsyncHttpClientProfileCookieDumpType=").append(ningAsyncHttpClientProfileCookieDumpType);
|
||||
sb.append("\n ningAsyncHttpClientProfileCookieDumpSize=").append(ningAsyncHttpClientProfileCookieDumpSize);
|
||||
sb.append("\n ningAsyncHttpClientProfileCookieSamplingRate=").append(ningAsyncHttpClientProfileCookieSamplingRate);
|
||||
sb.append("\n ningAsyncHttpClientProfileEntity=").append(ningAsyncHttpClientProfileEntity);
|
||||
sb.append("\n ningAsyncHttpClientProfileEntityDumpType=").append(ningAsyncHttpClientProfileEntityDumpType);
|
||||
sb.append("\n ningAsyncHttpClientProfileEntityDumpSize=").append(ningAsyncHttpClientProfileEntityDumpSize);
|
||||
sb.append("\n ningAsyncHttpClientProfileEntitySamplingRate=").append(ningAsyncHttpClientProfileEntitySamplingRate);
|
||||
sb.append("\n ningAsyncHttpClientProfileParam=").append(ningAsyncHttpClientProfileParam);
|
||||
sb.append("\n ningAsyncHttpClientProfileParamDumpType=").append(ningAsyncHttpClientProfileParamDumpType);
|
||||
sb.append("\n ningAsyncHttpClientProfileParamDumpSize=").append(ningAsyncHttpClientProfileParamDumpSize);
|
||||
sb.append("\n ningAsyncHttpClientProfileParamSamplingRate=").append(ningAsyncHttpClientProfileParamSamplingRate);
|
||||
sb.append("\n lineGameNettyParamDumpSize=").append(lineGameNettyParamDumpSize);
|
||||
sb.append("\n lineGameNettyEntityDumpSize=").append(lineGameNettyEntityDumpSize);
|
||||
sb.append("\n samplingEnable=").append(samplingEnable);
|
||||
sb.append("\n samplingRate=").append(samplingRate);
|
||||
sb.append("\n ioBufferingEnable=").append(ioBufferingEnable);
|
||||
sb.append("\n ioBufferingBufferSize=").append(ioBufferingBufferSize);
|
||||
sb.append("\n profileJvmCollectInterval=").append(profileJvmCollectInterval);
|
||||
sb.append("\n profileInclude=").append(profileInclude);
|
||||
sb.append("\n profileIncludeSub=").append(profileIncludeSub);
|
||||
sb.append("\n heartbeatInterval=").append(heartbeatInterval);
|
||||
sb.append("\n applicationServerType=").append(applicationServerType);
|
||||
sb.append(", collectorServerIp='").append(collectorServerIp).append('\'');
|
||||
sb.append(", collectorUdpSpanServerPort=").append(collectorUdpSpanServerPort);
|
||||
sb.append(", collectorUdpServerPort=").append(collectorUdpServerPort);
|
||||
sb.append(", collectorTcpServerPort=").append(collectorTcpServerPort);
|
||||
sb.append(", spanDataSenderWriteQueueSize=").append(spanDataSenderWriteQueueSize);
|
||||
sb.append(", spanDataSenderSocketSendBufferSize=").append(spanDataSenderSocketSendBufferSize);
|
||||
sb.append(", spanDataSenderSocketTimeout=").append(spanDataSenderSocketTimeout);
|
||||
sb.append(", statDataSenderWriteQueueSize=").append(statDataSenderWriteQueueSize);
|
||||
sb.append(", statDataSenderSocketSendBufferSize=").append(statDataSenderSocketSendBufferSize);
|
||||
sb.append(", statDataSenderSocketTimeout=").append(statDataSenderSocketTimeout);
|
||||
sb.append(", tcpDataSenderCommandAcceptEnable=").append(tcpDataSenderCommandAcceptEnable);
|
||||
sb.append(", jdbcSqlCacheSize=").append(jdbcSqlCacheSize);
|
||||
sb.append(", jdbcMaxSqlBindValueSize=").append(jdbcMaxSqlBindValueSize);
|
||||
sb.append(", jdbcProfile=").append(jdbcProfile);
|
||||
sb.append(", jdbcProfileMySql=").append(jdbcProfileMySql);
|
||||
sb.append(", jdbcProfileMySqlSetAutoCommit=").append(jdbcProfileMySqlSetAutoCommit);
|
||||
sb.append(", jdbcProfileMySqlCommit=").append(jdbcProfileMySqlCommit);
|
||||
sb.append(", jdbcProfileMySqlRollback=").append(jdbcProfileMySqlRollback);
|
||||
sb.append(", jdbcProfileJtds=").append(jdbcProfileJtds);
|
||||
sb.append(", jdbcProfileJtdsSetAutoCommit=").append(jdbcProfileJtdsSetAutoCommit);
|
||||
sb.append(", jdbcProfileJtdsCommit=").append(jdbcProfileJtdsCommit);
|
||||
sb.append(", jdbcProfileJtdsRollback=").append(jdbcProfileJtdsRollback);
|
||||
sb.append(", jdbcProfileOracle=").append(jdbcProfileOracle);
|
||||
sb.append(", jdbcProfileOracleSetAutoCommit=").append(jdbcProfileOracleSetAutoCommit);
|
||||
sb.append(", jdbcProfileOracleCommit=").append(jdbcProfileOracleCommit);
|
||||
sb.append(", jdbcProfileOracleRollback=").append(jdbcProfileOracleRollback);
|
||||
sb.append(", jdbcProfileCubrid=").append(jdbcProfileCubrid);
|
||||
sb.append(", jdbcProfileCubridSetAutoCommit=").append(jdbcProfileCubridSetAutoCommit);
|
||||
sb.append(", jdbcProfileCubridCommit=").append(jdbcProfileCubridCommit);
|
||||
sb.append(", jdbcProfileCubridRollback=").append(jdbcProfileCubridRollback);
|
||||
sb.append(", jdbcProfileDbcp=").append(jdbcProfileDbcp);
|
||||
sb.append(", jdbcProfileDbcpConnectionClose=").append(jdbcProfileDbcpConnectionClose);
|
||||
sb.append(", arucs=").append(arucs);
|
||||
sb.append(", arucsKeyTrace=").append(arucsKeyTrace);
|
||||
sb.append(", memcached=").append(memcached);
|
||||
sb.append(", memcachedKeyTrace=").append(memcachedKeyTrace);
|
||||
sb.append(", ibatis=").append(ibatis);
|
||||
sb.append(", mybatis=").append(mybatis);
|
||||
sb.append(", apacheHttpClient4Profile=").append(apacheHttpClient4Profile);
|
||||
sb.append(", apacheHttpClient4ProfileCookie=").append(apacheHttpClient4ProfileCookie);
|
||||
sb.append(", apacheHttpClient4ProfileCookieDumpType=").append(apacheHttpClient4ProfileCookieDumpType);
|
||||
sb.append(", apacheHttpClient4ProfileCookieSamplingRate=").append(apacheHttpClient4ProfileCookieSamplingRate);
|
||||
sb.append(", apacheHttpClient4ProfileEntity=").append(apacheHttpClient4ProfileEntity);
|
||||
sb.append(", apacheHttpClient4ProfileEntityDumpType=").append(apacheHttpClient4ProfileEntityDumpType);
|
||||
sb.append(", apacheHttpClient4ProfileEntitySamplingRate=").append(apacheHttpClient4ProfileEntitySamplingRate);
|
||||
sb.append(", apacheNIOHttpClient4Profile=").append(apacheNIOHttpClient4Profile);
|
||||
sb.append(", ningAsyncHttpClientProfile=").append(ningAsyncHttpClientProfile);
|
||||
sb.append(", ningAsyncHttpClientProfileCookie=").append(ningAsyncHttpClientProfileCookie);
|
||||
sb.append(", ningAsyncHttpClientProfileCookieDumpType=").append(ningAsyncHttpClientProfileCookieDumpType);
|
||||
sb.append(", ningAsyncHttpClientProfileCookieDumpSize=").append(ningAsyncHttpClientProfileCookieDumpSize);
|
||||
sb.append(", ningAsyncHttpClientProfileCookieSamplingRate=").append(ningAsyncHttpClientProfileCookieSamplingRate);
|
||||
sb.append(", ningAsyncHttpClientProfileEntity=").append(ningAsyncHttpClientProfileEntity);
|
||||
sb.append(", ningAsyncHttpClientProfileEntityDumpType=").append(ningAsyncHttpClientProfileEntityDumpType);
|
||||
sb.append(", ningAsyncHttpClientProfileEntityDumpSize=").append(ningAsyncHttpClientProfileEntityDumpSize);
|
||||
sb.append(", ningAsyncHttpClientProfileEntitySamplingRate=").append(ningAsyncHttpClientProfileEntitySamplingRate);
|
||||
sb.append(", ningAsyncHttpClientProfileParam=").append(ningAsyncHttpClientProfileParam);
|
||||
sb.append(", ningAsyncHttpClientProfileParamDumpType=").append(ningAsyncHttpClientProfileParamDumpType);
|
||||
sb.append(", ningAsyncHttpClientProfileParamDumpSize=").append(ningAsyncHttpClientProfileParamDumpSize);
|
||||
sb.append(", ningAsyncHttpClientProfileParamSamplingRate=").append(ningAsyncHttpClientProfileParamSamplingRate);
|
||||
sb.append(", lineGameNettyParamDumpSize=").append(lineGameNettyParamDumpSize);
|
||||
sb.append(", lineGameNettyEntityDumpSize=").append(lineGameNettyEntityDumpSize);
|
||||
sb.append(", samplingEnable=").append(samplingEnable);
|
||||
sb.append(", samplingRate=").append(samplingRate);
|
||||
sb.append(", ioBufferingEnable=").append(ioBufferingEnable);
|
||||
sb.append(", ioBufferingBufferSize=").append(ioBufferingBufferSize);
|
||||
sb.append(", profileJvmCollectInterval=").append(profileJvmCollectInterval);
|
||||
sb.append(", profileInclude=").append(profileInclude);
|
||||
sb.append(", profileIncludeSub=").append(profileIncludeSub);
|
||||
sb.append(", DEFAULT_HEART_BEAT_INTERVAL=").append(DEFAULT_HEART_BEAT_INTERVAL);
|
||||
sb.append(", heartbeatInterval=").append(heartbeatInterval);
|
||||
sb.append(", applicationServerType=").append(applicationServerType);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface AsyncTrace {
|
||||
public static final int STATE_INIT = 0;
|
||||
public static final int STATE_FIRE = 1;
|
||||
public static final int STATE_TIMEOUT = 2;
|
||||
|
||||
int getState();
|
||||
boolean fire();
|
||||
|
||||
void setTimeoutTask(TimerTask timeoutTask);
|
||||
|
||||
void setAsyncId(int asyncId);
|
||||
|
||||
int getAsyncId();
|
||||
|
||||
Object getAttachObject();
|
||||
|
||||
void setAttachObject(Object attachObject);
|
||||
|
||||
void traceBlockBegin();
|
||||
|
||||
void markBeforeTime();
|
||||
|
||||
long getBeforeTime();
|
||||
|
||||
void traceBlockEnd();
|
||||
|
||||
void markAfterTime();
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
void recordException(Object result);
|
||||
|
||||
void recordAttribute(AnnotationKey key, String value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, int value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, Object value);
|
||||
|
||||
void recordServiceType(ServiceType serviceType);
|
||||
|
||||
void recordRpcName(String rpcName);
|
||||
|
||||
void recordDestinationId(String destinationId);
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
void recordEndPoint(String endPoint);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface AsyncTrace {
|
||||
public static final int STATE_INIT = 0;
|
||||
public static final int STATE_FIRE = 1;
|
||||
public static final int STATE_TIMEOUT = 2;
|
||||
|
||||
int getState();
|
||||
boolean fire();
|
||||
|
||||
void setTimeoutTask(TimerTask timeoutTask);
|
||||
|
||||
void setAsyncId(int asyncId);
|
||||
|
||||
int getAsyncId();
|
||||
|
||||
Object getAttachObject();
|
||||
|
||||
void setAttachObject(Object attachObject);
|
||||
|
||||
void traceBlockBegin();
|
||||
|
||||
void markBeforeTime();
|
||||
|
||||
long getBeforeTime();
|
||||
|
||||
void traceBlockEnd();
|
||||
|
||||
void markAfterTime();
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
void recordException(Object result);
|
||||
|
||||
void recordAttribute(AnnotationKey key, String value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, int value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, Object value);
|
||||
|
||||
void recordServiceType(ServiceType serviceType);
|
||||
|
||||
void recordRpcName(String rpcName);
|
||||
|
||||
void recordDestinationId(String destinationId);
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
void recordEndPoint(String endPoint);
|
||||
}
|
||||
|
||||
+24
-24
@@ -1,24 +1,24 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface DatabaseInfo {
|
||||
List<String> getHost();
|
||||
|
||||
String getMultipleHost();
|
||||
|
||||
String getDatabaseId();
|
||||
|
||||
String getRealUrl();
|
||||
|
||||
String getUrl();
|
||||
|
||||
ServiceType getType();
|
||||
|
||||
ServiceType getExecuteQueryType();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface DatabaseInfo {
|
||||
List<String> getHost();
|
||||
|
||||
String getMultipleHost();
|
||||
|
||||
String getDatabaseId();
|
||||
|
||||
String getRealUrl();
|
||||
|
||||
String getUrl();
|
||||
|
||||
ServiceType getType();
|
||||
|
||||
ServiceType getExecuteQueryType();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Metric {
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Metric {
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.common.bo.SpanEventBo;
|
||||
|
||||
/**
|
||||
* @author Hyun Jeong
|
||||
*/
|
||||
public interface ReadableStorage {
|
||||
public List<SpanEventBo> getSpanEventList();
|
||||
}
|
||||
+75
-75
@@ -1,75 +1,75 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface RecordableTrace {
|
||||
|
||||
void markBeforeTime();
|
||||
|
||||
long getBeforeTime();
|
||||
|
||||
void markAfterTime();
|
||||
|
||||
long getAfterTime();
|
||||
|
||||
TraceId getTraceId();
|
||||
|
||||
boolean canSampled();
|
||||
|
||||
boolean isRoot();
|
||||
|
||||
|
||||
void recordException(Throwable throwable);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object[] args);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object args, int index);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object[] args, int start, int end);
|
||||
|
||||
void recordApiCachedString(MethodDescriptor methodDescriptor, String args, int index);
|
||||
|
||||
ParsingResult recordSqlInfo(String sql);
|
||||
|
||||
void recordSqlParsingResult(ParsingResult parsingResult);
|
||||
|
||||
void recordSqlParsingResult(ParsingResult parsingResult, String bindValue);
|
||||
|
||||
void recordAttribute(AnnotationKey key, String value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, int value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, Object value);
|
||||
|
||||
void recordServiceType(ServiceType serviceType);
|
||||
|
||||
void recordRpcName(String rpc);
|
||||
|
||||
void recordDestinationId(String destinationId);
|
||||
|
||||
void recordEndPoint(String endPoint);
|
||||
|
||||
void recordRemoteAddress(String remoteAddress);
|
||||
|
||||
void recordNextSpanId(long spanId);
|
||||
|
||||
void recordParentApplication(String parentApplicationName, short parentApplicationType);
|
||||
|
||||
/**
|
||||
* WAS_A -> WAS_B 호출 관계일 때 WAS_B에서 WAS_A가 보내준 호출 정보를 통해 자기 자신의 정보를 추출하여 저장
|
||||
* 이 데이터는 서버맵에서 WAS끼리 호출관계를 알아낼 떄 필요하다.
|
||||
*
|
||||
* @param host host 값은 WAS를 호출한 URL상의 host를 가져와야 한다.
|
||||
*/
|
||||
void recordAcceptorHost(String host);
|
||||
|
||||
int getStackFrameId();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface RecordableTrace {
|
||||
|
||||
void markBeforeTime();
|
||||
|
||||
long getBeforeTime();
|
||||
|
||||
void markAfterTime();
|
||||
|
||||
long getAfterTime();
|
||||
|
||||
TraceId getTraceId();
|
||||
|
||||
boolean canSampled();
|
||||
|
||||
boolean isRoot();
|
||||
|
||||
|
||||
void recordException(Throwable throwable);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object[] args);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object args, int index);
|
||||
|
||||
void recordApi(MethodDescriptor methodDescriptor, Object[] args, int start, int end);
|
||||
|
||||
void recordApiCachedString(MethodDescriptor methodDescriptor, String args, int index);
|
||||
|
||||
ParsingResult recordSqlInfo(String sql);
|
||||
|
||||
void recordSqlParsingResult(ParsingResult parsingResult);
|
||||
|
||||
void recordSqlParsingResult(ParsingResult parsingResult, String bindValue);
|
||||
|
||||
void recordAttribute(AnnotationKey key, String value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, int value);
|
||||
|
||||
void recordAttribute(AnnotationKey key, Object value);
|
||||
|
||||
void recordServiceType(ServiceType serviceType);
|
||||
|
||||
void recordRpcName(String rpc);
|
||||
|
||||
void recordDestinationId(String destinationId);
|
||||
|
||||
void recordEndPoint(String endPoint);
|
||||
|
||||
void recordRemoteAddress(String remoteAddress);
|
||||
|
||||
void recordNextSpanId(long spanId);
|
||||
|
||||
void recordParentApplication(String parentApplicationName, short parentApplicationType);
|
||||
|
||||
/**
|
||||
* WAS_A -> WAS_B 호출 관계일 때 WAS_B에서 WAS_A가 보내준 호출 정보를 통해 자기 자신의 정보를 추출하여 저장
|
||||
* 이 데이터는 서버맵에서 WAS끼리 호출관계를 알아낼 떄 필요하다.
|
||||
*
|
||||
* @param host host 값은 WAS를 호출한 URL상의 host를 가져와야 한다.
|
||||
*/
|
||||
void recordAcceptorHost(String host);
|
||||
|
||||
int getStackFrameId();
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface StackOperation {
|
||||
|
||||
public static final int DEFAULT_STACKID = -1;
|
||||
public static final int ROOT_STACKID = 0;
|
||||
|
||||
void traceBlockBegin();
|
||||
|
||||
void traceBlockBegin(int stackId);
|
||||
|
||||
// traceRootBlockBegin을 명시적으로 빼내야 되듯함.
|
||||
|
||||
void traceRootBlockEnd();
|
||||
|
||||
void traceBlockEnd();
|
||||
|
||||
void traceBlockEnd(int stackId);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface StackOperation {
|
||||
|
||||
public static final int DEFAULT_STACKID = -1;
|
||||
public static final int ROOT_STACKID = 0;
|
||||
|
||||
void traceBlockBegin();
|
||||
|
||||
void traceBlockBegin(int stackId);
|
||||
|
||||
// traceRootBlockBegin을 명시적으로 빼내야 되듯함.
|
||||
|
||||
void traceRootBlockEnd();
|
||||
|
||||
void traceBlockEnd();
|
||||
|
||||
void traceBlockEnd(int stackId);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Trace extends RecordableTrace, StackOperation {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Trace extends RecordableTrace, StackOperation {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+64
-64
@@ -1,64 +1,64 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceContext {
|
||||
|
||||
Trace currentTraceObject();
|
||||
|
||||
/**
|
||||
* sampling rate를 추가적으로 확인해야 되는 trace를 리턴한다.
|
||||
* @return
|
||||
*/
|
||||
Trace currentRawTraceObject();
|
||||
|
||||
Trace continueTraceObject(TraceId traceID);
|
||||
|
||||
Trace newTraceObject();
|
||||
|
||||
void detachTraceObject();
|
||||
|
||||
// ActiveThreadCounter getActiveThreadCounter();
|
||||
|
||||
String getAgentId();
|
||||
|
||||
String getApplicationName();
|
||||
|
||||
long getAgentStartTime();
|
||||
|
||||
short getServerTypeCode();
|
||||
|
||||
String getServerType();
|
||||
|
||||
int cacheApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
int cacheString(String value);
|
||||
|
||||
ParsingResult parseSql(String sql);
|
||||
|
||||
DatabaseInfo parseJdbcUrl(String sql);
|
||||
|
||||
DatabaseInfo createDatabaseInfo(ServiceType type, ServiceType executeQueryType, String url, int port, String databaseId);
|
||||
|
||||
TraceId createTraceId(String transactionId, long parentSpanID, long spanID, short flags);
|
||||
|
||||
Trace disableSampling();
|
||||
|
||||
ProfilerConfig getProfilerConfig();
|
||||
|
||||
Metric getRpcMetric(ServiceType serviceType);
|
||||
|
||||
void recordContextMetricIsError();
|
||||
|
||||
void recordContextMetric(int elapsedTime);
|
||||
|
||||
void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime);
|
||||
|
||||
void recordUserAcceptResponseTime(int elapsedTime);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceContext {
|
||||
|
||||
Trace currentTraceObject();
|
||||
|
||||
/**
|
||||
* sampling rate를 추가적으로 확인해야 되는 trace를 리턴한다.
|
||||
* @return
|
||||
*/
|
||||
Trace currentRawTraceObject();
|
||||
|
||||
Trace continueTraceObject(TraceId traceID);
|
||||
|
||||
Trace newTraceObject();
|
||||
|
||||
void detachTraceObject();
|
||||
|
||||
// ActiveThreadCounter getActiveThreadCounter();
|
||||
|
||||
String getAgentId();
|
||||
|
||||
String getApplicationName();
|
||||
|
||||
long getAgentStartTime();
|
||||
|
||||
short getServerTypeCode();
|
||||
|
||||
String getServerType();
|
||||
|
||||
int cacheApi(MethodDescriptor methodDescriptor);
|
||||
|
||||
int cacheString(String value);
|
||||
|
||||
ParsingResult parseSql(String sql);
|
||||
|
||||
DatabaseInfo parseJdbcUrl(String sql);
|
||||
|
||||
DatabaseInfo createDatabaseInfo(ServiceType type, ServiceType executeQueryType, String url, int port, String databaseId);
|
||||
|
||||
TraceId createTraceId(String transactionId, long parentSpanID, long spanID, short flags);
|
||||
|
||||
Trace disableSampling();
|
||||
|
||||
ProfilerConfig getProfilerConfig();
|
||||
|
||||
Metric getRpcMetric(ServiceType serviceType);
|
||||
|
||||
void recordContextMetricIsError();
|
||||
|
||||
void recordContextMetric(int elapsedTime);
|
||||
|
||||
void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime);
|
||||
|
||||
void recordUserAcceptResponseTime(int elapsedTime);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceId {
|
||||
|
||||
TraceId getNextTraceId();
|
||||
|
||||
long getSpanId();
|
||||
|
||||
String getTransactionId();
|
||||
|
||||
String getAgentId();
|
||||
|
||||
long getAgentStartTime();
|
||||
|
||||
long getTransactionSequence();
|
||||
|
||||
long getParentSpanId();
|
||||
|
||||
short getFlags();
|
||||
|
||||
boolean isRoot();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.context;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceId {
|
||||
|
||||
TraceId getNextTraceId();
|
||||
|
||||
long getSpanId();
|
||||
|
||||
String getTransactionId();
|
||||
|
||||
String getAgentId();
|
||||
|
||||
long getAgentStartTime();
|
||||
|
||||
long getTransactionSequence();
|
||||
|
||||
long getParentSpanId();
|
||||
|
||||
short getFlags();
|
||||
|
||||
boolean isRoot();
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* precompile level의 methodDescriptor를 setting 받을수 있게 한다.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ByteCodeMethodDescriptorSupport {
|
||||
void setMethodDescriptor(MethodDescriptor descriptor);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* precompile level의 methodDescriptor를 setting 받을수 있게 한다.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ByteCodeMethodDescriptorSupport {
|
||||
void setMethodDescriptor(MethodDescriptor descriptor);
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class EmptyParameterExtractor implements ParameterExtractor {
|
||||
|
||||
public static final ParameterExtractor INSTANCE = new EmptyParameterExtractor();
|
||||
|
||||
private EmptyParameterExtractor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object extractObject(Object[] parameterList) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class EmptyParameterExtractor implements ParameterExtractor {
|
||||
|
||||
public static final ParameterExtractor INSTANCE = new EmptyParameterExtractor();
|
||||
|
||||
private EmptyParameterExtractor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object extractObject(Object[] parameterList) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Interceptor {
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Interceptor {
|
||||
}
|
||||
|
||||
+6
-9
@@ -37,10 +37,9 @@ public class InterceptorRegistry {
|
||||
if (interceptor == null) {
|
||||
return -1;
|
||||
}
|
||||
int newId = nextId();
|
||||
|
||||
if (newId > max) {
|
||||
throw new IndexOutOfBoundsException("size=" + index.length + ", id=" + id);
|
||||
final int newId = nextId();
|
||||
if (newId >= max) {
|
||||
throw new IndexOutOfBoundsException("size=" + index.length + " id=" + id);
|
||||
}
|
||||
|
||||
this.index[newId] = interceptor;
|
||||
@@ -49,18 +48,16 @@ public class InterceptorRegistry {
|
||||
}
|
||||
|
||||
private int nextId() {
|
||||
int number = id.getAndIncrement();
|
||||
|
||||
return number;
|
||||
return id.getAndIncrement();
|
||||
}
|
||||
|
||||
int addSimpleInterceptor0(SimpleAroundInterceptor interceptor) {
|
||||
if (interceptor == null) {
|
||||
return -1;
|
||||
}
|
||||
int newId = nextId();
|
||||
final int newId = nextId();
|
||||
if (newId >= max) {
|
||||
throw new IndexOutOfBoundsException("size=" + index.length + ", id=" + id);
|
||||
throw new IndexOutOfBoundsException("size=" + index.length + " id=" + id);
|
||||
}
|
||||
|
||||
this.simpleIndex[newId] = interceptor;
|
||||
|
||||
+48
-48
@@ -1,48 +1,48 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LoggingInterceptor implements StaticAroundInterceptor, SimpleAroundInterceptor {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public LoggingInterceptor(String loggerName) {
|
||||
this.logger = Logger.getLogger(loggerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("after " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("before " + StringUtils.toString(target) + " args:" + Arrays.toString(args) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("after " + StringUtils.toString(target) + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LoggingInterceptor implements StaticAroundInterceptor, SimpleAroundInterceptor {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public LoggingInterceptor(String loggerName) {
|
||||
this.logger = Logger.getLogger(loggerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("before " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("after " + StringUtils.toString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("before " + StringUtils.toString(target) + " args:" + Arrays.toString(args) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("after " + StringUtils.toString(target) + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+26
-26
@@ -1,26 +1,26 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface MethodDescriptor {
|
||||
String getMethodName();
|
||||
|
||||
String getClassName();
|
||||
|
||||
String[] getParameterTypes();
|
||||
|
||||
String[] getParameterVariableName();
|
||||
|
||||
String getParameterDescriptor();
|
||||
|
||||
int getLineNumber();
|
||||
|
||||
String getFullName();
|
||||
|
||||
void setApiId(int apiId);
|
||||
|
||||
int getApiId();
|
||||
|
||||
String getApiDescriptor();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface MethodDescriptor {
|
||||
String getMethodName();
|
||||
|
||||
String getClassName();
|
||||
|
||||
String[] getParameterTypes();
|
||||
|
||||
String[] getParameterVariableName();
|
||||
|
||||
String getParameterDescriptor();
|
||||
|
||||
int getLineNumber();
|
||||
|
||||
String getFullName();
|
||||
|
||||
void setApiId(int apiId);
|
||||
|
||||
int getApiId();
|
||||
|
||||
String getApiDescriptor();
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,15 +1,15 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* 객체 생성을 줄이기 위해서 객체를 리턴하지 않고 c 스타일 api로 디자인함.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParameterExtractor {
|
||||
public static final Object NULL = new Object();
|
||||
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
int getIndex();
|
||||
|
||||
Object extractObject(Object[] parameterList);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* 객체 생성을 줄이기 위해서 객체를 리턴하지 않고 c 스타일 api로 디자인함.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParameterExtractor {
|
||||
public static final Object NULL = new Object();
|
||||
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
int getIndex();
|
||||
|
||||
Object extractObject(Object[] parameterList);
|
||||
}
|
||||
|
||||
+8
-8
@@ -1,8 +1,8 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParameterExtractorSupport {
|
||||
void setParameterExtractor(ParameterExtractor parameterExtractor);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParameterExtractorSupport {
|
||||
void setParameterExtractor(ParameterExtractor parameterExtractor);
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ServiceTypeSupport {
|
||||
|
||||
void setServiceType(ServiceType serviceType);
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ServiceTypeSupport {
|
||||
|
||||
void setServiceType(ServiceType serviceType);
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAroundInterceptor extends Interceptor {
|
||||
|
||||
void before(Object target, Object[] args);
|
||||
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleAroundInterceptor extends Interceptor {
|
||||
|
||||
void before(Object target, Object[] args);
|
||||
|
||||
void after(Object target, Object[] args, Object result, Throwable throwable);
|
||||
}
|
||||
|
||||
+111
-111
@@ -1,111 +1,111 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public abstract class SpanEventSimpleAroundInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
protected final PLogger logger;
|
||||
protected final boolean isDebug;
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
|
||||
private TraceContext traceContext;
|
||||
|
||||
protected SpanEventSimpleAroundInterceptor(Class<? extends SpanEventSimpleAroundInterceptor> childClazz) {
|
||||
this.logger = PLoggerFactory.getLogger(childClazz);
|
||||
this.isDebug = logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logBeforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
prepareBeforeTrace(target, args);
|
||||
|
||||
final Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// blockBegin 인터페이스 분리가 필요함.
|
||||
trace.traceBlockBegin();
|
||||
doInBeforeTrace(trace, target, args);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("before. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void logBeforeInterceptor(Object target, Object[] args) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
protected void prepareBeforeTrace(Object target, Object[] args) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doInBeforeTrace(final RecordableTrace trace, final Object target, final Object[] args);
|
||||
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logAfterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
prepareAfterTrace(target, args, result, throwable);
|
||||
|
||||
final Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
doInAfterTrace(trace, target, args, result, throwable);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("after error. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
} finally {
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected void logAfterInterceptor(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doInAfterTrace(final RecordableTrace trace, final Object target, final Object[] args, final Object result, Throwable throwable);
|
||||
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
public MethodDescriptor getMethodDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public abstract class SpanEventSimpleAroundInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
protected final PLogger logger;
|
||||
protected final boolean isDebug;
|
||||
|
||||
private MethodDescriptor descriptor;
|
||||
|
||||
private TraceContext traceContext;
|
||||
|
||||
protected SpanEventSimpleAroundInterceptor(Class<? extends SpanEventSimpleAroundInterceptor> childClazz) {
|
||||
this.logger = PLoggerFactory.getLogger(childClazz);
|
||||
this.isDebug = logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logBeforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
prepareBeforeTrace(target, args);
|
||||
|
||||
final Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// blockBegin 인터페이스 분리가 필요함.
|
||||
trace.traceBlockBegin();
|
||||
doInBeforeTrace(trace, target, args);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("before. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void logBeforeInterceptor(Object target, Object[] args) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
protected void prepareBeforeTrace(Object target, Object[] args) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doInBeforeTrace(final RecordableTrace trace, final Object target, final Object[] args);
|
||||
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logAfterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
prepareAfterTrace(target, args, result, throwable);
|
||||
|
||||
final Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
doInAfterTrace(trace, target, args, result, throwable);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("after error. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
} finally {
|
||||
trace.traceBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected void logAfterInterceptor(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doInAfterTrace(final RecordableTrace trace, final Object target, final Object[] args, final Object result, Throwable throwable);
|
||||
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
public MethodDescriptor getMethodDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
|
||||
+101
-101
@@ -1,101 +1,101 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public abstract class SpanSimpleAroundInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
protected final PLogger logger;
|
||||
protected final boolean isDebug;
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
|
||||
private TraceContext traceContext;
|
||||
|
||||
protected SpanSimpleAroundInterceptor(Class<? extends SpanSimpleAroundInterceptor> childClazz) {
|
||||
this.logger = PLoggerFactory.getLogger(childClazz);
|
||||
this.isDebug = logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
try {
|
||||
final Trace trace = createTrace(target, args);
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
// TODO STATDISABLE 일단 통계 저장기능을 disable하기 위해 아래 로직을 추가함.
|
||||
if (!trace.canSampled()) {
|
||||
return;
|
||||
}
|
||||
//------------------------------------------------------
|
||||
doInBeforeTrace(trace, target, args);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("before. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void doInBeforeTrace(final RecordableTrace trace, Object target, final Object[] args);
|
||||
|
||||
protected abstract Trace createTrace(final Object target, final Object[] args);
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
final Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
traceContext.detachTraceObject();
|
||||
// TODO STATDISABLE 일단 통계 저장기능을 disable하기 위해 아래 로직을 추가함.
|
||||
if (!trace.canSampled()) {
|
||||
return;
|
||||
}
|
||||
//------------------------------------------------------
|
||||
try {
|
||||
doInAfterTrace(trace, target, args, result, throwable);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("after. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
} finally {
|
||||
trace.traceRootBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void doInAfterTrace(final RecordableTrace trace, final Object target, final Object[] args, final Object result, Throwable throwable);
|
||||
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
public MethodDescriptor getMethodDescriptor() {
|
||||
return methodDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public abstract class SpanSimpleAroundInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
|
||||
protected final PLogger logger;
|
||||
protected final boolean isDebug;
|
||||
|
||||
private MethodDescriptor methodDescriptor;
|
||||
|
||||
private TraceContext traceContext;
|
||||
|
||||
protected SpanSimpleAroundInterceptor(Class<? extends SpanSimpleAroundInterceptor> childClazz) {
|
||||
this.logger = PLoggerFactory.getLogger(childClazz);
|
||||
this.isDebug = logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Object target, Object[] args) {
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, args);
|
||||
}
|
||||
|
||||
try {
|
||||
final Trace trace = createTrace(target, args);
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
// TODO STATDISABLE 일단 통계 저장기능을 disable하기 위해 아래 로직을 추가함.
|
||||
if (!trace.canSampled()) {
|
||||
return;
|
||||
}
|
||||
//------------------------------------------------------
|
||||
doInBeforeTrace(trace, target, args);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("before. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void doInBeforeTrace(final RecordableTrace trace, Object target, final Object[] args);
|
||||
|
||||
protected abstract Trace createTrace(final Object target, final Object[] args);
|
||||
|
||||
@Override
|
||||
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
if (isDebug) {
|
||||
logger.afterInterceptor(target, args, result, throwable);
|
||||
}
|
||||
|
||||
final Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
traceContext.detachTraceObject();
|
||||
// TODO STATDISABLE 일단 통계 저장기능을 disable하기 위해 아래 로직을 추가함.
|
||||
if (!trace.canSampled()) {
|
||||
return;
|
||||
}
|
||||
//------------------------------------------------------
|
||||
try {
|
||||
doInAfterTrace(trace, target, args, result, throwable);
|
||||
} catch (Throwable th) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("after. Caused:{}", th.getMessage(), th);
|
||||
}
|
||||
} finally {
|
||||
trace.traceRootBlockEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void doInAfterTrace(final RecordableTrace trace, final Object target, final Object[] args, final Object result, Throwable throwable);
|
||||
|
||||
|
||||
@Override
|
||||
public void setMethodDescriptor(MethodDescriptor descriptor) {
|
||||
this.methodDescriptor = descriptor;
|
||||
this.traceContext.cacheApi(descriptor);
|
||||
}
|
||||
|
||||
public MethodDescriptor getMethodDescriptor() {
|
||||
return methodDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTraceContext(TraceContext traceContext) {
|
||||
this.traceContext = traceContext;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface StaticAroundInterceptor extends Interceptor {
|
||||
|
||||
void before(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface StaticAroundInterceptor extends Interceptor {
|
||||
|
||||
void before(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
}
|
||||
|
||||
+8
-8
@@ -1,8 +1,8 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* 마커 newInterceptor를 통해 new할 경우 마크로 붙여야 한다. new Interceptor()를 하지 않아도 되는 곳에 강제 로딩을 하였을 경우 에러를 발생시키기 위해서 만듬.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TargetClassLoader {
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
/**
|
||||
* 마커 newInterceptor를 통해 new할 경우 마크로 붙여야 한다. new Interceptor()를 하지 않아도 되는 곳에 강제 로딩을 하였을 경우 에러를 발생시키기 위해서 만듬.
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TargetClassLoader {
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceContextSupport {
|
||||
void setTraceContext(TraceContext traceContext);
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceContextSupport {
|
||||
void setTraceContext(TraceContext traceContext);
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface BindValueTraceValue extends TraceValue {
|
||||
void __setTraceBindValue(Map<Integer, String> value);
|
||||
|
||||
Map<Integer, String> __getTraceBindValue();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface BindValueTraceValue extends TraceValue {
|
||||
void __setTraceBindValue(Map<Integer, String> value);
|
||||
|
||||
Map<Integer, String> __getTraceBindValue();
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface DatabaseInfoTraceValue extends TraceValue {
|
||||
void __setTraceDatabaseInfo(DatabaseInfo value);
|
||||
|
||||
DatabaseInfo __getTraceDatabaseInfo();
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface DatabaseInfoTraceValue extends TraceValue {
|
||||
void __setTraceDatabaseInfo(DatabaseInfo value);
|
||||
|
||||
DatabaseInfo __getTraceDatabaseInfo();
|
||||
|
||||
}
|
||||
|
||||
+32
-32
@@ -1,32 +1,32 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DatabaseInfoTraceValueUtils {
|
||||
|
||||
public static DatabaseInfo __getTraceDatabaseInfo(Object target, DatabaseInfo defaultValue) {
|
||||
if (target == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (target instanceof DatabaseInfoTraceValue) {
|
||||
final DatabaseInfo databaseInfo = ((DatabaseInfoTraceValue) target).__getTraceDatabaseInfo();
|
||||
if (databaseInfo == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return databaseInfo;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void __setTraceDatabaseInfo(Object target, DatabaseInfo databaseInfo) {
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
if (target instanceof DatabaseInfoTraceValue) {
|
||||
((DatabaseInfoTraceValue) target).__setTraceDatabaseInfo(databaseInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DatabaseInfoTraceValueUtils {
|
||||
|
||||
public static DatabaseInfo __getTraceDatabaseInfo(Object target, DatabaseInfo defaultValue) {
|
||||
if (target == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (target instanceof DatabaseInfoTraceValue) {
|
||||
final DatabaseInfo databaseInfo = ((DatabaseInfoTraceValue) target).__getTraceDatabaseInfo();
|
||||
if (databaseInfo == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return databaseInfo;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void __setTraceDatabaseInfo(Object target, DatabaseInfo databaseInfo) {
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
if (target instanceof DatabaseInfoTraceValue) {
|
||||
((DatabaseInfoTraceValue) target).__setTraceDatabaseInfo(databaseInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface IntTraceValue extends TraceValue {
|
||||
void __setTraceInt(int value);
|
||||
|
||||
int __getTraceInt();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface IntTraceValue extends TraceValue {
|
||||
void __setTraceInt(int value);
|
||||
|
||||
int __getTraceInt();
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ObjectTraceValue extends TraceValue {
|
||||
|
||||
void __setTraceObject(Object value);
|
||||
|
||||
Object __getTraceObject();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ObjectTraceValue extends TraceValue {
|
||||
|
||||
void __setTraceObject(Object value);
|
||||
|
||||
Object __getTraceObject();
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParsingResultTraceValue extends TraceValue {
|
||||
void __setTraceParsingResult(ParsingResult parsingResult);
|
||||
|
||||
ParsingResult __getTraceParsingResult();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ParsingResultTraceValue extends TraceValue {
|
||||
void __setTraceParsingResult(ParsingResult parsingResult);
|
||||
|
||||
ParsingResult __getTraceParsingResult();
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,9 +1,9 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* marker Interface
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceValue {
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor.tracevalue;
|
||||
|
||||
/**
|
||||
* marker Interface
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface TraceValue {
|
||||
|
||||
}
|
||||
|
||||
+186
-186
@@ -1,186 +1,186 @@
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyPLogger implements PLogger {
|
||||
|
||||
public static final PLogger INSTANCE = new DummyPLogger();
|
||||
|
||||
@Override
|
||||
public void beforeInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInterceptor(Object target, Object[] args) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyPLogger implements PLogger {
|
||||
|
||||
public static final PLogger INSTANCE = new DummyPLogger();
|
||||
|
||||
@Override
|
||||
public void beforeInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeInterceptor(Object target, Object[] args) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, Object[] args, Object result, Throwable throwable) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterInterceptor(Object target, Object[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arg1, Object arg2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object[] argArray) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg, Throwable t) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+53
-53
@@ -1,53 +1,53 @@
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LoggingUtils {
|
||||
|
||||
|
||||
public static void logBefore(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("before ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
public static void logAfter(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("after ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
sb.append(" result:");
|
||||
sb.append(getTarget(result));
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
public static void logAfter(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("after ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
private static void logMethod(StringBuilder sb, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
sb.append(getTarget(target));
|
||||
sb.append(' ');
|
||||
sb.append(className);
|
||||
sb.append(' ');
|
||||
sb.append(methodName);
|
||||
sb.append(parameterDescription);
|
||||
sb.append(" args:");
|
||||
sb.append(Arrays.toString(args));
|
||||
}
|
||||
|
||||
private static Object getTarget(Object target) {
|
||||
if (target == null) {
|
||||
return "target=null";
|
||||
}
|
||||
return target.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LoggingUtils {
|
||||
|
||||
|
||||
public static void logBefore(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("before ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
public static void logAfter(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args, Object result) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("after ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
sb.append(" result:");
|
||||
sb.append(getTarget(result));
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
public static void logAfter(PLogger logger, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("after ");
|
||||
logMethod(sb, getTarget(target), className, methodName, parameterDescription, args);
|
||||
logger.debug(sb.toString());
|
||||
}
|
||||
|
||||
private static void logMethod(StringBuilder sb, Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
sb.append(getTarget(target));
|
||||
sb.append(' ');
|
||||
sb.append(className);
|
||||
sb.append(' ');
|
||||
sb.append(methodName);
|
||||
sb.append(parameterDescription);
|
||||
sb.append(" args:");
|
||||
sb.append(Arrays.toString(args));
|
||||
}
|
||||
|
||||
private static Object getTarget(Object target) {
|
||||
if (target == null) {
|
||||
return "target=null";
|
||||
}
|
||||
return target.getClass().getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface PLogger {
|
||||
|
||||
|
||||
void beforeInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void beforeInterceptor(Object target, Object[] args);
|
||||
|
||||
void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
void afterInterceptor(Object target, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void afterInterceptor(Object target, Object[] args);
|
||||
|
||||
boolean isTraceEnabled();
|
||||
|
||||
|
||||
void trace(String msg);
|
||||
|
||||
|
||||
void trace(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
void trace(String format, Object arg1, Object arg2);
|
||||
|
||||
void trace(String format, Object[] argArray);
|
||||
|
||||
void trace(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isDebugEnabled();
|
||||
|
||||
|
||||
|
||||
public void debug(String msg);
|
||||
|
||||
|
||||
|
||||
public void debug(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
|
||||
public void debug(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void debug(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void debug(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isInfoEnabled();
|
||||
|
||||
|
||||
public void info(String msg);
|
||||
|
||||
|
||||
|
||||
public void info(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
public void info(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void info(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void info(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isWarnEnabled();
|
||||
|
||||
|
||||
public void warn(String msg);
|
||||
|
||||
|
||||
public void warn(String format, Object arg);
|
||||
|
||||
|
||||
public void warn(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void warn(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void warn(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isErrorEnabled();
|
||||
|
||||
|
||||
public void error(String msg);
|
||||
|
||||
|
||||
public void error(String format, Object arg);
|
||||
|
||||
|
||||
public void error(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void error(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void error(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface PLogger {
|
||||
|
||||
|
||||
void beforeInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void beforeInterceptor(Object target, Object[] args);
|
||||
|
||||
void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
void afterInterceptor(Object target, Object[] args, Object result, Throwable throwable);
|
||||
|
||||
void afterInterceptor(Object target, String className, String methodName, String parameterDescription, Object[] args);
|
||||
|
||||
void afterInterceptor(Object target, Object[] args);
|
||||
|
||||
boolean isTraceEnabled();
|
||||
|
||||
|
||||
void trace(String msg);
|
||||
|
||||
|
||||
void trace(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
void trace(String format, Object arg1, Object arg2);
|
||||
|
||||
void trace(String format, Object[] argArray);
|
||||
|
||||
void trace(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isDebugEnabled();
|
||||
|
||||
|
||||
|
||||
public void debug(String msg);
|
||||
|
||||
|
||||
|
||||
public void debug(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
|
||||
public void debug(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void debug(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void debug(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isInfoEnabled();
|
||||
|
||||
|
||||
public void info(String msg);
|
||||
|
||||
|
||||
|
||||
public void info(String format, Object arg);
|
||||
|
||||
|
||||
|
||||
public void info(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void info(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void info(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isWarnEnabled();
|
||||
|
||||
|
||||
public void warn(String msg);
|
||||
|
||||
|
||||
public void warn(String format, Object arg);
|
||||
|
||||
|
||||
public void warn(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void warn(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void warn(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
public boolean isErrorEnabled();
|
||||
|
||||
|
||||
public void error(String msg);
|
||||
|
||||
|
||||
public void error(String format, Object arg);
|
||||
|
||||
|
||||
public void error(String format, Object arg1, Object arg2);
|
||||
|
||||
|
||||
public void error(String format, Object[] argArray);
|
||||
|
||||
|
||||
public void error(String msg, Throwable t);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface PLoggerBinder {
|
||||
PLogger getLogger(String name);
|
||||
|
||||
void shutdown();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface PLoggerBinder {
|
||||
PLogger getLogger(String name);
|
||||
|
||||
void shutdown();
|
||||
}
|
||||
|
||||
+43
-43
@@ -1,43 +1,43 @@
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class PLoggerFactory {
|
||||
|
||||
private static PLoggerBinder loggerBinder;
|
||||
|
||||
public static void initialize(PLoggerBinder loggerBinder) {
|
||||
if (PLoggerFactory.loggerBinder == null) {
|
||||
PLoggerFactory.loggerBinder = loggerBinder;
|
||||
} else {
|
||||
final Logger logger = Logger.getLogger(PLoggerFactory.class.getName());
|
||||
logger.warning("loggerBinder is not null");
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregister(PLoggerBinder loggerBinder) {
|
||||
// 등록한 놈만 제거 가능하도록 제한
|
||||
// testcase 작성시 가능한 logger를 등록했다가 삭제하는 로직은 beforeClass, afterClass에 넣어야 한다.
|
||||
if (loggerBinder == PLoggerFactory.loggerBinder) {
|
||||
PLoggerFactory.loggerBinder = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PLogger getLogger(String name) {
|
||||
if (loggerBinder == null) {
|
||||
// 바인딩 되지 않은 상태에서 getLogger를 호출시 null ex가 발생하므로 dummy logger를 리턴하도록 함.
|
||||
return DummyPLogger.INSTANCE;
|
||||
}
|
||||
return loggerBinder.getLogger(name);
|
||||
}
|
||||
|
||||
public static PLogger getLogger(Class clazz) {
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException("class must not be null");
|
||||
}
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.logging;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class PLoggerFactory {
|
||||
|
||||
private static PLoggerBinder loggerBinder;
|
||||
|
||||
public static void initialize(PLoggerBinder loggerBinder) {
|
||||
if (PLoggerFactory.loggerBinder == null) {
|
||||
PLoggerFactory.loggerBinder = loggerBinder;
|
||||
} else {
|
||||
final Logger logger = Logger.getLogger(PLoggerFactory.class.getName());
|
||||
logger.warning("loggerBinder is not null");
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregister(PLoggerBinder loggerBinder) {
|
||||
// 등록한 놈만 제거 가능하도록 제한
|
||||
// testcase 작성시 가능한 logger를 등록했다가 삭제하는 로직은 beforeClass, afterClass에 넣어야 한다.
|
||||
if (loggerBinder == PLoggerFactory.loggerBinder) {
|
||||
PLoggerFactory.loggerBinder = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PLogger getLogger(String name) {
|
||||
if (loggerBinder == null) {
|
||||
// 바인딩 되지 않은 상태에서 getLogger를 호출시 null ex가 발생하므로 dummy logger를 리턴하도록 함.
|
||||
return DummyPLogger.INSTANCE;
|
||||
}
|
||||
return loggerBinder.getLogger(name);
|
||||
}
|
||||
|
||||
public static PLogger getLogger(Class clazz) {
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException("class must not be null");
|
||||
}
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
}
|
||||
|
||||
+32
-32
@@ -1,32 +1,32 @@
|
||||
package com.nhn.pinpoint.bootstrap.pair;
|
||||
|
||||
/**
|
||||
* classLoading구조에서 interceptor가 parent에 위치하면서 멀티 value access 데이터 전달이 필요할 경우의 공통 자료구조로 사용한다.
|
||||
* value가 int type일때 사용
|
||||
* @author emeroad
|
||||
*/
|
||||
public class NameIntValuePair<T> {
|
||||
private T name;
|
||||
private int value;
|
||||
|
||||
public NameIntValuePair(T name, int value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.pair;
|
||||
|
||||
/**
|
||||
* classLoading구조에서 interceptor가 parent에 위치하면서 멀티 value access 데이터 전달이 필요할 경우의 공통 자료구조로 사용한다.
|
||||
* value가 int type일때 사용
|
||||
* @author emeroad
|
||||
*/
|
||||
public class NameIntValuePair<T> {
|
||||
private T name;
|
||||
private int value;
|
||||
|
||||
public NameIntValuePair(T name, int value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package com.nhn.pinpoint.bootstrap.pair;
|
||||
|
||||
/**
|
||||
* classLoading구조에서 interceptor가 parent에 위치하면서 멀티 value access 데이터 전달이 필요할 경우의 공통 자료구조로 사용한다.
|
||||
* @author emeroad
|
||||
*/
|
||||
public class NameValuePair<T, V> {
|
||||
private T name;
|
||||
private V value;
|
||||
|
||||
public NameValuePair(T name, V value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.pair;
|
||||
|
||||
/**
|
||||
* classLoading구조에서 interceptor가 parent에 위치하면서 멀티 value access 데이터 전달이 필요할 경우의 공통 자료구조로 사용한다.
|
||||
* @author emeroad
|
||||
*/
|
||||
public class NameValuePair<T, V> {
|
||||
private T name;
|
||||
private V value;
|
||||
|
||||
public NameValuePair(T name, V value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(V value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.nhn.pinpoint.bootstrap.sampler;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Sampler {
|
||||
boolean isSampling();
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.sampler;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface Sampler {
|
||||
boolean isSampling();
|
||||
}
|
||||
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
package com.nhn.pinpoint.bootstrap.sampler;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class SamplingFlagUtils {
|
||||
|
||||
// 향후 다른 샘플링 스펙이 추가될수 있으므로
|
||||
// 일부러 1개 byte를 소비하여 sampling마크 한다.
|
||||
public static final String SAMPLING_RATE_PREFIX = "s";
|
||||
|
||||
|
||||
public static final String SAMPLING_RATE_FALSE = SAMPLING_RATE_PREFIX + "0";
|
||||
public static final String SAMPLING_RATE_TRUE = SAMPLING_RATE_PREFIX + "1";
|
||||
|
||||
private SamplingFlagUtils() {
|
||||
}
|
||||
|
||||
public static boolean isSamplingFlag(String samplingFlag) {
|
||||
if (samplingFlag == null) {
|
||||
return true;
|
||||
}
|
||||
// 정확하게 하지 말란 flag가 세팅되었을 경우만 샘플링을 하지 않는다.
|
||||
// prefix를 보고 뭔가 더 정확하게 동작되어야 필요성이 있음.
|
||||
if (samplingFlag.startsWith(SAMPLING_RATE_PREFIX)) {
|
||||
return !SAMPLING_RATE_FALSE.equals(samplingFlag);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
package com.nhn.pinpoint.bootstrap.sampler;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class SamplingFlagUtils {
|
||||
|
||||
// 향후 다른 샘플링 스펙이 추가될수 있으므로
|
||||
// 일부러 1개 byte를 소비하여 sampling마크 한다.
|
||||
public static final String SAMPLING_RATE_PREFIX = "s";
|
||||
|
||||
|
||||
public static final String SAMPLING_RATE_FALSE = SAMPLING_RATE_PREFIX + "0";
|
||||
public static final String SAMPLING_RATE_TRUE = SAMPLING_RATE_PREFIX + "1";
|
||||
|
||||
private SamplingFlagUtils() {
|
||||
}
|
||||
|
||||
public static boolean isSamplingFlag(String samplingFlag) {
|
||||
if (samplingFlag == null) {
|
||||
return true;
|
||||
}
|
||||
// 정확하게 하지 말란 flag가 세팅되었을 경우만 샘플링을 하지 않는다.
|
||||
// prefix를 보고 뭔가 더 정확하게 동작되어야 필요성이 있음.
|
||||
if (samplingFlag.startsWith(SAMPLING_RATE_PREFIX)) {
|
||||
return !SAMPLING_RATE_FALSE.equals(samplingFlag);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
-34
@@ -1,34 +1,34 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
public final class InterceptorUtils {
|
||||
private InterceptorUtils() {
|
||||
}
|
||||
|
||||
public static boolean isThrowable(Object result) {
|
||||
return result instanceof Throwable;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(Throwable throwable) {
|
||||
return throwable == null;
|
||||
}
|
||||
|
||||
|
||||
public static String exceptionToString(Throwable ex) {
|
||||
if (ex != null) {
|
||||
StringBuilder sb = new StringBuilder(128);
|
||||
sb.append(ex.toString()).append("\n");
|
||||
|
||||
Writer writer = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
ex.printStackTrace(printWriter);
|
||||
sb.append(writer.toString());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
public final class InterceptorUtils {
|
||||
private InterceptorUtils() {
|
||||
}
|
||||
|
||||
public static boolean isThrowable(Object result) {
|
||||
return result instanceof Throwable;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(Throwable throwable) {
|
||||
return throwable == null;
|
||||
}
|
||||
|
||||
|
||||
public static String exceptionToString(Throwable ex) {
|
||||
if (ex != null) {
|
||||
StringBuilder sb = new StringBuilder(128);
|
||||
sb.append(ex.toString()).append("\n");
|
||||
|
||||
Writer writer = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
ex.printStackTrace(printWriter);
|
||||
sb.append(writer.toString());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* TraceValue interface를 구현하여 사용하라
|
||||
*/
|
||||
@Deprecated
|
||||
public final class MetaObject<R> {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final String methodName;
|
||||
private final Class<?>[] args;
|
||||
private final R defaultReturnValue;
|
||||
|
||||
// 이것을 class loading시 정적 타임에서 생성해 둘수 없는가?
|
||||
private Method methodRef;
|
||||
|
||||
|
||||
|
||||
public MetaObject(String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
this.defaultReturnValue = null;
|
||||
}
|
||||
|
||||
public MetaObject(R defaultReturnValue, String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
this.defaultReturnValue = defaultReturnValue;
|
||||
}
|
||||
|
||||
public R invoke(Object target, Object... args) {
|
||||
if (target == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
|
||||
Method method = this.methodRef;
|
||||
if (method == null) {
|
||||
// 멀티쓰레드에서 중복 엑세스해도 별 문제 없을것임.
|
||||
final Class<?> aClass = target.getClass();
|
||||
method = findMethod(aClass);
|
||||
this.methodRef = method;
|
||||
}
|
||||
return invoke(method, target, args);
|
||||
}
|
||||
|
||||
private R invoke(Method method, Object target, Object[] args) {
|
||||
if (method == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
try {
|
||||
return (R) method.invoke(target, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.warn("{} invoke fail", this.methodName, e);
|
||||
return defaultReturnValue;
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.warn("{} invoke fail", this.methodName, e);
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
private Method findMethod(Class<?> aClass) {
|
||||
try {
|
||||
final Method method = aClass.getMethod(this.methodName, this.args);
|
||||
if (!method.isAccessible()) {
|
||||
// package등과 같이 access 제한이 걸려 있을 경우 강 푼다.
|
||||
method.setAccessible(true);
|
||||
}
|
||||
return method;
|
||||
} catch (NoSuchMethodException e) {
|
||||
logger.warn("{} not found class:{} Caused:{}", new Object[] { this.methodName, aClass, e.getMessage(), e });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* TraceValue interface를 구현하여 사용하라
|
||||
*/
|
||||
@Deprecated
|
||||
public final class MetaObject<R> {
|
||||
|
||||
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final String methodName;
|
||||
private final Class<?>[] args;
|
||||
private final R defaultReturnValue;
|
||||
|
||||
// 이것을 class loading시 정적 타임에서 생성해 둘수 없는가?
|
||||
private Method methodRef;
|
||||
|
||||
|
||||
|
||||
public MetaObject(String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
this.defaultReturnValue = null;
|
||||
}
|
||||
|
||||
public MetaObject(R defaultReturnValue, String methodName, Class... args) {
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
this.defaultReturnValue = defaultReturnValue;
|
||||
}
|
||||
|
||||
public R invoke(Object target, Object... args) {
|
||||
if (target == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
|
||||
Method method = this.methodRef;
|
||||
if (method == null) {
|
||||
// 멀티쓰레드에서 중복 엑세스해도 별 문제 없을것임.
|
||||
final Class<?> aClass = target.getClass();
|
||||
method = findMethod(aClass);
|
||||
this.methodRef = method;
|
||||
}
|
||||
return invoke(method, target, args);
|
||||
}
|
||||
|
||||
private R invoke(Method method, Object target, Object[] args) {
|
||||
if (method == null) {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
try {
|
||||
return (R) method.invoke(target, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.warn("{} invoke fail", this.methodName, e);
|
||||
return defaultReturnValue;
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.warn("{} invoke fail", this.methodName, e);
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
|
||||
private Method findMethod(Class<?> aClass) {
|
||||
try {
|
||||
final Method method = aClass.getMethod(this.methodName, this.args);
|
||||
if (!method.isAccessible()) {
|
||||
// package등과 같이 access 제한이 걸려 있을 경우 강 푼다.
|
||||
method.setAccessible(true);
|
||||
}
|
||||
return method;
|
||||
} catch (NoSuchMethodException e) {
|
||||
logger.warn("{} not found class:{} Caused:{}", new Object[] { this.methodName, aClass, e.getMessage(), e });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class NetworkUtils {
|
||||
|
||||
public static final String ERROR_HOST_NAME = "UNKNOWN-HOST";
|
||||
|
||||
private NetworkUtils() {
|
||||
}
|
||||
|
||||
public static String getHostName() {
|
||||
try {
|
||||
final InetAddress localHost = InetAddress.getLocalHost();
|
||||
return localHost.getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
// Try to get machine name from network interface.
|
||||
return getMachineName();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getMachineName() {
|
||||
try {
|
||||
String name = null;
|
||||
Enumeration<NetworkInterface> enet = NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while (enet.hasMoreElements() && (name == null)) {
|
||||
NetworkInterface net = enet.nextElement();
|
||||
|
||||
if (net.isLoopback())
|
||||
continue;
|
||||
|
||||
Enumeration<InetAddress> eaddr = net.getInetAddresses();
|
||||
|
||||
while (eaddr.hasMoreElements()) {
|
||||
InetAddress inet = eaddr.nextElement();
|
||||
|
||||
final String canonicalHostName = inet.getCanonicalHostName();
|
||||
if (!canonicalHostName.equalsIgnoreCase(inet.getHostAddress())) {
|
||||
name = canonicalHostName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
} catch (SocketException e) {
|
||||
Logger.getLogger(NetworkUtils.class.getClass().getName()).warning(e.getMessage());
|
||||
return "UNKNOWN-HOST";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHostFromURL(final String urlSpec) {
|
||||
if (urlSpec == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final URL url = new URL(urlSpec);
|
||||
|
||||
final String host = url.getHost();
|
||||
final int port = url.getPort();
|
||||
|
||||
if (port == -1) {
|
||||
return host;
|
||||
} else {
|
||||
// TODO defualt port일 경우 아래와 같이 url을 만들어야 하는지 애매함.
|
||||
return host + ":" + port;
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class NetworkUtils {
|
||||
|
||||
public static final String ERROR_HOST_NAME = "UNKNOWN-HOST";
|
||||
|
||||
private NetworkUtils() {
|
||||
}
|
||||
|
||||
public static String getHostName() {
|
||||
try {
|
||||
final InetAddress localHost = InetAddress.getLocalHost();
|
||||
return localHost.getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
// Try to get machine name from network interface.
|
||||
return getMachineName();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getMachineName() {
|
||||
try {
|
||||
String name = null;
|
||||
Enumeration<NetworkInterface> enet = NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while (enet.hasMoreElements() && (name == null)) {
|
||||
NetworkInterface net = enet.nextElement();
|
||||
|
||||
if (net.isLoopback())
|
||||
continue;
|
||||
|
||||
Enumeration<InetAddress> eaddr = net.getInetAddresses();
|
||||
|
||||
while (eaddr.hasMoreElements()) {
|
||||
InetAddress inet = eaddr.nextElement();
|
||||
|
||||
final String canonicalHostName = inet.getCanonicalHostName();
|
||||
if (!canonicalHostName.equalsIgnoreCase(inet.getHostAddress())) {
|
||||
name = canonicalHostName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
} catch (SocketException e) {
|
||||
Logger.getLogger(NetworkUtils.class.getClass().getName()).warning(e.getMessage());
|
||||
return "UNKNOWN-HOST";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHostFromURL(final String urlSpec) {
|
||||
if (urlSpec == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final URL url = new URL(urlSpec);
|
||||
|
||||
final String host = url.getHost();
|
||||
final int port = url.getPort();
|
||||
|
||||
if (port == -1) {
|
||||
return host;
|
||||
} else {
|
||||
// TODO defualt port일 경우 아래와 같이 url을 만들어야 하는지 애매함.
|
||||
return host + ":" + port;
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
public final class NumberUtils {
|
||||
private NumberUtils() {
|
||||
}
|
||||
|
||||
public static long parseLong(String str, long defaultLong) {
|
||||
if (str == null) {
|
||||
return defaultLong;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultLong;
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseInteger(String str, int defaultInt) {
|
||||
if (str == null) {
|
||||
return defaultInt;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultInt;
|
||||
}
|
||||
}
|
||||
|
||||
public static short parseShort(String str, short defaultInt) {
|
||||
if (str == null) {
|
||||
return defaultInt;
|
||||
}
|
||||
try {
|
||||
return Short.parseShort(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultInt;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer toInteger(Object integer) {
|
||||
if (integer == null) {
|
||||
return null;
|
||||
}
|
||||
if (integer instanceof Integer) {
|
||||
return (Integer) integer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
public final class NumberUtils {
|
||||
private NumberUtils() {
|
||||
}
|
||||
|
||||
public static long parseLong(String str, long defaultLong) {
|
||||
if (str == null) {
|
||||
return defaultLong;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultLong;
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseInteger(String str, int defaultInt) {
|
||||
if (str == null) {
|
||||
return defaultInt;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultInt;
|
||||
}
|
||||
}
|
||||
|
||||
public static short parseShort(String str, short defaultInt) {
|
||||
if (str == null) {
|
||||
return defaultInt;
|
||||
}
|
||||
try {
|
||||
return Short.parseShort(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultInt;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer toInteger(Object integer) {
|
||||
if (integer == null) {
|
||||
return null;
|
||||
}
|
||||
if (integer instanceof Integer) {
|
||||
return (Integer) integer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleSampler {
|
||||
|
||||
boolean isSampling();
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface SimpleSampler {
|
||||
|
||||
boolean isSampling();
|
||||
|
||||
}
|
||||
|
||||
+57
-57
@@ -1,57 +1,57 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import com.nhn.pinpoint.common.util.MathUtils;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SimpleSamplerFactory {
|
||||
// profiler에 있는 Sampler와 기능이 동일하지만. profiler에 있는 sampler의 경우 좀더 파생 모델이 나와야 되므로 별도로 분리한다.
|
||||
public static final SimpleSampler FALSE_SAMPLER = new SimpleFalseSampler();
|
||||
public static final SimpleSampler TRUE_SAMPLER = new SimpleTrueSampler();
|
||||
|
||||
public static SimpleSampler createSampler(boolean sampling, int samplingRate) {
|
||||
if (!sampling || samplingRate <= 0) {
|
||||
return FALSE_SAMPLER;
|
||||
}
|
||||
if (samplingRate == 1) {
|
||||
return TRUE_SAMPLER;
|
||||
}
|
||||
return new SamplingRateSampler(samplingRate);
|
||||
}
|
||||
|
||||
public static class SimpleTrueSampler implements SimpleSampler {
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleFalseSampler implements SimpleSampler {
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SamplingRateSampler implements SimpleSampler {
|
||||
private final AtomicInteger counter = new AtomicInteger(0);
|
||||
private final int samplingRate;
|
||||
|
||||
public SamplingRateSampler(int samplingRate) {
|
||||
if (samplingRate <= 0) {
|
||||
throw new IllegalArgumentException("Invalid samplingRate " + samplingRate);
|
||||
}
|
||||
this.samplingRate = samplingRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
int samplingCount = MathUtils.fastAbs(counter.getAndIncrement());
|
||||
int isSampling = samplingCount % samplingRate;
|
||||
return isSampling == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import com.nhn.pinpoint.common.util.MathUtils;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SimpleSamplerFactory {
|
||||
// profiler에 있는 Sampler와 기능이 동일하지만. profiler에 있는 sampler의 경우 좀더 파생 모델이 나와야 되므로 별도로 분리한다.
|
||||
public static final SimpleSampler FALSE_SAMPLER = new SimpleFalseSampler();
|
||||
public static final SimpleSampler TRUE_SAMPLER = new SimpleTrueSampler();
|
||||
|
||||
public static SimpleSampler createSampler(boolean sampling, int samplingRate) {
|
||||
if (!sampling || samplingRate <= 0) {
|
||||
return FALSE_SAMPLER;
|
||||
}
|
||||
if (samplingRate == 1) {
|
||||
return TRUE_SAMPLER;
|
||||
}
|
||||
return new SamplingRateSampler(samplingRate);
|
||||
}
|
||||
|
||||
public static class SimpleTrueSampler implements SimpleSampler {
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleFalseSampler implements SimpleSampler {
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SamplingRateSampler implements SimpleSampler {
|
||||
private final AtomicInteger counter = new AtomicInteger(0);
|
||||
private final int samplingRate;
|
||||
|
||||
public SamplingRateSampler(int samplingRate) {
|
||||
if (samplingRate <= 0) {
|
||||
throw new IllegalArgumentException("Invalid samplingRate " + samplingRate);
|
||||
}
|
||||
this.samplingRate = samplingRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSampling() {
|
||||
int samplingCount = MathUtils.fastAbs(counter.getAndIncrement());
|
||||
int isSampling = samplingCount % samplingRate;
|
||||
return isSampling == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
public static String defaultString(final String str, final String defaultStr) {
|
||||
return str == null ? defaultStr : str;
|
||||
}
|
||||
|
||||
public static String toString(final Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
public static String drop(final String str) {
|
||||
return drop(str, 64);
|
||||
}
|
||||
|
||||
public static String drop(final String str, final int length) {
|
||||
if (str == null) {
|
||||
return "null";
|
||||
}
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("negative length:" + length);
|
||||
}
|
||||
if (str.length() > length) {
|
||||
StringBuilder buffer = new StringBuilder(length + 10);
|
||||
buffer.append(str.substring(0, length));
|
||||
appendDropMessage(buffer, str.length());
|
||||
return buffer.toString();
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static void appendDrop(StringBuilder builder, final String str, final int length) {
|
||||
if (str == null) {
|
||||
return;
|
||||
}
|
||||
if (length < 0) {
|
||||
return;
|
||||
}
|
||||
if (str.length() > length) {
|
||||
builder.append(str.substring(0, length));
|
||||
appendDropMessage(builder, str.length());
|
||||
} else {
|
||||
builder.append(str);
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendDropMessage(StringBuilder buffer, int length) {
|
||||
buffer.append("...(");
|
||||
buffer.append(length);
|
||||
buffer.append(')');
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
public static String defaultString(final String str, final String defaultStr) {
|
||||
return str == null ? defaultStr : str;
|
||||
}
|
||||
|
||||
public static String toString(final Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
public static String drop(final String str) {
|
||||
return drop(str, 64);
|
||||
}
|
||||
|
||||
public static String drop(final String str, final int length) {
|
||||
if (str == null) {
|
||||
return "null";
|
||||
}
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("negative length:" + length);
|
||||
}
|
||||
if (str.length() > length) {
|
||||
StringBuilder buffer = new StringBuilder(length + 10);
|
||||
buffer.append(str.substring(0, length));
|
||||
appendDropMessage(buffer, str.length());
|
||||
return buffer.toString();
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static void appendDrop(StringBuilder builder, final String str, final int length) {
|
||||
if (str == null) {
|
||||
return;
|
||||
}
|
||||
if (length < 0) {
|
||||
return;
|
||||
}
|
||||
if (str.length() > length) {
|
||||
builder.append(str.substring(0, length));
|
||||
appendDropMessage(builder, str.length());
|
||||
} else {
|
||||
builder.append(str);
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendDropMessage(StringBuilder buffer, int length) {
|
||||
buffer.append("...(");
|
||||
buffer.append(length);
|
||||
buffer.append(')');
|
||||
}
|
||||
}
|
||||
|
||||
+40
-40
@@ -1,40 +1,40 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* WARN
|
||||
* 주의 ------------------ <br>
|
||||
* 이 data 전달자는 threadlocal로 전달하기 때문에. proxy클래스로 감쌋을 경우도 경계를 넘어 갈수 있으나. <br>
|
||||
* 상태를 가질수 없음. static method나 parameter의 인자로 들어오는 값을 잠시 저장하여 다른 곳으로 넘기는 경우만 사용해야 함. <br>
|
||||
* 절대 object의 상태를 가지고 있는데 사용할수 없음. <br>
|
||||
* 주의 ------------------
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThreadLocalMetadata<T> {
|
||||
private final String name;
|
||||
private final ThreadLocal<T> threadLocal;
|
||||
|
||||
public ThreadLocalMetadata(String metadataName) {
|
||||
this.name = metadataName;
|
||||
this.threadLocal = new ThreadLocal<T>();
|
||||
}
|
||||
|
||||
public void set(T object) {
|
||||
threadLocal.set(object);
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
public T getAndRemove() {
|
||||
final ThreadLocal<T> threadLocal = this.threadLocal;
|
||||
final T t = threadLocal.get();
|
||||
threadLocal.remove();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* WARN
|
||||
* 주의 ------------------ <br>
|
||||
* 이 data 전달자는 threadlocal로 전달하기 때문에. proxy클래스로 감쌋을 경우도 경계를 넘어 갈수 있으나. <br>
|
||||
* 상태를 가질수 없음. static method나 parameter의 인자로 들어오는 값을 잠시 저장하여 다른 곳으로 넘기는 경우만 사용해야 함. <br>
|
||||
* 절대 object의 상태를 가지고 있는데 사용할수 없음. <br>
|
||||
* 주의 ------------------
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThreadLocalMetadata<T> {
|
||||
private final String name;
|
||||
private final ThreadLocal<T> threadLocal;
|
||||
|
||||
public ThreadLocalMetadata(String metadataName) {
|
||||
this.name = metadataName;
|
||||
this.threadLocal = new ThreadLocal<T>();
|
||||
}
|
||||
|
||||
public void set(T object) {
|
||||
threadLocal.set(object);
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
||||
public T getAndRemove() {
|
||||
final ThreadLocal<T> threadLocal = this.threadLocal;
|
||||
final T t = threadLocal.get();
|
||||
threadLocal.remove();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class TimeObject {
|
||||
private long cancelTime;
|
||||
private long sendTime;
|
||||
|
||||
public void markCancelTime() {
|
||||
cancelTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getCancelTime() {
|
||||
return cancelTime;
|
||||
}
|
||||
|
||||
public void markSendTime() {
|
||||
this.sendTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getSendTime() {
|
||||
return System.currentTimeMillis() - this.sendTime;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class TimeObject {
|
||||
private long cancelTime;
|
||||
private long sendTime;
|
||||
|
||||
public void markCancelTime() {
|
||||
cancelTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getCancelTime() {
|
||||
return cancelTime;
|
||||
}
|
||||
|
||||
public void markSendTime() {
|
||||
this.sendTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getSendTime() {
|
||||
return System.currentTimeMillis() - this.sendTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.nhn.pinpoint.exception;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointException extends RuntimeException {
|
||||
public PinpointException() {
|
||||
}
|
||||
|
||||
public PinpointException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PinpointException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PinpointException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.exception;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointException extends RuntimeException {
|
||||
public PinpointException() {
|
||||
}
|
||||
|
||||
public PinpointException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PinpointException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PinpointException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
+50
-50
@@ -1,50 +1,50 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class AgentClassLoaderTest {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void boot() throws IOException, ClassNotFoundException {
|
||||
AgentClassLoader agentClassLoader = new AgentClassLoader(new URL[0]);
|
||||
agentClassLoader.setBootClass("com.nhn.pinpoint.bootstrap.DummyAgent");
|
||||
agentClassLoader.boot("test", new DummyInstrumentation(), new ProfilerConfig());
|
||||
// TODO logger가져오는 기능이 달라져서 확인이 필요함.
|
||||
// PLoggerBinder loggerBinder = (PLoggerBinder) agentClassLoader.initializeLoggerBinder();
|
||||
// PLogger test = loggerBinder.getLogger("test");
|
||||
// test.info("slf4j logger test");
|
||||
|
||||
}
|
||||
|
||||
private String getProjectLibDir() {
|
||||
// 필요는 없으나 protectionDomain을 테스트하기 좋아 내비둠.
|
||||
ProtectionDomain protectionDomain = AgentClassLoader.class.getProtectionDomain();
|
||||
CodeSource codeSource = protectionDomain.getCodeSource();
|
||||
URL location = codeSource.getLocation();
|
||||
|
||||
logger.info("lib location:" + location);
|
||||
String path = location.getPath();
|
||||
// file:/D:/nhn_source/pinpoint_project/pinpoint-tomcat-profiler/target/classes/
|
||||
int dirPath = path.lastIndexOf("target/classes/");
|
||||
if (dirPath == -1) {
|
||||
throw new RuntimeException("target/classes/ not found");
|
||||
}
|
||||
String projectDir = path.substring(1, dirPath);
|
||||
return projectDir + "src/test/lib";
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class AgentClassLoaderTest {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void boot() throws IOException, ClassNotFoundException {
|
||||
AgentClassLoader agentClassLoader = new AgentClassLoader(new URL[0]);
|
||||
agentClassLoader.setBootClass("com.nhn.pinpoint.bootstrap.DummyAgent");
|
||||
agentClassLoader.boot("test", new DummyInstrumentation(), new ProfilerConfig());
|
||||
// TODO logger가져오는 기능이 달라져서 확인이 필요함.
|
||||
// PLoggerBinder loggerBinder = (PLoggerBinder) agentClassLoader.initializeLoggerBinder();
|
||||
// PLogger test = loggerBinder.getLogger("test");
|
||||
// test.info("slf4j logger test");
|
||||
|
||||
}
|
||||
|
||||
private String getProjectLibDir() {
|
||||
// 필요는 없으나 protectionDomain을 테스트하기 좋아 내비둠.
|
||||
ProtectionDomain protectionDomain = AgentClassLoader.class.getProtectionDomain();
|
||||
CodeSource codeSource = protectionDomain.getCodeSource();
|
||||
URL location = codeSource.getLocation();
|
||||
|
||||
logger.info("lib location:" + location);
|
||||
String path = location.getPath();
|
||||
// file:/D:/nhn_source/pinpoint_project/pinpoint-tomcat-profiler/target/classes/
|
||||
int dirPath = path.lastIndexOf("target/classes/");
|
||||
if (dirPath == -1) {
|
||||
throw new RuntimeException("target/classes/ not found");
|
||||
}
|
||||
String projectDir = path.substring(1, dirPath);
|
||||
return projectDir + "src/test/lib";
|
||||
}
|
||||
}
|
||||
|
||||
+103
-103
@@ -1,103 +1,103 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.ClassPathResolver;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Ignore
|
||||
public class ClassPathResolverTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindAgentJar() throws Exception {
|
||||
String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" +
|
||||
"D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar";
|
||||
// D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean findAgentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(findAgentJar);
|
||||
|
||||
String agentJar = classPathResolver.getAgentJarName();
|
||||
Assert.assertEquals("pinpoint-bootstrap-0.0.2.jar", agentJar);
|
||||
|
||||
String agentPath = classPathResolver.getAgentJarFullPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar", agentPath);
|
||||
|
||||
String agentDirPath = classPathResolver.getAgentDirPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath );
|
||||
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAgentSnapshotJar() throws Exception {
|
||||
String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" +
|
||||
"D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib" +
|
||||
"/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar";
|
||||
// D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean findAgentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(findAgentJar);
|
||||
|
||||
String agentJar = classPathResolver.getAgentJarName();
|
||||
Assert.assertEquals("pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentJar);
|
||||
|
||||
String agentPath = classPathResolver.getAgentJarFullPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentPath);
|
||||
|
||||
String agentDirPath = classPathResolver.getAgentDirPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath );
|
||||
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAgentJar() {
|
||||
findAgentJar("pinpoint-bootstrap-0.0.2.jar");
|
||||
findAgentJar("pinpoint-bootstrap-1.0.0.jar");
|
||||
findAgentJar("pinpoint-bootstrap-1.10.20.jar");
|
||||
findAgentJar("pinpoint-bootstrap.jar");
|
||||
|
||||
|
||||
findAgentJarAssertFail("pinpoint-bootstrap-1.a.test.jar");
|
||||
findAgentJarAssertFail("pinpointbootstrap-1.a.test.jar");
|
||||
findAgentJarAssertFail("pinpointbootstrap.jar");
|
||||
}
|
||||
|
||||
private void findAgentJar(String path) {
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean agentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(agentJar);
|
||||
}
|
||||
|
||||
private void findAgentJarAssertFail(String path) {
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean agentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertFalse(agentJar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullArray() {
|
||||
String[] nullArray = null;
|
||||
try {
|
||||
for (String str : nullArray) {
|
||||
logger.warn("null");
|
||||
}
|
||||
Assert.fail();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.ClassPathResolver;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Ignore
|
||||
public class ClassPathResolverTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindAgentJar() throws Exception {
|
||||
String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" +
|
||||
"D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar";
|
||||
// D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean findAgentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(findAgentJar);
|
||||
|
||||
String agentJar = classPathResolver.getAgentJarName();
|
||||
Assert.assertEquals("pinpoint-bootstrap-0.0.2.jar", agentJar);
|
||||
|
||||
String agentPath = classPathResolver.getAgentJarFullPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar", agentPath);
|
||||
|
||||
String agentDirPath = classPathResolver.getAgentDirPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath );
|
||||
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAgentSnapshotJar() throws Exception {
|
||||
String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" +
|
||||
"D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib" +
|
||||
"/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar";
|
||||
// D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean findAgentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(findAgentJar);
|
||||
|
||||
String agentJar = classPathResolver.getAgentJarName();
|
||||
Assert.assertEquals("pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentJar);
|
||||
|
||||
String agentPath = classPathResolver.getAgentJarFullPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentPath);
|
||||
|
||||
String agentDirPath = classPathResolver.getAgentDirPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath );
|
||||
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAgentJar() {
|
||||
findAgentJar("pinpoint-bootstrap-0.0.2.jar");
|
||||
findAgentJar("pinpoint-bootstrap-1.0.0.jar");
|
||||
findAgentJar("pinpoint-bootstrap-1.10.20.jar");
|
||||
findAgentJar("pinpoint-bootstrap.jar");
|
||||
|
||||
|
||||
findAgentJarAssertFail("pinpoint-bootstrap-1.a.test.jar");
|
||||
findAgentJarAssertFail("pinpointbootstrap-1.a.test.jar");
|
||||
findAgentJarAssertFail("pinpointbootstrap.jar");
|
||||
}
|
||||
|
||||
private void findAgentJar(String path) {
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean agentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertTrue(agentJar);
|
||||
}
|
||||
|
||||
private void findAgentJarAssertFail(String path) {
|
||||
ClassPathResolver classPathResolver = new ClassPathResolver(path);
|
||||
boolean agentJar = classPathResolver.findAgentJar();
|
||||
Assert.assertFalse(agentJar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullArray() {
|
||||
String[] nullArray = null;
|
||||
try {
|
||||
for (String str : nullArray) {
|
||||
logger.warn("null");
|
||||
}
|
||||
Assert.fail();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +1,54 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyAgent implements Agent {
|
||||
|
||||
public DummyAgent(String agentArgs, Instrumentation instrumentation, ProfilerConfig profilerConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void started() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnector(String protocol, int port) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceContext getTraceContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public PLoggerBinder initializeLogger() {
|
||||
// return new PLoggerBinder() {
|
||||
// @Override
|
||||
// public PLogger getLogger(String name) {
|
||||
// return new DummyPLogger();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void shutdown() {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceContext;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class DummyAgent implements Agent {
|
||||
|
||||
public DummyAgent(String agentArgs, Instrumentation instrumentation, ProfilerConfig profilerConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnector(String protocol, int port) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceContext getTraceContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public PLoggerBinder initializeLogger() {
|
||||
// return new PLoggerBinder() {
|
||||
// @Override
|
||||
// public PLogger getLogger(String name) {
|
||||
// return new DummyPLogger();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void shutdown() {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
+87
-87
@@ -1,87 +1,87 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.lang.instrument.ClassDefinition;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyInstrumentation implements Instrumentation {
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer, boolean canRetransform) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeTransformer(ClassFileTransformer transformer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRetransformClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retransformClasses(Class<?>... classes) throws UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedefineClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException, UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModifiableClass(Class<?> theClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getAllLoadedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getInitiatedClasses(ClassLoader loader) {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectSize(Object objectToSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToBootstrapClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToSystemClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNativeMethodPrefixSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) {
|
||||
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import java.lang.instrument.ClassDefinition;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DummyInstrumentation implements Instrumentation {
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer, boolean canRetransform) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTransformer(ClassFileTransformer transformer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeTransformer(ClassFileTransformer transformer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRetransformClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retransformClasses(Class<?>... classes) throws UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRedefineClassesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redefineClasses(ClassDefinition... definitions) throws ClassNotFoundException, UnmodifiableClassException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModifiableClass(Class<?> theClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getAllLoadedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getInitiatedClasses(ClassLoader loader) {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getObjectSize(Object objectToSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToBootstrapClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToSystemClassLoaderSearch(JarFile jarfile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNativeMethodPrefixSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointBootStrapTest {
|
||||
@Test
|
||||
public void testDuplicatedLoadCheck() throws Exception {
|
||||
PinpointBootStrap.premain("test", new DummyInstrumentation());
|
||||
String exist = System.getProperty(PinpointBootStrap.BOOT_STRAP_LOAD_STATE);
|
||||
Assert.assertTrue(exist != null);
|
||||
|
||||
PinpointBootStrap.premain("test", new DummyInstrumentation());
|
||||
// 중복 된경우를 체크 할수 있는 방법이 로그 확인 뿐이 없나??
|
||||
|
||||
String recheck = System.getProperty(PinpointBootStrap.BOOT_STRAP_LOAD_STATE);
|
||||
Assert.assertEquals(exist, recheck);
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointBootStrapTest {
|
||||
@Test
|
||||
public void testDuplicatedLoadCheck() throws Exception {
|
||||
PinpointBootStrap.premain("test", new DummyInstrumentation());
|
||||
String exist = System.getProperty(PinpointBootStrap.BOOT_STRAP_LOAD_STATE);
|
||||
Assert.assertTrue(exist != null);
|
||||
|
||||
PinpointBootStrap.premain("test", new DummyInstrumentation());
|
||||
// 중복 된경우를 체크 할수 있는 방법이 로그 확인 뿐이 없나??
|
||||
|
||||
String recheck = System.getProperty(PinpointBootStrap.BOOT_STRAP_LOAD_STATE);
|
||||
Assert.assertEquals(exist, recheck);
|
||||
}
|
||||
}
|
||||
|
||||
+33
-33
@@ -1,33 +1,33 @@
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointURLClassLoaderTest {
|
||||
|
||||
@Test
|
||||
public void testOnLoadClass() throws Exception {
|
||||
|
||||
PinpointURLClassLoader cl = new PinpointURLClassLoader(new URL[]{}, Thread.currentThread().getContextClassLoader());
|
||||
try {
|
||||
cl.loadClass("test");
|
||||
Assert.fail();
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
|
||||
// try {
|
||||
// cl.loadClass("com.nhn.pinpoint.profiler.DefaultAgent");
|
||||
// } catch (ClassNotFoundException e) {
|
||||
//
|
||||
// }
|
||||
// 사실 위에 코드로 정상 테스트가 가능해야 겠지만 bootstrap testcase에서는 jar라서 찾을수 없음
|
||||
// 아래 코드로 로드 하는 클래스인지 체크 정도만 하자.
|
||||
// URL에 다가 pinpoint.jar를 걸면 되긴하겠지만. 관리가 힘들듯함.
|
||||
Assert.assertTrue(cl.onLoadClass("com.nhn.pinpoint.profiler.DefaultAgent"));
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class PinpointURLClassLoaderTest {
|
||||
|
||||
@Test
|
||||
public void testOnLoadClass() throws Exception {
|
||||
|
||||
PinpointURLClassLoader cl = new PinpointURLClassLoader(new URL[]{}, Thread.currentThread().getContextClassLoader());
|
||||
try {
|
||||
cl.loadClass("test");
|
||||
Assert.fail();
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
|
||||
// try {
|
||||
// cl.loadClass("com.nhn.pinpoint.profiler.DefaultAgent");
|
||||
// } catch (ClassNotFoundException e) {
|
||||
//
|
||||
// }
|
||||
// 사실 위에 코드로 정상 테스트가 가능해야 겠지만 bootstrap testcase에서는 jar라서 찾을수 없음
|
||||
// 아래 코드로 로드 하는 클래스인지 체크 정도만 하자.
|
||||
// URL에 다가 pinpoint.jar를 걸면 되긴하겠지만. 관리가 힘들듯함.
|
||||
Assert.assertTrue(cl.onLoadClass("com.nhn.pinpoint.profiler.DefaultAgent"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package com.nhn.pinpoint.bootstrap.config;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DumpTypeTest {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void find() {
|
||||
DumpType none = DumpType.valueOf("ALWAYS");
|
||||
logger.debug("type:{}", none);
|
||||
|
||||
try {
|
||||
DumpType.valueOf("error");
|
||||
Assert.fail("not found");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.config;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class DumpTypeTest {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void find() {
|
||||
DumpType none = DumpType.valueOf("ALWAYS");
|
||||
logger.debug("type:{}", none);
|
||||
|
||||
try {
|
||||
DumpType.valueOf("error");
|
||||
Assert.fail("not found");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ public class ProfilerConfigTest {
|
||||
profilerConfig.readConfigFile(path);
|
||||
|
||||
Assert.assertEquals(profilerConfig.isIoBufferingEnable(), false);
|
||||
Assert.assertEquals(profilerConfig.getIoBufferingBufferBufferSize(), 30);
|
||||
Assert.assertEquals(profilerConfig.getIoBufferingBufferSize(), 30);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ public class ProfilerConfigTest {
|
||||
profilerConfig.readConfigFile(path);
|
||||
|
||||
Assert.assertEquals(profilerConfig.isIoBufferingEnable(), true);
|
||||
Assert.assertEquals(profilerConfig.getIoBufferingBufferBufferSize(), 10);
|
||||
Assert.assertEquals(profilerConfig.getIoBufferingBufferSize(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=true
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=true
|
||||
profiler.io.buffering.buffersize=10
|
||||
@@ -1,5 +1,5 @@
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=false
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=false
|
||||
profiler.io.buffering.buffersize=30
|
||||
@@ -1,7 +1,7 @@
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=false
|
||||
profiler.io.buffering.buffersize=30
|
||||
|
||||
profiler.apache.httpclient4.cookie.dumptype=EXCEPTION
|
||||
|
||||
|
||||
profiler.io.buffering.enable=false
|
||||
profiler.io.buffering.buffersize=30
|
||||
|
||||
profiler.tcpdatasender.command.accept.enable=true
|
||||
+187
-187
@@ -1,187 +1,187 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceId;
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTrace implements Trace {
|
||||
|
||||
private long beforeTime;
|
||||
private long afterTime;
|
||||
|
||||
private boolean sampled = true;
|
||||
|
||||
@Override
|
||||
public void markBeforeTime() {
|
||||
beforeTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBeforeTime() {
|
||||
return beforeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
afterTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAfterTime() {
|
||||
return afterTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceId getTraceId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSampled(boolean sampled) {
|
||||
this.sampled = sampled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSampled() {
|
||||
return sampled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordException(Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object args, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args, int start, int end) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApiCachedString(MethodDescriptor methodDescriptor, String args, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingResult recordSqlInfo(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult, String bindValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, String value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, int value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, Object value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordServiceType(ServiceType serviceType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRpcName(String rpc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordDestinationId(String destinationId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordEndPoint(String endPoint) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRemoteAddress(String remoteAddress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordNextSpanId(long spanId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordParentApplication(String parentApplicationName, short parentApplicationType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAcceptorHost(String host) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackFrameId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockBegin() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockBegin(int stackId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceRootBlockEnd() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockEnd() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockEnd(int stackId) {
|
||||
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import com.nhn.pinpoint.bootstrap.context.TraceId;
|
||||
import com.nhn.pinpoint.common.AnnotationKey;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTrace implements Trace {
|
||||
|
||||
private long beforeTime;
|
||||
private long afterTime;
|
||||
|
||||
private boolean sampled = true;
|
||||
|
||||
@Override
|
||||
public void markBeforeTime() {
|
||||
beforeTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBeforeTime() {
|
||||
return beforeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
afterTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAfterTime() {
|
||||
return afterTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceId getTraceId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSampled(boolean sampled) {
|
||||
this.sampled = sampled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSampled() {
|
||||
return sampled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordException(Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object args, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApi(MethodDescriptor methodDescriptor, Object[] args, int start, int end) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordApiCachedString(MethodDescriptor methodDescriptor, String args, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingResult recordSqlInfo(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult, String bindValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, String value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, int value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, Object value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordServiceType(ServiceType serviceType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRpcName(String rpc) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordDestinationId(String destinationId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordEndPoint(String endPoint) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordRemoteAddress(String remoteAddress) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordNextSpanId(long spanId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordParentApplication(String parentApplicationName, short parentApplicationType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAcceptorHost(String host) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackFrameId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockBegin() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockBegin(int stackId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceRootBlockEnd() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockEnd() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceBlockEnd(int stackId) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+139
-139
@@ -1,139 +1,139 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.*;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTraceContext implements TraceContext {
|
||||
|
||||
private Trace trace;
|
||||
|
||||
public void setTrace(Trace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace currentTraceObject() {
|
||||
if (trace == null) {
|
||||
return null;
|
||||
}
|
||||
if (trace.canSampled()) {
|
||||
return null;
|
||||
}
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace currentRawTraceObject() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace continueTraceObject(TraceId traceID) {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace newTraceObject() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachTraceObject() {
|
||||
trace = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAgentId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApplicationName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAgentStartTime() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getServerTypeCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cacheApi(MethodDescriptor methodDescriptor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cacheString(String value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingResult parseSql(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseInfo parseJdbcUrl(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseInfo createDatabaseInfo(ServiceType type, ServiceType executeQueryType, String url, int port, String databaseId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceId createTraceId(String transactionId, long parentSpanID, long spanID, short flags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace disableSampling() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metric getRpcMetric(ServiceType serviceType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordContextMetricIsError() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordContextMetric(int elapsedTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordUserAcceptResponseTime(int elapsedTime) {
|
||||
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.context.*;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTraceContext implements TraceContext {
|
||||
|
||||
private Trace trace;
|
||||
|
||||
public void setTrace(Trace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace currentTraceObject() {
|
||||
if (trace == null) {
|
||||
return null;
|
||||
}
|
||||
if (trace.canSampled()) {
|
||||
return null;
|
||||
}
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace currentRawTraceObject() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace continueTraceObject(TraceId traceID) {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace newTraceObject() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachTraceObject() {
|
||||
trace = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAgentId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApplicationName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAgentStartTime() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getServerTypeCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cacheApi(MethodDescriptor methodDescriptor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cacheString(String value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingResult parseSql(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseInfo parseJdbcUrl(String sql) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseInfo createDatabaseInfo(ServiceType type, ServiceType executeQueryType, String url, int port, String databaseId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceId createTraceId(String transactionId, long parentSpanID, long spanID, short flags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trace disableSampling() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfilerConfig getProfilerConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metric getRpcMetric(ServiceType serviceType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordContextMetricIsError() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordContextMetric(int elapsedTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordUserAcceptResponseTime(int elapsedTime) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+183
-183
@@ -1,184 +1,184 @@
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
public class SpanSimpleAroundInterceptorTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@Test
|
||||
public void lifeCycle() throws Exception {
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor();
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeAfterExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceCreateFail() {
|
||||
MockTraceContext context = mock(MockTraceContext.class);
|
||||
when(context.newTraceObject()).thenReturn(null);
|
||||
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor();
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkTraceCreateFailInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
private void checkSpanInterceptor(MockTraceContext context, TestSpanSimpleAroundInterceptor interceptor) {
|
||||
Trace createTrace = interceptor.createTrace(null, null);
|
||||
interceptor.before(new Object(), null);
|
||||
Assert.assertEquals(interceptor.getBeforeTouchCount(), 1);
|
||||
Trace before = context.currentRawTraceObject();
|
||||
Assert.assertEquals(createTrace, before);
|
||||
|
||||
interceptor.after(new Object(), null, null, null);
|
||||
Assert.assertEquals(interceptor.getAfterTouchCount(), 1);
|
||||
Trace after = context.currentRawTraceObject();
|
||||
Assert.assertNull(after);
|
||||
}
|
||||
|
||||
private void checkTraceCreateFailInterceptor(MockTraceContext context, TestSpanSimpleAroundInterceptor interceptor) {
|
||||
Trace createTrace = interceptor.createTrace(null, null);
|
||||
Assert.assertNull(createTrace);
|
||||
interceptor.before(new Object(), null);
|
||||
|
||||
Assert.assertEquals(interceptor.getBeforeTouchCount(), 0);
|
||||
Assert.assertNull(context.currentRawTraceObject());
|
||||
|
||||
interceptor.after(new Object(), null, null, null);
|
||||
Assert.assertEquals(interceptor.getAfterTouchCount(), 0);
|
||||
Assert.assertNull(context.currentRawTraceObject());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateTrace() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoInAfterTrace() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public static class TestSpanSimpleAroundInterceptor extends SpanSimpleAroundInterceptor {
|
||||
private int beforeTouchCount;
|
||||
private int afterTouchCount;
|
||||
|
||||
public TestSpanSimpleAroundInterceptor() {
|
||||
super(TestSpanSimpleAroundInterceptor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Trace createTrace(Object target, Object[] args) {
|
||||
return getTraceContext().newTraceObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
}
|
||||
|
||||
protected void touchBefore() {
|
||||
beforeTouchCount++;
|
||||
}
|
||||
|
||||
public int getAfterTouchCount() {
|
||||
return afterTouchCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
}
|
||||
|
||||
protected void touchAfter() {
|
||||
afterTouchCount++;
|
||||
}
|
||||
|
||||
public int getBeforeTouchCount() {
|
||||
return beforeTouchCount;
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.interceptor;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.context.RecordableTrace;
|
||||
import com.nhn.pinpoint.bootstrap.context.Trace;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
public class SpanSimpleAroundInterceptorTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@Test
|
||||
public void lifeCycle() throws Exception {
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor();
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeAfterExceptionLifeCycle() throws Exception {
|
||||
|
||||
MockTraceContext context = new MockTraceContext();
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor() {
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkSpanInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceCreateFail() {
|
||||
MockTraceContext context = mock(MockTraceContext.class);
|
||||
when(context.newTraceObject()).thenReturn(null);
|
||||
|
||||
MockTrace mockTrace = new MockTrace();
|
||||
context.setTrace(mockTrace);
|
||||
|
||||
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor();
|
||||
interceptor.setTraceContext(context);
|
||||
|
||||
checkTraceCreateFailInterceptor(context, interceptor);
|
||||
}
|
||||
|
||||
private void checkSpanInterceptor(MockTraceContext context, TestSpanSimpleAroundInterceptor interceptor) {
|
||||
Trace createTrace = interceptor.createTrace(null, null);
|
||||
interceptor.before(new Object(), null);
|
||||
Assert.assertEquals(interceptor.getBeforeTouchCount(), 1);
|
||||
Trace before = context.currentRawTraceObject();
|
||||
Assert.assertEquals(createTrace, before);
|
||||
|
||||
interceptor.after(new Object(), null, null, null);
|
||||
Assert.assertEquals(interceptor.getAfterTouchCount(), 1);
|
||||
Trace after = context.currentRawTraceObject();
|
||||
Assert.assertNull(after);
|
||||
}
|
||||
|
||||
private void checkTraceCreateFailInterceptor(MockTraceContext context, TestSpanSimpleAroundInterceptor interceptor) {
|
||||
Trace createTrace = interceptor.createTrace(null, null);
|
||||
Assert.assertNull(createTrace);
|
||||
interceptor.before(new Object(), null);
|
||||
|
||||
Assert.assertEquals(interceptor.getBeforeTouchCount(), 0);
|
||||
Assert.assertNull(context.currentRawTraceObject());
|
||||
|
||||
interceptor.after(new Object(), null, null, null);
|
||||
Assert.assertEquals(interceptor.getAfterTouchCount(), 0);
|
||||
Assert.assertNull(context.currentRawTraceObject());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateTrace() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoInAfterTrace() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public static class TestSpanSimpleAroundInterceptor extends SpanSimpleAroundInterceptor {
|
||||
private int beforeTouchCount;
|
||||
private int afterTouchCount;
|
||||
|
||||
public TestSpanSimpleAroundInterceptor() {
|
||||
super(TestSpanSimpleAroundInterceptor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Trace createTrace(Object target, Object[] args) {
|
||||
return getTraceContext().newTraceObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInBeforeTrace(RecordableTrace trace, Object target, Object[] args) {
|
||||
touchBefore();
|
||||
}
|
||||
|
||||
protected void touchBefore() {
|
||||
beforeTouchCount++;
|
||||
}
|
||||
|
||||
public int getAfterTouchCount() {
|
||||
return afterTouchCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
||||
touchAfter();
|
||||
}
|
||||
|
||||
protected void touchAfter() {
|
||||
afterTouchCount++;
|
||||
}
|
||||
|
||||
public int getBeforeTouchCount() {
|
||||
return beforeTouchCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LocalHostTest {
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException, SocketException {
|
||||
System.out.println("Canonical:" + InetAddress.getLocalHost().getCanonicalHostName());
|
||||
System.out.println("normal:" + InetAddress.getLocalHost().getHostName());
|
||||
|
||||
System.out.println("NetworkInterface");
|
||||
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (networkInterfaces.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||
System.out.println("Nic:" + networkInterface);
|
||||
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
||||
while (inetAddresses.hasMoreElements()) {
|
||||
InetAddress inetAddress = inetAddresses.nextElement();
|
||||
System.out.println(inetAddress.getCanonicalHostName());
|
||||
System.out.println(inetAddress.getHostName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class LocalHostTest {
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException, SocketException {
|
||||
System.out.println("Canonical:" + InetAddress.getLocalHost().getCanonicalHostName());
|
||||
System.out.println("normal:" + InetAddress.getLocalHost().getHostName());
|
||||
|
||||
System.out.println("NetworkInterface");
|
||||
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (networkInterfaces.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||
System.out.println("Nic:" + networkInterface);
|
||||
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
||||
while (inetAddresses.hasMoreElements()) {
|
||||
InetAddress inetAddress = inetAddresses.nextElement();
|
||||
System.out.println(inetAddress.getCanonicalHostName());
|
||||
System.out.println(inetAddress.getHostName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MetaObjectTest {
|
||||
private String test;
|
||||
|
||||
public String getTest() {
|
||||
return test;
|
||||
}
|
||||
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInvoke() throws Exception {
|
||||
MetaObjectTest test = new MetaObjectTest();
|
||||
|
||||
MetaObject metaObject = new MetaObject("setTest", String.class);
|
||||
Object result = metaObject.invoke(test, "set");
|
||||
Assert.assertEquals(test.getTest(), "set");
|
||||
Assert.assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInvoke() throws Exception {
|
||||
MetaObjectTest test = new MetaObjectTest();
|
||||
test.setTest("get");
|
||||
|
||||
MetaObject metaObject = new MetaObject("getTest");
|
||||
Object result = metaObject.invoke(test);
|
||||
Assert.assertEquals(test.getTest(), result);
|
||||
}
|
||||
}
|
||||
package com.nhn.pinpoint.bootstrap.util;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MetaObjectTest {
|
||||
private String test;
|
||||
|
||||
public String getTest() {
|
||||
return test;
|
||||
}
|
||||
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInvoke() throws Exception {
|
||||
MetaObjectTest test = new MetaObjectTest();
|
||||
|
||||
MetaObject metaObject = new MetaObject("setTest", String.class);
|
||||
Object result = metaObject.invoke(test, "set");
|
||||
Assert.assertEquals(test.getTest(), "set");
|
||||
Assert.assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInvoke() throws Exception {
|
||||
MetaObjectTest test = new MetaObjectTest();
|
||||
test.setTest("get");
|
||||
|
||||
MetaObject metaObject = new MetaObject("getTest");
|
||||
Object result = metaObject.invoke(test);
|
||||
Assert.assertEquals(test.getTest(), result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1.}) %m%n" />
|
||||
<!-- %L 옵션은 라인넘버가 출력되나 속도저하가 심하다. -->
|
||||
<!--<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-30c{1}) %m%n" />-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="dailyRollingFile" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="file" value="${pinpoint.log}/pinpoint.log" />
|
||||
<param name="Append" value="true" />
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
|
||||
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1.}) %m%n" />
|
||||
<!-- %L 옵션은 라인넘버가 출력되나 속도저하가 심하다. -->
|
||||
<!--<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-30c{1}) %m%n" />-->
|
||||
</layout>
|
||||
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<logger name="com.nhn.pinpoint" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="console" />
|
||||
<!-- testcase용은 파일로 남길 필요가 없음. -->
|
||||
<!--<appender-ref ref="dailyRollingFile" />-->
|
||||
</logger>
|
||||
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="console" />
|
||||
<!-- testcase용은 파일로 남길 필요가 없음. -->
|
||||
<!--<appender-ref ref="dailyRollingFile" />-->
|
||||
</root>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1.}) %m%n" />
|
||||
<!-- %L 옵션은 라인넘버가 출력되나 속도저하가 심하다. -->
|
||||
<!--<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-30c{1}) %m%n" />-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="dailyRollingFile" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="file" value="${pinpoint.log}/pinpoint.log" />
|
||||
<param name="Append" value="true" />
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
|
||||
|
||||
<layout class="org.apache.log4j.EnhancedPatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-35c{1.}) %m%n" />
|
||||
<!-- %L 옵션은 라인넘버가 출력되나 속도저하가 심하다. -->
|
||||
<!--<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p](%-30c{1}) %m%n" />-->
|
||||
</layout>
|
||||
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<logger name="com.nhn.pinpoint" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="console" />
|
||||
<!-- testcase용은 파일로 남길 필요가 없음. -->
|
||||
<!--<appender-ref ref="dailyRollingFile" />-->
|
||||
</logger>
|
||||
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="console" />
|
||||
<!-- testcase용은 파일로 남길 필요가 없음. -->
|
||||
<!--<appender-ref ref="dailyRollingFile" />-->
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
+87
-87
@@ -1,87 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
This configuration file was written by the eclipse-cs plugin configuration editor
|
||||
-->
|
||||
<!--
|
||||
Checkstyle-Configuration: nhn-0.5
|
||||
Description: none
|
||||
-->
|
||||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
<module name="Checker">
|
||||
<property name="severity" value="warning"/>
|
||||
<module name="TreeWalker">
|
||||
<property name="tabWidth" value="4"/>
|
||||
<property name="charset" value="UTF-8"/>
|
||||
<module name="JavadocMethod">
|
||||
<property name="allowMissingPropertyJavadoc" value="true"/>
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="JavadocType">
|
||||
<property name="authorFormat" value=".+"/>
|
||||
</module>
|
||||
<module name="ConstantName">
|
||||
<property name="format" value="^[A-Z][A-Z0-9]+(_[A-Z0-9]+)*$"/>
|
||||
</module>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^(com\.naver\.|com\.nhncorp\.|com\.nhn\.|com\.hangame\.){1}([a-z])+(\.[a-z_][a-z0-9_]*)*$"/>
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="StaticVariableName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<property name="format" value="^[A-Z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="LineLength">
|
||||
<property name="max" value="200"/>
|
||||
<property name="tabWidth" value="4"/>
|
||||
</module>
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore">
|
||||
<property name="tokens" value="SEMI,DOT,POST_DEC,POST_INC"/>
|
||||
</module>
|
||||
<module name="OperatorWrap"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad">
|
||||
<property name="tokens" value="RPAREN,TYPECAST"/>
|
||||
</module>
|
||||
<module name="WhitespaceAfter">
|
||||
<property name="tokens" value="COMMA,SEMI"/>
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
|
||||
</module>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="RightCurly"/>
|
||||
<module name="ActionClass"/>
|
||||
<module name="BOClass"/>
|
||||
<module name="DAOClass"/>
|
||||
<module name="TempVariable"/>
|
||||
<module name="BracketSpace"/>
|
||||
<module name="Indentation"/>
|
||||
<module name="AfterPackage"/>
|
||||
<module name="AfterClass"/>
|
||||
<module name="AfterEnum"/>
|
||||
<module name="AfterAnnotation"/>
|
||||
<module name="AfterAnnotations"/>
|
||||
<module name="AfterSemicolon"/>
|
||||
<module name="ControlStatement"/>
|
||||
<module name="DAOMethod"/>
|
||||
<module name="AfterMethod"/>
|
||||
<module name="NewLine"/>
|
||||
<module name="NewLine"/>
|
||||
</module>
|
||||
</module>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
This configuration file was written by the eclipse-cs plugin configuration editor
|
||||
-->
|
||||
<!--
|
||||
Checkstyle-Configuration: nhn-0.5
|
||||
Description: none
|
||||
-->
|
||||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
<module name="Checker">
|
||||
<property name="severity" value="warning"/>
|
||||
<module name="TreeWalker">
|
||||
<property name="tabWidth" value="4"/>
|
||||
<property name="charset" value="UTF-8"/>
|
||||
<module name="JavadocMethod">
|
||||
<property name="allowMissingPropertyJavadoc" value="true"/>
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
</module>
|
||||
<module name="JavadocType">
|
||||
<property name="authorFormat" value=".+"/>
|
||||
</module>
|
||||
<module name="ConstantName">
|
||||
<property name="format" value="^[A-Z][A-Z0-9]+(_[A-Z0-9]+)*$"/>
|
||||
</module>
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<module name="LocalVariableName"/>
|
||||
<module name="MemberName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^(com\.naver\.|com\.nhncorp\.|com\.nhn\.|com\.hangame\.){1}([a-z])+(\.[a-z_][a-z0-9_]*)*$"/>
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="StaticVariableName">
|
||||
<property name="format" value="^[a-z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<property name="format" value="^[A-Z][a-zA-Z0-9]+$"/>
|
||||
</module>
|
||||
<module name="LineLength">
|
||||
<property name="max" value="200"/>
|
||||
<property name="tabWidth" value="4"/>
|
||||
</module>
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore">
|
||||
<property name="tokens" value="SEMI,DOT,POST_DEC,POST_INC"/>
|
||||
</module>
|
||||
<module name="OperatorWrap"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad">
|
||||
<property name="tokens" value="RPAREN,TYPECAST"/>
|
||||
</module>
|
||||
<module name="WhitespaceAfter">
|
||||
<property name="tokens" value="COMMA,SEMI"/>
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
|
||||
</module>
|
||||
<module name="LeftCurly"/>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="RightCurly"/>
|
||||
<module name="ActionClass"/>
|
||||
<module name="BOClass"/>
|
||||
<module name="DAOClass"/>
|
||||
<module name="TempVariable"/>
|
||||
<module name="BracketSpace"/>
|
||||
<module name="Indentation"/>
|
||||
<module name="AfterPackage"/>
|
||||
<module name="AfterClass"/>
|
||||
<module name="AfterEnum"/>
|
||||
<module name="AfterAnnotation"/>
|
||||
<module name="AfterAnnotations"/>
|
||||
<module name="AfterSemicolon"/>
|
||||
<module name="ControlStatement"/>
|
||||
<module name="DAOMethod"/>
|
||||
<module name="AfterMethod"/>
|
||||
<module name="NewLine"/>
|
||||
<module name="NewLine"/>
|
||||
</module>
|
||||
</module>
|
||||
|
||||
+14
-14
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
||||
|
||||
<suppressions>
|
||||
<suppress checks="StrictDuplicateCodeCheck" files="AnnotationValidationConfigurationBuilder.java"/>
|
||||
<suppress checks="ModifiedControlVariableCheck" files="ErrorUtil.java" lines="31"/>
|
||||
<suppress checks="SuperCloneCheck" files="ResultCacheEntry.java" />
|
||||
<suppress checks="SuperCloneCheck" files="ServiceExecutionContext.java" />
|
||||
<suppress checks="NPathComplexityCheck" files="DefaultUsfActionInvocation.java" />
|
||||
<suppress checks="CyclomaticComplexityCheck" files="StringUtil.java" />
|
||||
<suppress checks="NPathComplexityCheck" files="MessageMethod.java" />
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
||||
|
||||
<suppressions>
|
||||
<suppress checks="StrictDuplicateCodeCheck" files="AnnotationValidationConfigurationBuilder.java"/>
|
||||
<suppress checks="ModifiedControlVariableCheck" files="ErrorUtil.java" lines="31"/>
|
||||
<suppress checks="SuperCloneCheck" files="ResultCacheEntry.java" />
|
||||
<suppress checks="SuperCloneCheck" files="ServiceExecutionContext.java" />
|
||||
<suppress checks="NPathComplexityCheck" files="DefaultUsfActionInvocation.java" />
|
||||
<suppress checks="CyclomaticComplexityCheck" files="StringUtil.java" />
|
||||
<suppress checks="NPathComplexityCheck" files="MessageMethod.java" />
|
||||
</suppressions>
|
||||
@@ -1,13 +1,13 @@
|
||||
<FindBugsFilter>
|
||||
<!--
|
||||
<Match> <Class name="com.foobar.ClassWithSomeBugsMatched" /> <Bug
|
||||
code="DE,UrF,SIC" /> </Match>
|
||||
-->
|
||||
<!--<Match>-->
|
||||
<!--<Class name="com.nhncorp.usf.core.result.RedirectResult" />-->
|
||||
<!--<Bug pattern="DM_CONVERT_CASE" />-->
|
||||
<!--</Match>-->
|
||||
<!--
|
||||
Match all XYZ violations. <Match> <Bug code="XYZ" /> </Match>
|
||||
-->
|
||||
<FindBugsFilter>
|
||||
<!--
|
||||
<Match> <Class name="com.foobar.ClassWithSomeBugsMatched" /> <Bug
|
||||
code="DE,UrF,SIC" /> </Match>
|
||||
-->
|
||||
<!--<Match>-->
|
||||
<!--<Class name="com.nhncorp.usf.core.result.RedirectResult" />-->
|
||||
<!--<Bug pattern="DM_CONVERT_CASE" />-->
|
||||
<!--</Match>-->
|
||||
<!--
|
||||
Match all XYZ violations. <Match> <Bug code="XYZ" /> </Match>
|
||||
-->
|
||||
</FindBugsFilter>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import com.nhn.pinpoint.collector.config.CollectorConfiguration;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public abstract class AbstractClusterService implements ClusterService {
|
||||
|
||||
protected final CollectorConfiguration config;
|
||||
protected final ClusterPointRouter clusterPointRouter;
|
||||
|
||||
public AbstractClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
|
||||
this.config = config;
|
||||
this.clusterPointRouter = clusterPointRouter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
public interface ClusterPoint {
|
||||
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.apache.thrift.TException;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.collector.util.CollectorUtils;
|
||||
import com.nhn.pinpoint.rpc.Future;
|
||||
import com.nhn.pinpoint.rpc.ResponseMessage;
|
||||
import com.nhn.pinpoint.rpc.client.MessageListener;
|
||||
import com.nhn.pinpoint.rpc.packet.RequestPacket;
|
||||
import com.nhn.pinpoint.rpc.packet.ResponsePacket;
|
||||
import com.nhn.pinpoint.rpc.packet.SendPacket;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
import com.nhn.pinpoint.thrift.dto.TResult;
|
||||
import com.nhn.pinpoint.thrift.dto.command.TCommandTransfer;
|
||||
import com.nhn.pinpoint.thrift.io.DeserializerFactory;
|
||||
import com.nhn.pinpoint.thrift.io.HeaderTBaseDeserializer;
|
||||
import com.nhn.pinpoint.thrift.io.HeaderTBaseSerializer;
|
||||
import com.nhn.pinpoint.thrift.io.SerializerFactory;
|
||||
import com.nhn.pinpoint.thrift.io.TCommandTypeVersion;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public class ClusterPointRouter {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final String serverIdentifier = CollectorUtils.getServerIdentifier();
|
||||
|
||||
private final ProfilerClusterPoint profilerClusterPoint;
|
||||
private final WebClusterPoint webClusterPoint;
|
||||
|
||||
@Autowired
|
||||
private SerializerFactory commandSerializerFactory;
|
||||
|
||||
@Autowired
|
||||
private DeserializerFactory commandDeserializerFactory;
|
||||
|
||||
public ClusterPointRouter() {
|
||||
this.profilerClusterPoint = new ProfilerClusterPoint();
|
||||
this.webClusterPoint = new WebClusterPoint(serverIdentifier, new WebPointMessageListener());
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void stop() {
|
||||
if (webClusterPoint != null) {
|
||||
webClusterPoint.close();
|
||||
}
|
||||
}
|
||||
|
||||
public ProfilerClusterPoint getProfilerClusterPoint() {
|
||||
return profilerClusterPoint;
|
||||
}
|
||||
|
||||
public WebClusterPoint getWebClusterPoint() {
|
||||
return webClusterPoint;
|
||||
}
|
||||
|
||||
private byte[] serialize(TBase result) {
|
||||
if (result == null) {
|
||||
logger.warn("tBase may not be null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
HeaderTBaseSerializer serializer = commandSerializerFactory.createSerializer();
|
||||
byte[] payload = serializer.serialize(result);
|
||||
return payload;
|
||||
} catch (TException e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private TBase deserialize(byte[] payload) {
|
||||
if (payload == null) {
|
||||
logger.warn("Payload may not be null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
final HeaderTBaseDeserializer deserializer = commandDeserializerFactory.createDeserializer();
|
||||
TBase<?, ?> tBase = deserializer.deserialize(payload);
|
||||
return tBase;
|
||||
} catch (TException e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
class WebPointMessageListener implements MessageListener {
|
||||
|
||||
@Override
|
||||
public void handleSend(SendPacket sendPacket, Channel channel) {
|
||||
logger.info("Received SendPacket {} {}.", sendPacket, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(RequestPacket requestPacket, Channel channel) {
|
||||
logger.info("Received RequestPacket {} {}.", requestPacket, channel);
|
||||
|
||||
TBase<?, ?> request = deserialize(requestPacket.getPayload());
|
||||
|
||||
if (request == null) {
|
||||
TResult tResult = new TResult(false);
|
||||
tResult.setMessage("Unexpected decode result.");
|
||||
|
||||
channel.write(new ResponsePacket(requestPacket.getRequestId(), serialize(tResult)));
|
||||
} else if (request instanceof TCommandTransfer) {
|
||||
|
||||
String applicationName = ((TCommandTransfer) request).getApplicationName();
|
||||
String agentId = ((TCommandTransfer) request).getAgentId();
|
||||
byte[] payload = ((TCommandTransfer) request).getPayload();
|
||||
|
||||
TBase command = deserialize(payload);
|
||||
|
||||
ChannelContext channelContext = profilerClusterPoint.getChannelContext(applicationName, agentId, -1);
|
||||
if (channelContext == null) {
|
||||
TResult result = new TResult(false);
|
||||
result.setMessage(applicationName + "/" + agentId + " can't find suitable ChannelContext.");
|
||||
channel.write(new ResponsePacket(requestPacket.getRequestId(), serialize(result)));
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Object, Object> proeprties = channelContext.getChannelProperties();
|
||||
String version = MapUtils.getString(proeprties, AgentPropertiesType.VERSION.getName());
|
||||
|
||||
TCommandTypeVersion commandVersion = TCommandTypeVersion.getVersion(version);
|
||||
if (commandVersion.isSupportCommand(command)) {
|
||||
Future<ResponseMessage> future = channelContext.getSocketChannel().sendRequestMessage(payload);
|
||||
future.await();
|
||||
ResponseMessage responseMessage = future.getResult();
|
||||
|
||||
channel.write(new ResponsePacket(requestPacket.getRequestId(), responseMessage.getMessage()));
|
||||
} else {
|
||||
TResult result = new TResult(false);
|
||||
result.setMessage(applicationName + "/" + agentId + " unsupported command(" + command + ") type.");
|
||||
|
||||
channel.write(new ResponsePacket(requestPacket.getRequestId(), serialize(result)));
|
||||
}
|
||||
} else {
|
||||
TResult tResult = new TResult(false);
|
||||
tResult.setMessage("Unsupported command(" + request + ") type.");
|
||||
|
||||
channel.write(new ResponsePacket(requestPacket.getRequestId(), serialize(tResult)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public interface ClusterService {
|
||||
|
||||
void setUp() throws Exception;
|
||||
|
||||
void tearDown() throws Exception;
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public interface PinpointClusterManager {
|
||||
|
||||
void register(ChannelContext channelContext);
|
||||
|
||||
void unregister(ChannelContext channelContext);
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public class ProfilerClusterPoint implements ClusterPoint {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final CopyOnWriteArrayList<ChannelContext> clusterRepository = new CopyOnWriteArrayList<ChannelContext>();
|
||||
|
||||
|
||||
public boolean registerChannelContext(ChannelContext channelContext) {
|
||||
boolean isAdd = clusterRepository.addIfAbsent(channelContext);
|
||||
|
||||
if (!isAdd) {
|
||||
logger.warn("Already registered ChannelContext({}).", channelContext);
|
||||
}
|
||||
|
||||
return isAdd;
|
||||
}
|
||||
|
||||
public boolean unregisterChannelContext(ChannelContext channelContext) {
|
||||
boolean isRemove = clusterRepository.remove(channelContext);
|
||||
|
||||
if (!isRemove) {
|
||||
logger.warn("Already unregistered or not registered ChannelContext({}).", channelContext);
|
||||
}
|
||||
|
||||
return isRemove;
|
||||
}
|
||||
|
||||
public List<ChannelContext> getChannelContext() {
|
||||
return new ArrayList<ChannelContext>(clusterRepository);
|
||||
}
|
||||
|
||||
public ChannelContext getChannelContext(String applicationName, String agentId) {
|
||||
return getChannelContext(applicationName, agentId, -1);
|
||||
}
|
||||
|
||||
public ChannelContext getChannelContext(String applicationName, String agentId, long startTimestamp) {
|
||||
|
||||
for (ChannelContext channelContext : clusterRepository) {
|
||||
if (checkSuitableChannelContext(channelContext, applicationName, agentId, startTimestamp)) {
|
||||
return channelContext;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkSuitableChannelContext(ChannelContext channelContext, String applicationName, String agentId, long startTimestamp) {
|
||||
Map<Object, Object> properties = channelContext.getChannelProperties();
|
||||
|
||||
if (!applicationName.equals(MapUtils.getString(properties, AgentPropertiesType.APPLICATION_NAME.getName()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!agentId.equals(MapUtils.getString(properties, AgentPropertiesType.AGENT_ID.getName()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (startTimestamp <= 0) {
|
||||
// Fix Me
|
||||
// startTimestamp도 체크하게 변경해야함
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.rpc.PinpointSocketException;
|
||||
import com.nhn.pinpoint.rpc.client.MessageListener;
|
||||
import com.nhn.pinpoint.rpc.client.PinpointSocket;
|
||||
import com.nhn.pinpoint.rpc.client.PinpointSocketFactory;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public class WebClusterPoint implements ClusterPoint {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final PinpointSocketFactory factory;
|
||||
|
||||
private final MessageListener messageListener;
|
||||
// InetSocketAddress List로 전달 하는게 좋을거 같은데 이걸 Key로만들기가 쉽지 않네;
|
||||
|
||||
private final Map<InetSocketAddress, PinpointSocket> clusterRepository = new HashMap<InetSocketAddress, PinpointSocket>();
|
||||
|
||||
public WebClusterPoint(String id, MessageListener messageListener) {
|
||||
this.messageListener = messageListener;
|
||||
|
||||
this.factory = new PinpointSocketFactory();
|
||||
this.factory.setTimeoutMillis(1000 * 5);
|
||||
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("id", id);
|
||||
|
||||
factory.setProperties(properties);
|
||||
}
|
||||
|
||||
// Not safe for use by multiple threads.
|
||||
public void connectPointIfAbsent(InetSocketAddress address) {
|
||||
logger.info("localhost -> {} connect started.", address);
|
||||
|
||||
if (clusterRepository.containsKey(address)) {
|
||||
logger.info("localhost -> {} already connected.", address);
|
||||
return;
|
||||
}
|
||||
|
||||
PinpointSocket socket = createPinpointSocket(address);
|
||||
clusterRepository.put(address, socket);
|
||||
|
||||
logger.info("localhost -> {} connect completed.", address);
|
||||
}
|
||||
|
||||
// Not safe for use by multiple threads.
|
||||
public void disconnectPoint(InetSocketAddress address) {
|
||||
logger.info("localhost -> {} disconnect started.", address);
|
||||
|
||||
PinpointSocket socket = clusterRepository.remove(address);
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
logger.info("localhost -> {} disconnect completed.", address);
|
||||
} else {
|
||||
logger.info("localhost -> {} already disconnected.", address);
|
||||
}
|
||||
}
|
||||
|
||||
private PinpointSocket createPinpointSocket(InetSocketAddress address) {
|
||||
String host = address.getHostName();
|
||||
int port = address.getPort();
|
||||
|
||||
PinpointSocket socket = null;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
socket = factory.connect(host, port, messageListener);
|
||||
logger.info("tcp connect success:{}/{}", host, port);
|
||||
return socket;
|
||||
} catch (PinpointSocketException e) {
|
||||
logger.warn("tcp connect fail:{}/{} try reconnect, retryCount:{}", host, port, i);
|
||||
}
|
||||
}
|
||||
logger.warn("change background tcp connect mode {}/{} ", host, port);
|
||||
socket = factory.scheduledConnect(host, port, messageListener);
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
public List<InetSocketAddress> getWebClusterList() {
|
||||
return new ArrayList<InetSocketAddress>(clusterRepository.keySet());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
for (PinpointSocket socket : clusterRepository.values()) {
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (factory != null) {
|
||||
factory.release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
|
||||
public enum WorkerState {
|
||||
|
||||
NEW,
|
||||
INITIALIZING,
|
||||
STARTED,
|
||||
DESTROYING,
|
||||
STOPPED,
|
||||
ILLEGAL_STATE
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.nhn.pinpoint.collector.cluster;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class WorkerStateContext {
|
||||
|
||||
private final AtomicReference<WorkerState> currentState = new AtomicReference<WorkerState>();
|
||||
|
||||
public WorkerStateContext() {
|
||||
currentState.set(WorkerState.NEW);
|
||||
}
|
||||
|
||||
public WorkerState getCurrentState() {
|
||||
return currentState.get();
|
||||
}
|
||||
|
||||
public boolean changeStateInitializing() {
|
||||
return currentState.compareAndSet(WorkerState.NEW, WorkerState.INITIALIZING);
|
||||
}
|
||||
|
||||
public boolean changeStateStarted() {
|
||||
return currentState.compareAndSet(WorkerState.INITIALIZING, WorkerState.STARTED);
|
||||
}
|
||||
|
||||
public boolean changeStateDestroying() {
|
||||
return currentState.compareAndSet(WorkerState.STARTED, WorkerState.DESTROYING);
|
||||
}
|
||||
|
||||
public boolean changeStateStoped() {
|
||||
return currentState.compareAndSet(WorkerState.DESTROYING, WorkerState.STOPPED);
|
||||
}
|
||||
|
||||
public boolean changeStateIllegal() {
|
||||
currentState.set(WorkerState.ILLEGAL_STATE);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
if (currentState.get() == WorkerState.STARTED) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+250
-214
@@ -1,214 +1,250 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.apache.zookeeper.KeeperException.Code;
|
||||
import org.apache.zookeeper.ZooDefs.Ids;
|
||||
import org.apache.zookeeper.ZooKeeper;
|
||||
import org.apache.zookeeper.data.Stat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.ZookeeperEventWatcher;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.AuthException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.BadOperationException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.ConnectionException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.PinpointZookeeperException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.TimeoutException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.UnknownException;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public class ZookeeperClient {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
// 쥬키퍼 클라이언트는 스레드 세이프함
|
||||
private final ZooKeeper zookeeper;
|
||||
private final AtomicBoolean clientState = new AtomicBoolean(true);
|
||||
|
||||
private final ZookeeperEventWatcher watcher;
|
||||
|
||||
// 데이터를 이친구가 다가지고 있어야 할 거 같은데;
|
||||
public ZookeeperClient(String hostPort, int sessionTimeout, ZookeeperEventWatcher watcher) throws KeeperException, IOException, InterruptedException {
|
||||
this.watcher = watcher;
|
||||
zookeeper = new ZooKeeper(hostPort, sessionTimeout, this.watcher); // server
|
||||
}
|
||||
|
||||
/**
|
||||
* path의 가장마지막에 있는 node는 생성하지 않는다.
|
||||
*
|
||||
* @throws PinpointZookeeperException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void createPath(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
int pos = 1;
|
||||
do {
|
||||
pos = path.indexOf('/', pos + 1);
|
||||
|
||||
if (pos == -1) {
|
||||
pos = path.length();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String subPath = path.substring(0, pos);
|
||||
if (zookeeper.exists(subPath, false) != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
zookeeper.create(subPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
} while (pos < path.length());
|
||||
}
|
||||
|
||||
// 이미있는 노드가 괜찮은건지 검사 필요없을거 같긴한데, 혹시나 이건 일단 주석으로
|
||||
// Stat stat = zookeeper.exists(node, false);
|
||||
// if (stat != null) {
|
||||
// byte[] result = zookeeper.getData(node, false, stat);
|
||||
// if (byte[] array같은지 검사) {
|
||||
// return node;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// 데이터를 어떤식으로 넣지?
|
||||
public String createNode(String znodePath, byte[] data) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
if (zookeeper.exists(znodePath, false) != null) {
|
||||
return znodePath;
|
||||
}
|
||||
|
||||
String pathName = zookeeper.create(znodePath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
|
||||
return pathName;
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
return znodePath;
|
||||
}
|
||||
|
||||
public byte[] getData(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
return zookeeper.getData(path, false, null);
|
||||
} catch (KeeperException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
|
||||
throw new UnknownException("UnknownException.");
|
||||
}
|
||||
|
||||
public void setData(String path, byte[] data) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
if (zookeeper.exists(path, false) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
zookeeper.setData(path, data, -1);
|
||||
} catch (KeeperException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
zookeeper.delete(path, -1);
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NONODE) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
Stat stat = zookeeper.exists(path, false);
|
||||
if (stat == null) {
|
||||
return false;
|
||||
}
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkState() throws PinpointZookeeperException {
|
||||
if (!watcher.isConnected() || !clientState.get()) {
|
||||
throw new ConnectionException("instance must be connected.");
|
||||
}
|
||||
}
|
||||
|
||||
// public byte[] getData(String path) throws KeeperException, InterruptedException {
|
||||
// checkState();
|
||||
//
|
||||
// return zookeeper.getData(path, false, null);
|
||||
// }
|
||||
//
|
||||
// public List<String> getChildrenNode(String path) throws KeeperException, InterruptedException {
|
||||
// checkState();
|
||||
//
|
||||
// List<String> childNodeList = zookeeper.getChildren(path, false);
|
||||
// logger.info("ChildNode List = {}", childNodeList);
|
||||
// return childNodeList;
|
||||
// }
|
||||
|
||||
private void handleException(KeeperException keeperException) throws PinpointZookeeperException {
|
||||
switch (keeperException.code()) {
|
||||
case CONNECTIONLOSS:
|
||||
case SESSIONEXPIRED:
|
||||
throw new ConnectionException(keeperException.getMessage(), keeperException);
|
||||
case AUTHFAILED:
|
||||
case INVALIDACL:
|
||||
case NOAUTH:
|
||||
throw new AuthException(keeperException.getMessage(), keeperException);
|
||||
case BADARGUMENTS:
|
||||
case BADVERSION:
|
||||
case NOCHILDRENFOREPHEMERALS:
|
||||
case NOTEMPTY:
|
||||
case NODEEXISTS:
|
||||
case NONODE:
|
||||
throw new BadOperationException(keeperException.getMessage(), keeperException);
|
||||
case OPERATIONTIMEOUT:
|
||||
throw new TimeoutException(keeperException.getMessage(), keeperException);
|
||||
default:
|
||||
throw new UnknownException(keeperException.getMessage(), keeperException);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (clientState.compareAndSet(true, false)) {
|
||||
if (zookeeper != null) {
|
||||
try {
|
||||
zookeeper.close();
|
||||
} catch (InterruptedException ignore) {
|
||||
logger.debug(ignore.getMessage(), ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.apache.zookeeper.KeeperException.Code;
|
||||
import org.apache.zookeeper.ZooDefs.Ids;
|
||||
import org.apache.zookeeper.ZooKeeper;
|
||||
import org.apache.zookeeper.data.Stat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.AuthException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.BadOperationException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.ConnectionException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.PinpointZookeeperException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.TimeoutException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.UnknownException;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public class ZookeeperClient {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
// 쥬키퍼 클라이언트는 스레드 세이프함
|
||||
private final ZooKeeper zookeeper;
|
||||
private final AtomicBoolean clientState = new AtomicBoolean(true);
|
||||
|
||||
private final ZookeeperEventWatcher watcher;
|
||||
|
||||
// 데이터를 이친구가 다가지고 있어야 할 거 같은데;
|
||||
public ZookeeperClient(String hostPort, int sessionTimeout, ZookeeperEventWatcher watcher) throws KeeperException, IOException, InterruptedException {
|
||||
this.watcher = watcher;
|
||||
zookeeper = new ZooKeeper(hostPort, sessionTimeout, this.watcher); // server
|
||||
}
|
||||
|
||||
/**
|
||||
* path의 가장마지막에 있는 node는 생성하지 않는다.
|
||||
*
|
||||
* @throws PinpointZookeeperException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void createPath(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
createPath(path, false);
|
||||
}
|
||||
|
||||
public void createPath(String path, boolean createEndNode) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
int pos = 1;
|
||||
do {
|
||||
pos = path.indexOf('/', pos + 1);
|
||||
|
||||
if (pos == -1) {
|
||||
pos = path.length();
|
||||
}
|
||||
|
||||
try {
|
||||
if (pos == path.length()) {
|
||||
if (!createEndNode) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String subPath = path.substring(0, pos);
|
||||
if (zookeeper.exists(subPath, false) != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
zookeeper.create(subPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
} while (pos < path.length());
|
||||
}
|
||||
|
||||
|
||||
// 이미있는 노드가 괜찮은건지 검사 필요없을거 같긴한데, 혹시나 이건 일단 주석으로
|
||||
// Stat stat = zookeeper.exists(node, false);
|
||||
// if (stat != null) {
|
||||
// byte[] result = zookeeper.getData(node, false, stat);
|
||||
// if (byte[] array같은지 검사) {
|
||||
// return node;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// 데이터를 어떤식으로 넣지?
|
||||
public String createNode(String znodePath, byte[] data) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
if (zookeeper.exists(znodePath, false) != null) {
|
||||
return znodePath;
|
||||
}
|
||||
|
||||
String pathName = zookeeper.create(znodePath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
|
||||
return pathName;
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
return znodePath;
|
||||
}
|
||||
|
||||
public byte[] getData(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
return zookeeper.getData(path, false, null);
|
||||
} catch (KeeperException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
|
||||
throw new UnknownException("UnknownException.");
|
||||
}
|
||||
|
||||
public void setData(String path, byte[] data) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
if (zookeeper.exists(path, false) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
zookeeper.setData(path, data, -1);
|
||||
} catch (KeeperException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
zookeeper.delete(path, -1);
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NONODE) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
Stat stat = zookeeper.exists(path, false);
|
||||
if (stat == null) {
|
||||
return false;
|
||||
}
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NODEEXISTS) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkState() throws PinpointZookeeperException {
|
||||
if (!isConnected()) {
|
||||
throw new ConnectionException("instance must be connected.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
if (!watcher.isConnected() || !clientState.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getChildrenNode(String path, boolean watch) throws PinpointZookeeperException, InterruptedException {
|
||||
checkState();
|
||||
|
||||
try {
|
||||
List<String> childNodeList = zookeeper.getChildren(path, watch, null);
|
||||
|
||||
logger.info("ChildNode List = {}", childNodeList);
|
||||
return childNodeList;
|
||||
} catch (KeeperException exception) {
|
||||
if (exception.code() != Code.NONODE) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// public byte[] getData(String path) throws KeeperException, InterruptedException {
|
||||
// checkState();
|
||||
//
|
||||
// return zookeeper.getData(path, false, null);
|
||||
// }
|
||||
//
|
||||
// public List<String> getChildrenNode(String path) throws KeeperException, InterruptedException {
|
||||
// checkState();
|
||||
//
|
||||
// List<String> childNodeList = zookeeper.getChildren(path, false);
|
||||
// logger.info("ChildNode List = {}", childNodeList);
|
||||
// return childNodeList;
|
||||
// }
|
||||
|
||||
private void handleException(KeeperException keeperException) throws PinpointZookeeperException {
|
||||
switch (keeperException.code()) {
|
||||
case CONNECTIONLOSS:
|
||||
case SESSIONEXPIRED:
|
||||
throw new ConnectionException(keeperException.getMessage(), keeperException);
|
||||
case AUTHFAILED:
|
||||
case INVALIDACL:
|
||||
case NOAUTH:
|
||||
throw new AuthException(keeperException.getMessage(), keeperException);
|
||||
case BADARGUMENTS:
|
||||
case BADVERSION:
|
||||
case NOCHILDRENFOREPHEMERALS:
|
||||
case NOTEMPTY:
|
||||
case NODEEXISTS:
|
||||
case NONODE:
|
||||
throw new BadOperationException(keeperException.getMessage(), keeperException);
|
||||
case OPERATIONTIMEOUT:
|
||||
throw new TimeoutException(keeperException.getMessage(), keeperException);
|
||||
default:
|
||||
throw new UnknownException(keeperException.getMessage(), keeperException);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (clientState.compareAndSet(true, false)) {
|
||||
if (zookeeper != null) {
|
||||
try {
|
||||
zookeeper.close();
|
||||
} catch (InterruptedException ignore) {
|
||||
logger.debug(ignore.getMessage(), ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-179
@@ -1,179 +0,0 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.apache.zookeeper.WatchedEvent;
|
||||
import org.apache.zookeeper.Watcher.Event.KeeperState;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.DeleteJob;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.UpdateJob;
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.server.PinpointServerSocketStateCode;
|
||||
import com.nhn.pinpoint.rpc.server.SocketChannelStateChangeEventListener;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public class ZookeeperClusterManager implements SocketChannelStateChangeEventListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final InetAddress localHost;
|
||||
|
||||
private final ZookeeperClient client;
|
||||
private final ZookeeperLatestJobWorker worker;
|
||||
|
||||
private final ObjectMapper objectmapper = new ObjectMapper();
|
||||
|
||||
|
||||
// 단순하게 하자 그냥 RUN이면 등록 FINISHED면 경우 삭제 그외 skip
|
||||
// 만약 상태가 안맞으면(?) 보정 들어가야 하는데 leack detector 같은걸 worker내부에 둘 까도 고민중
|
||||
//
|
||||
// RUN에서만 생성할수 있게 해야한다.
|
||||
// 지금은 RUN_WITHOUT_REGISTER면 상대방의 상태를 알수 없는 상태이기 때문에 이상황에서 등록
|
||||
|
||||
public ZookeeperClusterManager(String hostPort, int sessionTimeout) throws KeeperException, IOException, InterruptedException {
|
||||
// 디폴트값으로 사용할 ip같은거 지정해 주는게 좋을듯
|
||||
this.localHost = InetAddress.getLocalHost();
|
||||
|
||||
this.client = new ZookeeperClient(hostPort, sessionTimeout, new ClusterManagerWatcher());
|
||||
this.worker = new ZookeeperLatestJobWorker(client);
|
||||
worker.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventPerformed(ChannelContext channelContext, PinpointServerSocketStateCode stateCode) {
|
||||
logger.info("eventPerformed ChannelContext={}, State={}", channelContext, stateCode);
|
||||
|
||||
Map agentProperties = channelContext.getChannelProperties();
|
||||
|
||||
// 현재는 AgentProperties에 값을 모를 경우 skip
|
||||
if (skipAgent(agentProperties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION == stateCode) {
|
||||
byte[] contents = serializeContents(agentProperties, stateCode);
|
||||
if (contents == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateJob job = new UpdateJob(channelContext, contents);
|
||||
worker.putJob(job);
|
||||
} else if (PinpointServerSocketStateCode.isFinished(stateCode)) {
|
||||
DeleteJob job = new DeleteJob(channelContext);
|
||||
worker.putJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
public Map getData(ChannelContext channelContext) {
|
||||
byte[] contents = worker.getData(channelContext);
|
||||
|
||||
if (contents == null) {
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
return deserializeContents(contents);
|
||||
}
|
||||
|
||||
private boolean skipAgent(Map<Object, Object> agentProperties) {
|
||||
String applicationName = MapUtils.getString(agentProperties, AgentPropertiesType.APPLICATION_NAME.getName());
|
||||
String agentId = MapUtils.getString(agentProperties, AgentPropertiesType.AGENT_ID.getName());
|
||||
|
||||
if (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(agentId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private byte[] serializeContents(Map agentProperties, PinpointServerSocketStateCode state) {
|
||||
Map<Object, Object> contents = new HashMap<Object, Object>();
|
||||
contents.put(localHost.getHostAddress(), agentProperties);
|
||||
contents.put("state", state.name());
|
||||
|
||||
try {
|
||||
return objectmapper.writeValueAsBytes(contents);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map deserializeContents(byte[] contents) {
|
||||
try {
|
||||
return objectmapper.readValue(contents, Map.class);
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
client.close();
|
||||
worker.stop();
|
||||
}
|
||||
|
||||
// 쥬키퍼의 모든 노드를 EPHEMERAL 형태로 만들기 때문에 연결이 새로 연결되면 원래 가지고 있던 것들 재등록 함
|
||||
// 연결이 종료 될때는 별다른 액션을 취하지 않는다.
|
||||
class ClusterManagerWatcher implements ZookeeperEventWatcher {
|
||||
|
||||
private final AtomicBoolean connected = new AtomicBoolean(false);
|
||||
|
||||
// 여기서 고민을 좀 해봐야 할듯
|
||||
// 이전에 있던 job을 다 지운다. 어떻게 지울까?
|
||||
// 새로 생긴 job을 모두 새로 만든다 어떻게 만들지? 추가적으로 이걸 지워질수는 없나?
|
||||
// 타이밍이 안좋아서 문제가 생길수 있나?
|
||||
//
|
||||
|
||||
@Override
|
||||
public void process(WatchedEvent event) {
|
||||
KeeperState state = event.getState();
|
||||
|
||||
// 상태가 되면 ephemeral 노드가 사라짐
|
||||
// 문서에 따라 자동으로 연결이 되고, 연결되는 이벤트는 process에서 감지가 됨
|
||||
if (state == KeeperState.Disconnected || state == KeeperState.Expired) {
|
||||
connected.compareAndSet(true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) {
|
||||
// 이전상태가 RUN일수 있기 때문에 유지해도 됨
|
||||
boolean changed = connected.compareAndSet(false, true);
|
||||
if (changed) {
|
||||
// 여기서 데이터가 있으면 다 넣어줘야함
|
||||
List<ChannelContext> currentChannelContextList = worker.getRegisteredChannelContextList();
|
||||
|
||||
for (ChannelContext channelContext : currentChannelContextList) {
|
||||
eventPerformed(channelContext, channelContext.getCurrentStateCode());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return connected.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.apache.zookeeper.WatchedEvent;
|
||||
import org.apache.zookeeper.Watcher.Event.EventType;
|
||||
import org.apache.zookeeper.Watcher.Event.KeeperState;
|
||||
import org.apache.zookeeper.proto.WatcherEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.cluster.AbstractClusterService;
|
||||
import com.nhn.pinpoint.collector.cluster.ClusterPointRouter;
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerState;
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerStateContext;
|
||||
import com.nhn.pinpoint.collector.config.CollectorConfiguration;
|
||||
import com.nhn.pinpoint.collector.util.CollectorUtils;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.server.SocketChannelStateChangeEventListener;
|
||||
|
||||
public class ZookeeperClusterService extends AbstractClusterService {
|
||||
|
||||
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
|
||||
private static final String PINPOINT_WEB_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/web";
|
||||
private static final String PINPOINT_PROFILER_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/profiler";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
// 해당 값이 유일한 값이 아닌 경우 MAC주소나 IP주소 등으로 변경할 예정
|
||||
// 요렇게 하면 pid@hostname 으로 나옴 (localhost 요런놈은 겹칠 가능성이 존재함)
|
||||
private final String serverIdentifier = CollectorUtils.getServerIdentifier();
|
||||
|
||||
private final WorkerStateContext serviceState;
|
||||
|
||||
private ZookeeperClient client;
|
||||
|
||||
|
||||
// ProfilerClusterManager는 프로파일러 -> 콜렉터 연결을 감지 및 관리하고, 쥬키퍼에 등록한다.
|
||||
// private ZookeeperProfilerClusterManager profilerClusterManager;
|
||||
// WebClusterManager는 웹 정보가 쥬키퍼에 등록되어 있는지 체크하고, 콜렉터 -> 웹 연결을 관리한다.
|
||||
|
||||
private ZookeeperWebClusterManager webClusterManager;
|
||||
private ZookeeperProfilerClusterManager profilerClusterManager;
|
||||
|
||||
public ZookeeperClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
|
||||
super(config, clusterPointRouter);
|
||||
this.serviceState = new WorkerStateContext();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@Override
|
||||
public void setUp() throws KeeperException, IOException, InterruptedException {
|
||||
if (!config.isClusterEnable()) {
|
||||
logger.info("pinpoint-collector cluster disable.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.serviceState.getCurrentState()) {
|
||||
case NEW:
|
||||
if (this.serviceState.changeStateInitializing()) {
|
||||
logger.info("{} initialization started.", this.getClass().getSimpleName());
|
||||
|
||||
// 이 상태값은 반드시 필요한것들인데.
|
||||
ClusterManagerWatcher watcher = new ClusterManagerWatcher();
|
||||
this.client = new ZookeeperClient(config.getClusterAddress(), config.getClusterSessionTimeout(), watcher);
|
||||
|
||||
this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, serverIdentifier, clusterPointRouter.getProfilerClusterPoint());
|
||||
this.profilerClusterManager.start();
|
||||
|
||||
this.webClusterManager = new ZookeeperWebClusterManager(client, PINPOINT_WEB_CLUSTER_PATH, serverIdentifier, clusterPointRouter.getWebClusterPoint());
|
||||
this.webClusterManager.start();
|
||||
|
||||
this.serviceState.changeStateStarted();
|
||||
logger.info("{} initialization completed.", this.getClass().getSimpleName());
|
||||
|
||||
if (client.isConnected()) {
|
||||
WatcherEvent watcherEvent = new WatcherEvent(EventType.None.getIntValue(), KeeperState.SyncConnected.getIntValue(), "");
|
||||
WatchedEvent event = new WatchedEvent(watcherEvent);
|
||||
|
||||
watcher.process(event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case INITIALIZING:
|
||||
logger.info("{} already initializing.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case STARTED:
|
||||
logger.info("{} already started.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case DESTROYING:
|
||||
throw new IllegalStateException("Already destroying.");
|
||||
case STOPPED:
|
||||
throw new IllegalStateException("Already stopped.");
|
||||
case ILLEGAL_STATE:
|
||||
throw new IllegalStateException("Invalid State.");
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@Override
|
||||
public void tearDown() {
|
||||
if (!config.isClusterEnable()) {
|
||||
logger.info("pinpoint-collector cluster disable.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(this.serviceState.changeStateDestroying())) {
|
||||
WorkerState state = this.serviceState.getCurrentState();
|
||||
|
||||
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("{} destroying started.", this.getClass().getSimpleName());
|
||||
|
||||
if (this.profilerClusterManager != null) {
|
||||
profilerClusterManager.stop();
|
||||
}
|
||||
|
||||
if (this.webClusterManager != null) {
|
||||
webClusterManager.stop();
|
||||
}
|
||||
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
|
||||
this.serviceState.changeStateStoped();
|
||||
logger.info("{} destroying completed.", this.getClass().getSimpleName());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public SocketChannelStateChangeEventListener getChannelStateChangeEventListener() {
|
||||
return profilerClusterManager;
|
||||
}
|
||||
|
||||
public ZookeeperProfilerClusterManager getProfilerClusterManager() {
|
||||
return profilerClusterManager;
|
||||
}
|
||||
|
||||
public ZookeeperWebClusterManager getWebClusterManager() {
|
||||
return webClusterManager;
|
||||
}
|
||||
|
||||
class ClusterManagerWatcher implements ZookeeperEventWatcher {
|
||||
|
||||
private final AtomicBoolean connected = new AtomicBoolean(false);
|
||||
|
||||
@Override
|
||||
public void process(WatchedEvent event) {
|
||||
logger.debug("Process Zookeeper Event({})", event);
|
||||
|
||||
KeeperState state = event.getState();
|
||||
EventType eventType = event.getType();
|
||||
|
||||
// 상태가 되면 ephemeral 노드가 사라짐
|
||||
// 문서에 따라 자동으로 연결이 되고, 연결되는 이벤트는 process에서 감지가 됨
|
||||
if (ZookeeperUtils.isDisconnectedEvent(state, eventType)) {
|
||||
connected.compareAndSet(true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
|
||||
// 이전상태가 RUN일수 있기 때문에 유지해도 됨
|
||||
boolean changed = connected.compareAndSet(false, true);
|
||||
}
|
||||
|
||||
if (serviceState.isStarted() && connected.get()) {
|
||||
|
||||
// 중복 요청이 있을수 있음 일단은 중복 로직 감안함
|
||||
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
|
||||
// 이전상태가 RUN일수 있기 때문에 유지해도 됨
|
||||
// 여기서 데이터가 있으면 다 넣어줘야함
|
||||
List<ChannelContext> currentChannelContextList = profilerClusterManager.getRegisteredChannelContextList();
|
||||
for (ChannelContext channelContext : currentChannelContextList) {
|
||||
profilerClusterManager.eventPerformed(channelContext, channelContext.getCurrentStateCode());
|
||||
}
|
||||
|
||||
webClusterManager.handleAndRegisterWatcher(PINPOINT_WEB_CLUSTER_PATH);
|
||||
} else if (eventType == EventType.NodeChildrenChanged) {
|
||||
String path = event.getPath();
|
||||
|
||||
if (PINPOINT_WEB_CLUSTER_PATH.equals(path)) {
|
||||
webClusterManager.handleAndRegisterWatcher(path);
|
||||
} else {
|
||||
logger.warn("Unknown Path ChildrenChanged {}.", path);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return connected.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import org.apache.zookeeper.Watcher;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public interface ZookeeperEventWatcher extends Watcher {
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import org.apache.zookeeper.Watcher;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public interface ZookeeperEventWatcher extends Watcher {
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
}
|
||||
|
||||
+401
-380
@@ -1,380 +1,401 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.TimeoutException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.DeleteJob;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.Job;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.UpdateJob;
|
||||
import com.nhn.pinpoint.common.util.PinpointThreadFactory;
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.server.PinpointServerSocketStateCode;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public class ZookeeperLatestJobWorker implements Runnable {
|
||||
|
||||
private static final String PREFIX_ROOT_ZNODE = "/pinpoint-cluster";
|
||||
private static final String PATH_SEPRATOR = "/";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private final AtomicInteger workerState;
|
||||
private final Thread workerThread;
|
||||
|
||||
private final String identifier = ManagementFactory.getRuntimeMXBean().getName();
|
||||
private final AtomicInteger sequntialId = new AtomicInteger(0);
|
||||
|
||||
private final ZookeeperClient zookeeperClient;
|
||||
|
||||
// 메시지가 사라지면 ChannelContext 역시 사라짐
|
||||
private final Map<ChannelContext, Job> latestJobRepository = new HashMap<ChannelContext, Job>();
|
||||
|
||||
// 들어온 ChannelContext는 계속 유지됨
|
||||
private final Map<ChannelContext, String> znodeMappingRepository = new HashMap<ChannelContext, String>();
|
||||
|
||||
private final BlockingQueue<Job> leakJobQueue = new LinkedBlockingQueue<Job>();
|
||||
|
||||
// 등록순서
|
||||
// 순서대로 작업은 반드시 Worker에서만 돌아가기 때문에 동시성은 보장됨
|
||||
|
||||
public ZookeeperLatestJobWorker(ZookeeperClient zookeeperClient) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.zookeeperClient = zookeeperClient;
|
||||
|
||||
this.workerState = new AtomicInteger(0);
|
||||
|
||||
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
|
||||
this.workerThread = threadFactory.newThread(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
switch (this.workerState.get()) {
|
||||
case 0:
|
||||
if (this.workerState.compareAndSet(0, 1))
|
||||
logger.info("{} will be started", this.getClass().getSimpleName());
|
||||
this.workerThread.start();
|
||||
break;
|
||||
case 1:
|
||||
logger.info("{} already started.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case 2:
|
||||
throw new IllegalStateException("Already stopped");
|
||||
default:
|
||||
throw new Error("Invalid WorkerState");
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (!(this.workerState.compareAndSet(1, 2))) {
|
||||
logger.info("{} already stopped.", this.getClass().getSimpleName());
|
||||
this.workerState.set(2);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("{} will be stopped", this.getClass().getSimpleName());
|
||||
|
||||
boolean interrupted = false;
|
||||
while (this.workerThread.isAlive()) {
|
||||
this.workerThread.interrupt();
|
||||
try {
|
||||
this.workerThread.join(100L);
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// 고민할 것
|
||||
// 이벤트 삭제가 안될떄 spinlock 고민해야함
|
||||
// 이벤트 발생시 처리가 안될 경우 실제 등록이 안되어이는 ChannelContext가 남아있을 수 있음 이 경우
|
||||
// Manager에서
|
||||
// 종료가 될 경우 처리해주긴 하지만 LeakDetector같은게 있으면 더 좋을듯 안되면 (1분마다 확인등도 괜찮을듯)
|
||||
while (workerState.get() == 1) {
|
||||
boolean eventCreated = await(60000, 200);
|
||||
if (workerState.get() != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 이벤트 발생시 이벤트 처리
|
||||
// 이벤트 발생하지 않을 경우 leack ChannelContext 확인 및 처리
|
||||
if (eventCreated) {
|
||||
// ConcurrentModificationException 발생 피하기 위해서
|
||||
Iterator<ChannelContext> keyIterator = getLatestJobRepositoryKeyIterator();
|
||||
|
||||
while (keyIterator.hasNext()) {
|
||||
ChannelContext channelContext = keyIterator.next();
|
||||
Job job = getJob(channelContext);
|
||||
|
||||
if (job == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (job instanceof UpdateJob) {
|
||||
handleUpdate((UpdateJob) job);
|
||||
} else if (job instanceof DeleteJob) {
|
||||
handleDelete((DeleteJob) job);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.debug("LeackDetector Start.");
|
||||
|
||||
// while 걸자
|
||||
while (true) {
|
||||
Job job = leakJobQueue.poll();
|
||||
if (job == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (job instanceof UpdateJob) {
|
||||
putJob(new UpdateJob(job.getChannelContext(), 0, ((UpdateJob) job).getContents()));
|
||||
}
|
||||
}
|
||||
|
||||
List<ChannelContext> currentChannelContextList = getRegisteredChannelContextList();
|
||||
for (ChannelContext channelContext : currentChannelContextList) {
|
||||
if (PinpointServerSocketStateCode.isFinished(channelContext.getCurrentStateCode())) {
|
||||
logger.info("LeackDetector Find Leak ChannelContext={}.", channelContext);
|
||||
putJob(new DeleteJob(channelContext));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("{} stopped", this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public boolean handleUpdate(UpdateJob job) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
PinpointServerSocketStateCode code = channelContext.getCurrentStateCode();
|
||||
if (PinpointServerSocketStateCode.isFinished(code)) {
|
||||
putJob(new DeleteJob(channelContext));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 동시성에 문제 없게 하자
|
||||
String uniquePath = getUniquePath(channelContext, true);
|
||||
|
||||
try {
|
||||
if (zookeeperClient.exists(uniquePath)) {
|
||||
zookeeperClient.setData(uniquePath, job.getContents());
|
||||
} else {
|
||||
zookeeperClient.createPath(uniquePath);
|
||||
zookeeperClient.createNode(uniquePath, job.getContents());
|
||||
logger.info("Registed Zookeeper UniqPath = {}", uniquePath);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
if (e instanceof TimeoutException) {
|
||||
job.incrementCurrentRetryCount();
|
||||
putJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleDelete(Job job) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
String uniquePath = getUniquePath(channelContext, false);
|
||||
|
||||
if (uniquePath == null) {
|
||||
logger.info("Already Delete Zookeeper UniqPath ChannelContext = {}.", channelContext);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (zookeeperClient.exists(uniquePath)) {
|
||||
zookeeperClient.delete(uniquePath);
|
||||
logger.info("Unregisted Zookeeper UniqPath = {}", uniquePath);
|
||||
}
|
||||
removeUniquePath(channelContext);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
if (e instanceof TimeoutException) {
|
||||
job.incrementCurrentRetryCount();
|
||||
putJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public byte[] getData(ChannelContext channelContext) {
|
||||
String uniquePath = getUniquePath(channelContext, false);
|
||||
|
||||
if (uniquePath == null) {
|
||||
logger.info("Can't find suitable UniqPath ChannelContext = {}.", channelContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return zookeeperClient.getData(uniquePath);
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ChannelContext> getRegisteredChannelContextList() {
|
||||
synchronized (znodeMappingRepository) {
|
||||
return new ArrayList<ChannelContext>(znodeMappingRepository.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 파라미터의 대기시간동안 이벤트가 일어날 경우 true 일어나지 않을 경우 false
|
||||
*
|
||||
* @param waitTimeMillis
|
||||
* @return
|
||||
*/
|
||||
private boolean await(long waitTimeMillis, long waitUnitTimeMillis) {
|
||||
synchronized (lock) {
|
||||
long waitTime = waitTimeMillis;
|
||||
long waitUnitTime = waitUnitTimeMillis;
|
||||
if (waitTimeMillis < 1000) {
|
||||
waitTime = 1000;
|
||||
}
|
||||
if (waitUnitTimeMillis < 100) {
|
||||
waitUnitTime = 100;
|
||||
}
|
||||
|
||||
long startTimeMillis = System.currentTimeMillis();
|
||||
|
||||
while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.get() == 1) {
|
||||
try {
|
||||
lock.wait(waitUnitTime);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isOverWaitTime(waitTime, startTimeMillis)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOverWaitTime(long waitTimeMillis, long startTimeMillis) {
|
||||
return waitTimeMillis < (System.currentTimeMillis() - startTimeMillis);
|
||||
}
|
||||
|
||||
private Iterator<ChannelContext> getLatestJobRepositoryKeyIterator() {
|
||||
synchronized (lock) {
|
||||
return latestJobRepository.keySet().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
// 상당히 민감한 api임 Runnable에서만 사용해야함
|
||||
private Job getJob(ChannelContext channelContext) {
|
||||
synchronized (lock) {
|
||||
Job job = latestJobRepository.remove(channelContext);
|
||||
return job;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void putJob(Job job) {
|
||||
if (job.getMaxRetryCount() < job.getCurrentRetryCount()) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.warn("Leack Job Queue Register Job={}.", job);
|
||||
}
|
||||
leakJobQueue.add(job);
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
latestJobRepository.put(channelContext, job);
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
private String getUniquePath(ChannelContext channelContext, boolean create) {
|
||||
synchronized (znodeMappingRepository) {
|
||||
String zNodePath = znodeMappingRepository.get(channelContext);
|
||||
|
||||
if (!create) {
|
||||
return zNodePath;
|
||||
}
|
||||
|
||||
if (zNodePath == null) {
|
||||
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
|
||||
final String applicationName = MapUtils.getString(agentProperties, AgentPropertiesType.APPLICATION_NAME.getName());
|
||||
final String agentId = MapUtils.getString(agentProperties, AgentPropertiesType.AGENT_ID.getName());
|
||||
|
||||
if (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(agentId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String path = PREFIX_ROOT_ZNODE + "/" + applicationName + "/" + agentId;
|
||||
String zNodeName = createUniqueZnodeName();
|
||||
|
||||
zNodePath = bindingPathAndZnode(path, zNodeName);
|
||||
znodeMappingRepository.put(channelContext, zNodePath);
|
||||
|
||||
logger.info("Created Zookeeper UniqPath = {}", zNodePath);
|
||||
}
|
||||
|
||||
return zNodePath;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeUniquePath(ChannelContext channelContext) {
|
||||
synchronized (znodeMappingRepository) {
|
||||
String zNodePath = znodeMappingRepository.remove(channelContext);
|
||||
if (zNodePath != null) {
|
||||
logger.info("Deleted Zookeeper UniqPath = {}", zNodePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createUniqueZnodeName() {
|
||||
return identifier + "_" + sequntialId.getAndIncrement();
|
||||
}
|
||||
|
||||
private String bindingPathAndZnode(String path, String znodeName) {
|
||||
StringBuilder fullPath = new StringBuilder();
|
||||
|
||||
fullPath.append(path);
|
||||
if (!path.endsWith(PATH_SEPRATOR)) {
|
||||
fullPath.append(PATH_SEPRATOR);
|
||||
}
|
||||
fullPath.append(znodeName);
|
||||
|
||||
return fullPath.toString();
|
||||
}
|
||||
|
||||
}
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerState;
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerStateContext;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.TimeoutException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.DeleteJob;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.Job;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.UpdateJob;
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.common.util.PinpointThreadFactory;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.server.PinpointServerSocketStateCode;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
|
||||
/**
|
||||
* @author koo.taejin
|
||||
*/
|
||||
public class ZookeeperLatestJobWorker implements Runnable {
|
||||
|
||||
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
|
||||
private static final String PINPOINT_PROFILER_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/profiler";
|
||||
|
||||
private static final String PATH_SEPRATOR = "/";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private final WorkerStateContext workerState;
|
||||
private final Thread workerThread;
|
||||
|
||||
private final String identifier;
|
||||
private final AtomicInteger sequntialId = new AtomicInteger(0);
|
||||
|
||||
private final ZookeeperClient zookeeperClient;
|
||||
|
||||
// 메시지가 사라지면 ChannelContext 역시 사라짐
|
||||
private final Map<ChannelContext, Job> latestJobRepository = new HashMap<ChannelContext, Job>();
|
||||
|
||||
// 들어온 ChannelContext는 계속 유지됨
|
||||
private final Map<ChannelContext, String> znodeMappingRepository = new HashMap<ChannelContext, String>();
|
||||
|
||||
private final BlockingQueue<Job> leakJobQueue = new LinkedBlockingQueue<Job>();
|
||||
|
||||
// 등록순서
|
||||
// 순서대로 작업은 반드시 Worker에서만 돌아가기 때문에 동시성은 보장됨
|
||||
|
||||
public ZookeeperLatestJobWorker(ZookeeperClient zookeeperClient, String serverIdentifier) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.zookeeperClient = zookeeperClient;
|
||||
|
||||
this.workerState = new WorkerStateContext();
|
||||
|
||||
this.identifier = serverIdentifier;
|
||||
|
||||
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
|
||||
this.workerThread = threadFactory.newThread(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
switch (this.workerState.getCurrentState()) {
|
||||
case NEW:
|
||||
if (this.workerState.changeStateInitializing()) {
|
||||
logger.info("{} initialization started.", this.getClass().getSimpleName());
|
||||
this.workerThread.start();
|
||||
|
||||
workerState.changeStateStarted();
|
||||
logger.info("{} initialization completed.", this.getClass().getSimpleName());
|
||||
|
||||
break;
|
||||
}
|
||||
case INITIALIZING:
|
||||
logger.info("{} already initializing.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case STARTED:
|
||||
logger.info("{} already started.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case DESTROYING:
|
||||
throw new IllegalStateException("Already destroying.");
|
||||
case STOPPED:
|
||||
throw new IllegalStateException("Already stopped.");
|
||||
case ILLEGAL_STATE:
|
||||
throw new IllegalStateException("Invalid State.");
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (!(this.workerState.changeStateDestroying())) {
|
||||
WorkerState state = this.workerState.getCurrentState();
|
||||
|
||||
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("{} destorying started.", this.getClass().getSimpleName());
|
||||
boolean interrupted = false;
|
||||
while (this.workerThread.isAlive()) {
|
||||
this.workerThread.interrupt();
|
||||
try {
|
||||
this.workerThread.join(100L);
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.workerState.changeStateStoped();
|
||||
logger.info("{} destorying completed.", this.getClass().getSimpleName());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// 고민할 것
|
||||
// 이벤트 삭제가 안될떄 spinlock 고민해야함
|
||||
// 이벤트 발생시 처리가 안될 경우 실제 등록이 안되어이는 ChannelContext가 남아있을 수 있음 이 경우
|
||||
while (workerState.isStarted()) {
|
||||
boolean eventCreated = await(60000, 200);
|
||||
if (!workerState.isStarted()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 이벤트 발생시 이벤트 처리
|
||||
// 이벤트 발생하지 않을 경우 leak ChannelContext 확인 및 처리
|
||||
if (eventCreated) {
|
||||
// ConcurrentModificationException 발생 피하기 위해서
|
||||
Iterator<ChannelContext> keyIterator = getLatestJobRepositoryKeyIterator();
|
||||
|
||||
while (keyIterator.hasNext()) {
|
||||
ChannelContext channelContext = keyIterator.next();
|
||||
Job job = getJob(channelContext);
|
||||
|
||||
if (job == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (job instanceof UpdateJob) {
|
||||
handleUpdate((UpdateJob) job);
|
||||
} else if (job instanceof DeleteJob) {
|
||||
handleDelete((DeleteJob) job);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 삭제 타이밍이 잘 안맞을 경우 메시지 유실이 발생할 가능성이 있어서 유실 Job 처리
|
||||
logger.debug("LeakDetector Start.");
|
||||
|
||||
while (true) {
|
||||
Job job = leakJobQueue.poll();
|
||||
if (job == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (job instanceof UpdateJob) {
|
||||
putJob(new UpdateJob(job.getChannelContext(), 0, ((UpdateJob) job).getContents()));
|
||||
}
|
||||
}
|
||||
|
||||
List<ChannelContext> currentChannelContextList = getRegisteredChannelContextList();
|
||||
for (ChannelContext channelContext : currentChannelContextList) {
|
||||
if (PinpointServerSocketStateCode.isFinished(channelContext.getCurrentStateCode())) {
|
||||
logger.info("LeakDetector Find Leak ChannelContext={}.", channelContext);
|
||||
putJob(new DeleteJob(channelContext));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("{} stopped", this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public boolean handleUpdate(UpdateJob job) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
PinpointServerSocketStateCode code = channelContext.getCurrentStateCode();
|
||||
if (PinpointServerSocketStateCode.isFinished(code)) {
|
||||
putJob(new DeleteJob(channelContext));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 동시성에 문제 없게 하자
|
||||
String uniquePath = getUniquePath(channelContext, true);
|
||||
if (uniquePath == null) {
|
||||
logger.warn("Zookeeper UniqPath({}) may not be null.", uniquePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (zookeeperClient.exists(uniquePath)) {
|
||||
zookeeperClient.setData(uniquePath, job.getContents());
|
||||
} else {
|
||||
zookeeperClient.createPath(uniquePath);
|
||||
zookeeperClient.createNode(uniquePath, job.getContents());
|
||||
logger.info("Registed Zookeeper UniqPath = {}", uniquePath);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
if (e instanceof TimeoutException) {
|
||||
job.incrementCurrentRetryCount();
|
||||
putJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleDelete(Job job) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
String uniquePath = getUniquePath(channelContext, false);
|
||||
|
||||
if (uniquePath == null) {
|
||||
logger.info("Already Delete Zookeeper UniqPath ChannelContext = {}.", channelContext);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (zookeeperClient.exists(uniquePath)) {
|
||||
zookeeperClient.delete(uniquePath);
|
||||
logger.info("Unregisted Zookeeper UniqPath = {}", uniquePath);
|
||||
}
|
||||
removeUniquePath(channelContext);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
if (e instanceof TimeoutException) {
|
||||
job.incrementCurrentRetryCount();
|
||||
putJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public byte[] getData(ChannelContext channelContext) {
|
||||
String uniquePath = getUniquePath(channelContext, false);
|
||||
|
||||
if (uniquePath == null) {
|
||||
logger.info("Can't find suitable UniqPath ChannelContext = {}.", channelContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return zookeeperClient.getData(uniquePath);
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ChannelContext> getRegisteredChannelContextList() {
|
||||
synchronized (znodeMappingRepository) {
|
||||
return new ArrayList<ChannelContext>(znodeMappingRepository.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 파라미터의 대기시간동안 이벤트가 일어날 경우 true 일어나지 않을 경우 false
|
||||
*
|
||||
* @param waitTimeMillis
|
||||
* @return
|
||||
*/
|
||||
private boolean await(long waitTimeMillis, long waitUnitTimeMillis) {
|
||||
synchronized (lock) {
|
||||
long waitTime = waitTimeMillis;
|
||||
long waitUnitTime = waitUnitTimeMillis;
|
||||
if (waitTimeMillis < 1000) {
|
||||
waitTime = 1000;
|
||||
}
|
||||
if (waitUnitTimeMillis < 100) {
|
||||
waitUnitTime = 100;
|
||||
}
|
||||
|
||||
long startTimeMillis = System.currentTimeMillis();
|
||||
|
||||
while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.isStarted()) {
|
||||
try {
|
||||
lock.wait(waitUnitTime);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isOverWaitTime(waitTime, startTimeMillis)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOverWaitTime(long waitTimeMillis, long startTimeMillis) {
|
||||
return waitTimeMillis < (System.currentTimeMillis() - startTimeMillis);
|
||||
}
|
||||
|
||||
private Iterator<ChannelContext> getLatestJobRepositoryKeyIterator() {
|
||||
synchronized (lock) {
|
||||
return latestJobRepository.keySet().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
// 상당히 민감한 api임 Runnable에서만 사용해야함
|
||||
private Job getJob(ChannelContext channelContext) {
|
||||
synchronized (lock) {
|
||||
Job job = latestJobRepository.remove(channelContext);
|
||||
return job;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void putJob(Job job) {
|
||||
if (job.getMaxRetryCount() < job.getCurrentRetryCount()) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.warn("Leack Job Queue Register Job={}.", job);
|
||||
}
|
||||
leakJobQueue.add(job);
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
ChannelContext channelContext = job.getChannelContext();
|
||||
|
||||
latestJobRepository.put(channelContext, job);
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
private String getUniquePath(ChannelContext channelContext, boolean create) {
|
||||
synchronized (znodeMappingRepository) {
|
||||
String zNodePath = znodeMappingRepository.get(channelContext);
|
||||
|
||||
if (!create) {
|
||||
return zNodePath;
|
||||
}
|
||||
|
||||
if (zNodePath == null) {
|
||||
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
|
||||
final String applicationName = MapUtils.getString(agentProperties, AgentPropertiesType.APPLICATION_NAME.getName());
|
||||
final String agentId = MapUtils.getString(agentProperties, AgentPropertiesType.AGENT_ID.getName());
|
||||
|
||||
if (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(agentId)) {
|
||||
logger.warn("ApplicationName({}) and AgnetId({}) may not be null.", applicationName, agentId);
|
||||
return null;
|
||||
}
|
||||
|
||||
String path = PINPOINT_PROFILER_CLUSTER_PATH + "/" + applicationName + "/" + agentId;
|
||||
String zNodeName = createUniqueZnodeName();
|
||||
|
||||
zNodePath = bindingPathAndZnode(path, zNodeName);
|
||||
znodeMappingRepository.put(channelContext, zNodePath);
|
||||
|
||||
logger.info("Created Zookeeper UniqPath = {}", zNodePath);
|
||||
}
|
||||
|
||||
return zNodePath;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeUniquePath(ChannelContext channelContext) {
|
||||
synchronized (znodeMappingRepository) {
|
||||
String zNodePath = znodeMappingRepository.remove(channelContext);
|
||||
if (zNodePath != null) {
|
||||
logger.info("Deleted Zookeeper UniqPath = {}", zNodePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createUniqueZnodeName() {
|
||||
return identifier + "_" + sequntialId.getAndIncrement();
|
||||
}
|
||||
|
||||
private String bindingPathAndZnode(String path, String znodeName) {
|
||||
StringBuilder fullPath = new StringBuilder();
|
||||
|
||||
fullPath.append(path);
|
||||
if (!path.endsWith(PATH_SEPRATOR)) {
|
||||
fullPath.append(PATH_SEPRATOR);
|
||||
}
|
||||
fullPath.append(znodeName);
|
||||
|
||||
return fullPath.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nhn.pinpoint.collector.cluster.ProfilerClusterPoint;
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerState;
|
||||
import com.nhn.pinpoint.collector.cluster.WorkerStateContext;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.exception.PinpointZookeeperException;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.DeleteJob;
|
||||
import com.nhn.pinpoint.collector.cluster.zookeeper.job.UpdateJob;
|
||||
import com.nhn.pinpoint.collector.receiver.tcp.AgentPropertiesType;
|
||||
import com.nhn.pinpoint.rpc.server.ChannelContext;
|
||||
import com.nhn.pinpoint.rpc.server.PinpointServerSocketStateCode;
|
||||
import com.nhn.pinpoint.rpc.server.SocketChannelStateChangeEventListener;
|
||||
import com.nhn.pinpoint.rpc.util.MapUtils;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public class ZookeeperProfilerClusterManager implements SocketChannelStateChangeEventListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final ZookeeperClient client;
|
||||
private final ZookeeperLatestJobWorker worker;
|
||||
|
||||
private final WorkerStateContext workerState;
|
||||
|
||||
private final ProfilerClusterPoint clusterPoint;
|
||||
|
||||
private final ObjectMapper objectmapper = new ObjectMapper();
|
||||
|
||||
// 단순하게 하자 그냥 RUN이면 등록 FINISHED면 경우 삭제 그외 skip
|
||||
// 만약 상태가 안맞으면(?) 보정 들어가야 하는데 leak detector 같은걸 worker내부에 둘 까도 고민중
|
||||
//
|
||||
// RUN_DUPLEX에서만 생성할수 있게 해야한다.
|
||||
// 지금은 RUN 상대방의 상태를 알수 없는 상태이기 때문에 이상황에서 등록
|
||||
public ZookeeperProfilerClusterManager(ZookeeperClient client, String serverIdentifier, ProfilerClusterPoint clusterPoint) {
|
||||
this.workerState = new WorkerStateContext();
|
||||
this.clusterPoint = clusterPoint;
|
||||
|
||||
this.client = client;
|
||||
this.worker = new ZookeeperLatestJobWorker(client, serverIdentifier);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
switch (this.workerState.getCurrentState()) {
|
||||
case NEW:
|
||||
if (this.workerState.changeStateInitializing()) {
|
||||
logger.info("{} initialization started.", this.getClass().getSimpleName());
|
||||
|
||||
if (worker != null) {
|
||||
worker.start();
|
||||
}
|
||||
|
||||
workerState.changeStateStarted();
|
||||
logger.info("{} initialization completed.", this.getClass().getSimpleName());
|
||||
|
||||
break;
|
||||
}
|
||||
case INITIALIZING:
|
||||
logger.info("{} already initializing.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case STARTED:
|
||||
logger.info("{} already started.", this.getClass().getSimpleName());
|
||||
break;
|
||||
case DESTROYING:
|
||||
throw new IllegalStateException("Already destroying.");
|
||||
case STOPPED:
|
||||
throw new IllegalStateException("Already stopped.");
|
||||
case ILLEGAL_STATE:
|
||||
throw new IllegalStateException("Invalid State.");
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (!(this.workerState.changeStateDestroying())) {
|
||||
WorkerState state = this.workerState.getCurrentState();
|
||||
|
||||
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("{} destorying started.", this.getClass().getSimpleName());
|
||||
|
||||
if (worker != null) {
|
||||
worker.stop();
|
||||
}
|
||||
|
||||
this.workerState.changeStateStoped();
|
||||
logger.info("{} destorying completed.", this.getClass().getSimpleName());
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventPerformed(ChannelContext channelContext, PinpointServerSocketStateCode stateCode) {
|
||||
if (workerState.isStarted()) {
|
||||
logger.info("eventPerformed ChannelContext={}, State={}", channelContext, stateCode);
|
||||
|
||||
Map agentProperties = channelContext.getChannelProperties();
|
||||
|
||||
// 현재는 AgentProperties에 값을 모를 경우 skip
|
||||
if (skipAgent(agentProperties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION == stateCode) {
|
||||
byte[] contents = serializeContents(agentProperties, stateCode);
|
||||
if (contents == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateJob job = new UpdateJob(channelContext, contents);
|
||||
worker.putJob(job);
|
||||
|
||||
clusterPoint.registerChannelContext(channelContext);
|
||||
} else if (PinpointServerSocketStateCode.isFinished(stateCode)) {
|
||||
DeleteJob job = new DeleteJob(channelContext);
|
||||
worker.putJob(job);
|
||||
|
||||
clusterPoint.unregisterChannelContext(channelContext);
|
||||
}
|
||||
} else {
|
||||
WorkerState state = this.workerState.getCurrentState();
|
||||
logger.info("{} invalid state {}.", this.getClass().getSimpleName(), state.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Map getData(ChannelContext channelContext) {
|
||||
byte[] contents = worker.getData(channelContext);
|
||||
|
||||
if (contents == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
return deserializeContents(contents);
|
||||
}
|
||||
|
||||
public List<String> getChildrenNode(String path, boolean watch) throws PinpointZookeeperException, InterruptedException {
|
||||
if (client.exists(path)) {
|
||||
return client.getChildrenNode(path, watch);
|
||||
} else {
|
||||
client.createPath(path);
|
||||
return client.getChildrenNode(path, watch);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ChannelContext> getRegisteredChannelContextList() {
|
||||
return worker.getRegisteredChannelContextList();
|
||||
}
|
||||
|
||||
private boolean skipAgent(Map<Object, Object> agentProperties) {
|
||||
String applicationName = MapUtils.getString(agentProperties, AgentPropertiesType.APPLICATION_NAME.getName());
|
||||
String agentId = MapUtils.getString(agentProperties, AgentPropertiesType.AGENT_ID.getName());
|
||||
|
||||
if (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(agentId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private byte[] serializeContents(Map agentProperties, PinpointServerSocketStateCode state) {
|
||||
Map<Object, Object> contents = new HashMap<Object, Object>();
|
||||
contents.put("agent", agentProperties);
|
||||
contents.put("state", state.name());
|
||||
|
||||
try {
|
||||
return objectmapper.writeValueAsBytes(contents);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map deserializeContents(byte[] contents) {
|
||||
try {
|
||||
return objectmapper.readValue(contents, Map.class);
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.nhn.pinpoint.collector.cluster.zookeeper;
|
||||
|
||||
import org.apache.zookeeper.WatchedEvent;
|
||||
import org.apache.zookeeper.Watcher.Event.EventType;
|
||||
import org.apache.zookeeper.Watcher.Event.KeeperState;
|
||||
|
||||
/**
|
||||
* @author koo.taejin <kr14910>
|
||||
*/
|
||||
public final class ZookeeperUtils {
|
||||
|
||||
// 나중에 commons-hbase 같은것이 생기면 그쪽에 포함하는 것도 방법일듯
|
||||
private ZookeeperUtils() {
|
||||
}
|
||||
|
||||
public static boolean isConnectedEvent(WatchedEvent event) {
|
||||
KeeperState state = event.getState();
|
||||
EventType eventType = event.getType();
|
||||
|
||||
return isConnectedEvent(state, eventType);
|
||||
}
|
||||
|
||||
public static boolean isConnectedEvent(KeeperState state, EventType eventType) {
|
||||
if ((state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) && eventType == EventType.None) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isDisconnectedEvent(WatchedEvent event) {
|
||||
KeeperState state = event.getState();
|
||||
EventType eventType = event.getType();
|
||||
|
||||
return isDisconnectedEvent(state, eventType);
|
||||
}
|
||||
|
||||
public static boolean isDisconnectedEvent(KeeperState state, EventType eventType) {
|
||||
if ((state == KeeperState.Disconnected || state == KeeperState.Expired) && eventType == eventType.None) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user