完成Plugin部分功能
This commit is contained in:
parent
26d39e12b1
commit
558b31c29d
|
|
@ -0,0 +1,20 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
public class TestBeanFactoryPostProcessor implements BeanPostProcessor {
|
||||
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
System.out.println(bean.getClass().getName());
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
System.out.println(bean.getClass().getName());
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class TraceParser implements BeanDefinitionParser {
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
|
||||
rootBeanDefinition.setLazyInit(false);
|
||||
rootBeanDefinition.setBeanClass(TracingEnhanceProcessor.class);
|
||||
String id = null;
|
||||
id = element.getAttribute("name");
|
||||
int counter = 2;
|
||||
while (parserContext.getRegistry().containsBeanDefinition(id)) {
|
||||
id = id + (counter++);
|
||||
}
|
||||
if (id != null && id.length() > 0) {
|
||||
if (parserContext.getRegistry().containsBeanDefinition(id)) {
|
||||
throw new IllegalStateException("Duplicate spring bean id " + id);
|
||||
}
|
||||
parserContext.getRegistry().registerBeanDefinition(id, rootBeanDefinition);
|
||||
}
|
||||
return rootBeanDefinition;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class TracingBeanParser implements BeanDefinitionParser {
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
// 获取Method并处理
|
||||
String methodPattern = element.getAttribute("method");
|
||||
if (methodPattern == null || methodPattern.length() == 0) {
|
||||
throw new IllegalStateException("Miss method pattern");
|
||||
}
|
||||
|
||||
String packageName = element.getAttribute("package");
|
||||
String className = element.getAttribute("class");
|
||||
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition();
|
||||
beanDefinition.setBeanClass(TracingClassBean.class);
|
||||
String id = null;
|
||||
id =element.getAttribute("name");
|
||||
int counter = 2;
|
||||
while(parserContext.getRegistry().containsBeanDefinition(id)) {
|
||||
id = id +(counter++);
|
||||
}
|
||||
if (id != null &&id.length() > 0) {
|
||||
if(parserContext.getRegistry().containsBeanDefinition(id)) {
|
||||
throw new IllegalStateException("Duplicate spring bean id " + id);
|
||||
}
|
||||
parserContext.getRegistry().registerBeanDefinition(id,beanDefinition);
|
||||
}
|
||||
NamedNodeMap nnm =element.getAttributes();
|
||||
for (int i = 0; i <nnm.getLength(); i++) {
|
||||
Node node =nnm.item(i);
|
||||
String key =node.getLocalName();
|
||||
String value =node.getNodeValue();
|
||||
if(key.equals("entity")) {
|
||||
if(parserContext.getRegistry().containsBeanDefinition(value)) {
|
||||
beanDefinition.getPropertyValues().add(key,parserContext.getRegistry().getBeanDefinition(value));
|
||||
} else {
|
||||
beanDefinition.getPropertyValues().add(key,new RuntimeBeanReference(value));
|
||||
}
|
||||
} else {
|
||||
beanDefinition.getPropertyValues().add(key,value);
|
||||
}
|
||||
}
|
||||
|
||||
return beanDefinition;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E>, Serializable {
|
||||
private static final long serialVersionUID = -8672117787651310382L;
|
||||
private static final Object PRESENT = new Object();
|
||||
private final ConcurrentHashMap<E, Object> map;
|
||||
|
||||
public ConcurrentHashSet() {
|
||||
this.map = new ConcurrentHashMap();
|
||||
}
|
||||
|
||||
public ConcurrentHashSet(int initialCapacity) {
|
||||
this.map = new ConcurrentHashMap(initialCapacity);
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return this.map.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.map.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.map.isEmpty();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
return this.map.containsKey(o);
|
||||
}
|
||||
|
||||
public boolean add(E e) {
|
||||
return this.map.put(e, PRESENT) == null;
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
return this.map.remove(o) == PRESENT;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<xsd:schema xmlns="http://code.alibabatech.com/schema/dubbo"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://code.alibabatech.com/schema/dubbo">
|
||||
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[ Namespace support for the skywalking tracing class. ]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:complexType name="tracingClassType">
|
||||
<xsd:attribute name="name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[ The class name that need to tracing. ]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
<xsd:attribute name="method" type="xsd:wildcard">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[ The method name that need to tracing. ]]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="tracingPackageType">
|
||||
<xsd:attribute name="name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="tracing-class" type="tracingClassType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[ The service argument config ]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="tracing-package" type="tracingPackageType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[ The service argument config ]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="tracing"/>
|
||||
</xsd:schema>
|
||||
|
|
@ -0,0 +1 @@
|
|||
http\://cloud.asiainfo.com/schema/skywalking=com.ai.cloud.skywalking.plugin.spring.schema.SWNamespaceHandler
|
||||
|
|
@ -0,0 +1 @@
|
|||
http\://cloud.asiainfo.com/schema/skywalking/skywalking.xsd=META-INF/skywalking.xsd
|
||||
Loading…
Reference in New Issue