-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
1,447 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...-core/src/main/java/com/yiqiniu/easytrans/protocol/AnnotationBusinessProviderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.yiqiniu.easytrans.protocol; | ||
|
||
import java.io.Serializable; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
|
||
import com.yiqiniu.easytrans.executor.EasyTransExecutor; | ||
|
||
public abstract class AnnotationBusinessProviderBuilder implements ApplicationContextAware { | ||
|
||
private ApplicationContext ctx; | ||
|
||
protected ApplicationContext getApplicationContext() { | ||
return ctx; | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.ctx = applicationContext; | ||
} | ||
|
||
|
||
public abstract Class<? extends Annotation> getTargetAnnotation(); | ||
|
||
public abstract BusinessProvider<?> create(Annotation ann, Object proxyObj, Method targetMethod, Class<?> requestClass, String beanName); | ||
|
||
public abstract Class<? extends EasyTransRequest<?, ?>> getActualConfigClass(Annotation ann, Class<?> requestClass); | ||
|
||
@SuppressWarnings("rawtypes") | ||
public static class NullEasyTransRequest<R extends Serializable,E extends EasyTransExecutor> implements EasyTransRequest{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
easytrans-core/src/main/java/com/yiqiniu/easytrans/protocol/AnnotationProviderRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.yiqiniu.easytrans.protocol; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.aop.support.AopUtils; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; | ||
|
||
import com.yiqiniu.easytrans.util.ReflectUtil; | ||
|
||
public class AnnotationProviderRegister extends InstantiationAwareBeanPostProcessorAdapter { | ||
|
||
private Map<Class<? extends Annotation>,AnnotationBusinessProviderBuilder> mapHandler; | ||
private ConfigurableListableBeanFactory beanFactory; | ||
|
||
public AnnotationProviderRegister(List<AnnotationBusinessProviderBuilder> listHandler, ConfigurableListableBeanFactory beanFactory) { | ||
this.beanFactory = beanFactory; | ||
mapHandler = new HashMap<>(listHandler.size() * 2); | ||
for(AnnotationBusinessProviderBuilder handler :listHandler) { | ||
mapHandler.put(handler.getTargetAnnotation(), handler); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { | ||
if(bean instanceof AnnotationBusinessProviderBuilder) { | ||
return true; | ||
} | ||
|
||
Class<?> targetClass = AopUtils.getTargetClass(bean); | ||
for(Method m : targetClass.getMethods()) { | ||
for(Annotation a : m.getAnnotations()) { | ||
AnnotationBusinessProviderBuilder builder = mapHandler.get(a.annotationType()); | ||
if(builder != null) { | ||
|
||
Class<?>[] parameterTypes = m.getParameterTypes(); | ||
if(parameterTypes.length != 1) { | ||
throw new IllegalArgumentException("method should conatins only One parameter, method:" + m); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
Class<? extends EasyTransRequest<?, ?>> requestClass = (Class<? extends EasyTransRequest<?, ?>>) parameterTypes[0]; | ||
|
||
//create and register in bean factory | ||
BusinessProvider<?> provider = builder.create(a, bean, m, requestClass,beanName); | ||
|
||
Class<? extends EasyTransRequest<?, ?>> cfgClass = builder.getActualConfigClass(a, requestClass); | ||
BusinessIdentifer businessIdentifer = ReflectUtil.getBusinessIdentifer(cfgClass); | ||
|
||
if(businessIdentifer == null) { | ||
throw new RuntimeException("can not find BusinessIdentifer in request class!" + requestClass); | ||
} | ||
|
||
beanFactory.registerSingleton(businessIdentifer.appId() + "-" + businessIdentifer.busCode() +"-provider", provider); | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
easytrans-core/src/main/java/com/yiqiniu/easytrans/protocol/RequestClassAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.yiqiniu.easytrans.protocol; | ||
|
||
public interface RequestClassAware { | ||
|
||
public static final String GET_REQUEST_CLASS = "getRequestClass"; | ||
|
||
Class<? extends EasyTransRequest<?, ?>> getRequestClass(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
easytrans-core/src/main/java/com/yiqiniu/easytrans/protocol/aft/EtAfterMasterTrans.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.yiqiniu.easytrans.protocol.aft; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import com.yiqiniu.easytrans.protocol.AnnotationBusinessProviderBuilder.NullEasyTransRequest; | ||
import com.yiqiniu.easytrans.protocol.EasyTransRequest; | ||
|
||
/** | ||
* place in method of the bean that managed by spring | ||
* this method will do the TCC try | ||
* confirmMethod and cancelMethod should in the same class | ||
* @author xudeyou | ||
* | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@SuppressWarnings("rawtypes") | ||
public @interface EtAfterMasterTrans { | ||
|
||
/** | ||
* BusinessProvider.IDENPOTENT_TYPE_FRAMEWORK | ||
* BusinessProvider.IDENPOTENT_TYPE_BUSINESS | ||
* @return | ||
*/ | ||
int idempotentType(); | ||
|
||
|
||
/** | ||
* 当标注的方法的入参并非继承自EasyTransRequest时,需要用本字段指定继承自该类的类 | ||
* @return | ||
*/ | ||
Class<? extends EasyTransRequest> cfgClass() default NullEasyTransRequest.class; | ||
|
||
|
||
} |
Oops, something went wrong.