Skip to content

Commit 865c07b

Browse files
committed
Merge pull request #3 from codeLief/trunk
ankang
2 parents d882a75 + 1bdf438 commit 865c07b

File tree

7 files changed

+121
-24
lines changed

7 files changed

+121
-24
lines changed

src/main/java/com/ankang/report/config/ReportConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static boolean dynamicLoadConfig(String key, Object value) {
127127

128128
public static boolean containsKey(String key) {
129129
if (null == key) {
130-
logger.warn("key is null");
130+
logger.error("key is null");
131131
return Boolean.FALSE;
132132
}
133133
return REPORTCONFIG.containsKey(key);

src/main/java/com/ankang/report/example/Example.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public TestResponse check(@ReportParam(value = "testRequest") TestRequest testRe
5959
@HTTP(value = "checkMap", desc = "例子")
6060
public void checkMap(Map<String, Object> params){
6161

62-
62+
System.out.println("进入方法");
6363
for (Map.Entry<String, Object> param : params.entrySet()) {
6464
System.out.println("key:"+param.getKey()+" value:"+param.getValue());
6565
}

src/main/java/com/ankang/report/factory/ObjBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public synchronized Object createBean(Class<?> clazz){
4141
return null;
4242
}
4343
Object object = null;
44-
object = BeanUtil.getBean(null, clazz);
44+
object = BeanUtil.getBean(clazz);
4545
if(null != object){
4646
return object;
4747
}

src/main/java/com/ankang/report/main/handler/impl/ReportRequestHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public ReportResponse handler(String serviceAlias, String methodAlias,
6969
return startInvoke.invoke(request, invocation);
7070
}
7171

72-
// 暂不支持map,数组封装 可通过滤器自定义 或自定义end_invoke
7372
@Override
7473
public ReportResponse invoke(HttpServletRequest request,
7574
Invocation invocation) throws Exception {

src/main/java/com/ankang/report/register/impl/ResolverRegister.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.ankang.report.pool.AbstractReportAliasPool;
3030
import com.ankang.report.register.ReportRegister;
3131
import com.ankang.report.resolver.ReportResolver;
32+
import com.ankang.report.resolver.impl.JsonProtocolResolver;
33+
import com.ankang.report.resolver.impl.XmlProtocolResolver;
3234
import com.ankang.report.util.ReportUtil;
3335

3436
@SuppressWarnings("all")
@@ -41,10 +43,10 @@ public final class ResolverRegister extends AbstractReportAliasPool implements R
4143

4244
@Override
4345
public boolean reginster() {
44-
List<Class<?>> resolverAll = ReportUtil.getAllClassByInterface(ReportResolver.class);
45-
for (Class<?> clazz : resolverAll) {
46-
configer(clazz);
47-
}
46+
47+
configer(JsonProtocolResolver.class);
48+
configer(XmlProtocolResolver.class);
49+
4850
ReportCabinet.getReportApplicationContext().putPool(POOL_ALIAS_NAME, RESOLVERPOOL);
4951
return Boolean.TRUE;
5052
}

src/main/java/com/ankang/report/util/BeanUtil.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,18 @@ public void setApplicationContext(ApplicationContext applicationContext)throws B
3434
context = applicationContext;
3535
}
3636

37-
public synchronized static Object getBean(String beanName, Class<?> beanCalzz) {
38-
37+
public synchronized static Object getBean(String beanName) {
3938
try {
40-
Object object = null;
41-
if(StringUtils.isNotEmpty(beanName)){
42-
if((object = context.getBean(beanName)) != null){
43-
return object;
44-
}
45-
}else{
46-
return context.getBean(beanCalzz);
47-
}
48-
49-
} catch (BeansException e) {
50-
try {
51-
return context.getBean(beanCalzz);
52-
} catch (BeansException f) {
39+
if(StringUtils.isEmpty(beanName)){
5340
return null;
5441
}
42+
return context.getBean(beanName);
43+
} catch (BeansException e) {
44+
return null;
5545
}
56-
return null;
46+
47+
}
48+
public synchronized static Object getBean(Class<?> beanCalzz){
49+
return context.getBeansOfType(beanCalzz);
5750
}
5851
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.ankang.report.util;
2+
3+
import java.lang.reflect.Method;
4+
import java.util.concurrent.Callable;
5+
import java.util.concurrent.ExecutorService;
6+
import java.util.concurrent.Executors;
7+
import java.util.concurrent.Future;
8+
import java.util.concurrent.SynchronousQueue;
9+
import java.util.concurrent.ThreadPoolExecutor;
10+
import java.util.concurrent.TimeUnit;
11+
12+
import org.apache.log4j.Logger;
13+
14+
15+
/**
16+
* @author ankang
17+
* @time 2016-1-10
18+
*/
19+
public class FutrueProxy{
20+
21+
private static final Logger logger = Logger.getLogger(FutrueProxy.class);
22+
23+
private ExecutorService service;
24+
25+
public FutrueProxy(int nThreads){
26+
27+
if(nThreads > 0){
28+
29+
service = new ThreadPoolExecutor(nThreads, nThreads, 60L, TimeUnit.SECONDS,
30+
new SynchronousQueue<Runnable>());
31+
}else{
32+
service = Executors.newCachedThreadPool();
33+
}
34+
}
35+
36+
/**
37+
*
38+
* @author ankang
39+
* @time 2016-1-10
40+
* @param targerService 目标类
41+
* @param targerMethod 目标方法名称 注:不要有方法名称一样,参数个数一样的本类认为重复的方法。
42+
* @param resultType 返回值类型
43+
* @param args 参数,与实际方法参数类型,顺序一致。
44+
* @return 返回Future 通过get()获取真实返回值,此方法为阻塞方法
45+
*/
46+
public <T> Future<T> excute(final Object targerService, final String targerMethod, final Class<T> resultType, final Object...args) {
47+
48+
Future<T> real = service.submit(new Callable<T>() {
49+
50+
@Override
51+
public T call() throws Exception {
52+
53+
try {
54+
55+
Method method = getMethod(targerService, targerMethod, args);
56+
57+
return (T)method.invoke(targerService, args);
58+
} catch (Exception e) {
59+
60+
logger.error(String.format("并行调用失败 targetService:[%s], targetMethod:[%s], args:[%s]",
61+
targerService, targerMethod, args), e);
62+
throw e;
63+
}
64+
}
65+
});
66+
67+
return real;
68+
}
69+
70+
public void excute(final Object targerService, final String targerMethod, final Object...args){
71+
72+
service.execute(new Runnable() {
73+
74+
@Override
75+
public void run(){
76+
try {
77+
getMethod(targerService, targerMethod, args).invoke(targerService, args);
78+
79+
} catch (Exception e) {
80+
logger.error(String.format("并行调用失败 targetService:[%s], targetMethod:[%s], args:[%s]",targerService,
81+
targerMethod, args), e);
82+
}
83+
84+
}
85+
});
86+
87+
}
88+
private Method getMethod(Object targer, String targerMethod, Object...args){
89+
90+
if(args == null){
91+
args = new Object[0];
92+
}
93+
int i = 0;
94+
Method[] methods = targer.getClass().getMethods();
95+
for (; i < methods.length; i++) {
96+
if(targerMethod.equals(methods[i].getName())
97+
&& args.length == methods[i].getParameterTypes().length){
98+
break;
99+
}
100+
}
101+
return methods[i];
102+
}
103+
}

0 commit comments

Comments
 (0)