Skip to content

Commit af36544

Browse files
authored
release 0.4.0
2 parents 3ffa06e + 80014a0 commit af36544

File tree

114 files changed

+5004
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5004
-359
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cache:
1212
install: true
1313

1414
script:
15-
- mvn clean package
15+
- mvn clean package verify
1616

1717
after_success:
18-
- bash <(curl -s https://codecov.io/bash)
18+
- bash <(curl -s https://codecov.io/bash)

common/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<artifactId>fescar-all</artifactId>
2222
<groupId>com.alibaba.fescar</groupId>
23-
<version>0.3.1</version>
23+
<version>0.4.0</version>
2424
</parent>
2525
<modelVersion>4.0.0</modelVersion>
2626
<artifactId>fescar-common</artifactId>
@@ -38,6 +38,7 @@
3838
<dependency>
3939
<groupId>ch.qos.logback</groupId>
4040
<artifactId>logback-classic</artifactId>
41+
<optional>true</optional>
4142
</dependency>
4243
<dependency>
4344
<groupId>commons-lang</groupId>

common/src/main/java/com/alibaba/fescar/common/Constants.java

+58
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,62 @@ public class Constants {
4040
*/
4141
public static final String DBKEYS_SPLIT_CHAR = ",";
4242

43+
/** the start time of transaction */
44+
public static final String START_TIME = "start-time";
45+
46+
/**
47+
* app name
48+
*/
49+
public static final String APP_NAME = "appName";
50+
51+
/**
52+
* TCC start time
53+
*/
54+
public static final String ACTION_START_TIME = "action-start-time";
55+
56+
/**
57+
* TCC name
58+
*/
59+
public final static String ACTION_NAME = "actionName";
60+
61+
/**
62+
* phase one method name
63+
*/
64+
public final static String PREPARE_METHOD = "sys::prepare";
65+
66+
/**
67+
* phase two commit method name
68+
*/
69+
public final static String COMMIT_METHOD = "sys::commit";
70+
71+
/**
72+
* phase two rollback method name
73+
*/
74+
public final static String ROLLBACK_METHOD = "sys::rollback";
75+
76+
/**
77+
* host ip
78+
*/
79+
public final static String HOST_NAME = "host-name";
80+
81+
/**
82+
* The constant TCC_METHOD_RESULT.
83+
*/
84+
public final static String TCC_METHOD_RESULT = "result";
85+
86+
/**
87+
* The constant TCC_METHOD_ARGUMENTS.
88+
*/
89+
public final static String TCC_METHOD_ARGUMENTS = "arguments";
90+
91+
/**
92+
* transaction context
93+
*/
94+
public final static String TCC_ACTIVITY_CONTEXT = "activityContext";
95+
96+
/**
97+
* branch context
98+
*/
99+
public final static String TCC_ACTION_CONTEXT = "actionContext";
100+
43101
}

common/src/main/java/com/alibaba/fescar/common/exception/NotSupportYetException.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
/**
2020
* The type Not support yet exception.
21+
*
22+
* @author jimin.jm @alibaba-inc.com
2123
*/
2224
public class NotSupportYetException extends RuntimeException {
2325

common/src/main/java/com/alibaba/fescar/common/exception/ShouldNeverHappenException.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
/**
2020
* The type Should never happen exception.
21+
*
22+
* @author jimin.jm @alibaba-inc.com
2123
*/
2224
public class ShouldNeverHappenException extends RuntimeException {
2325

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fescar.common.executor;
18+
19+
/**
20+
* The interface Callback.
21+
*
22+
* @param <T> the type parameter
23+
*
24+
* @author zhangsen
25+
*/
26+
public interface Callback<T> {
27+
28+
/**
29+
* Execute t.
30+
*
31+
* @return the t
32+
* @throws Throwable the throwable
33+
*/
34+
public T execute() throws Throwable;
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fescar.common.executor;
18+
19+
/**
20+
* The interface Initialize.
21+
*
22+
* @author zhangsen
23+
*/
24+
public interface Initialize {
25+
26+
/**
27+
* init method
28+
*/
29+
public void init();
30+
31+
}

common/src/main/java/com/alibaba/fescar/common/loader/EnhancedServiceLoader.java

+54-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
package com.alibaba.fescar.common.loader;
1818

19+
import com.alibaba.fescar.common.executor.Initialize;
20+
import com.alibaba.fescar.common.util.CollectionUtils;
21+
import org.apache.commons.lang.ObjectUtils;
22+
import org.apache.commons.lang.StringUtils;
23+
import org.apache.commons.lang.exception.ExceptionUtils;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
1927
import java.io.BufferedReader;
2028
import java.io.IOException;
2129
import java.io.InputStreamReader;
@@ -28,12 +36,6 @@
2836
import java.util.Map;
2937
import java.util.concurrent.ConcurrentHashMap;
3038

31-
import org.apache.commons.lang.ObjectUtils;
32-
import org.apache.commons.lang.StringUtils;
33-
import org.apache.commons.lang.exception.ExceptionUtils;
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
36-
3739
/**
3840
* The type Enhanced service loader.
3941
*
@@ -100,6 +102,29 @@ public static <S> S load(Class<S> service, String activateName, ClassLoader load
100102
return loadFile(service, activateName, loader);
101103
}
102104

105+
/**
106+
* get all implements
107+
*
108+
* @param <S> the type parameter
109+
* @param service the service
110+
* @return list
111+
*/
112+
public static <S> List<S> loadAll(Class<S> service){
113+
List<S> allInstances = new ArrayList<>();
114+
List<Class> allClazzs = getAllExtensionClass(service);
115+
if(CollectionUtils.isEmpty(allClazzs)){
116+
return allInstances;
117+
}
118+
try {
119+
for(Class clazz : allClazzs){
120+
allInstances.add(initInstance(service, clazz));
121+
}
122+
} catch (Throwable t) {
123+
throw new EnhancedServiceNotFoundException(t);
124+
}
125+
return allInstances;
126+
}
127+
103128
/**
104129
* 获取所有的扩展类,按照{@linkplain LoadLevel}定义的order顺序进行排序
105130
*
@@ -163,20 +188,18 @@ private static <S> S loadFile(Class<S> service, String activateName, ClassLoader
163188
"not found service provider for : " + service.getName() + "[" + activateName
164189
+ "] and classloader : " + ObjectUtils.toString(loader));
165190
}
166-
Class<?> extension = extensions.get(extensions.size() - 1);
167-
S result = service.cast(extension.newInstance());
191+
Class<?> extension = extensions.get(extensions.size() - 1);// 最大的一个
192+
S result = initInstance(service, extension);
168193
if (!foundFromCache && LOGGER.isInfoEnabled()) {
169-
LOGGER.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class[" + extension
170-
.getName() + "]");
194+
LOGGER.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class[" + extension.getName() + "]");
171195
}
172196
return result;
173197
} catch (Throwable e) {
174198
if (e instanceof EnhancedServiceNotFoundException) {
175-
throw (EnhancedServiceNotFoundException)e;
199+
throw (EnhancedServiceNotFoundException) e;
176200
} else {
177201
throw new EnhancedServiceNotFoundException(
178-
"not found service provider for : " + service.getName() + " caused by " + ExceptionUtils
179-
.getFullStackTrace(e));
202+
"not found service provider for : " + service.getName() + " caused by " + ExceptionUtils.getFullStackTrace(e));
180203
}
181204
}
182205
}
@@ -263,6 +286,24 @@ private static void loadFile(Class<?> service, String dir, ClassLoader classLoad
263286
}
264287
}
265288

289+
/**
290+
* init instance
291+
*
292+
* @param <S> the type parameter
293+
* @param service the service
294+
* @param implClazz the impl clazz
295+
* @return s
296+
* @throws IllegalAccessException the illegal access exception
297+
* @throws InstantiationException the instantiation exception
298+
*/
299+
protected static <S> S initInstance(Class<S> service, Class implClazz) throws IllegalAccessException, InstantiationException {
300+
S s = service.cast(implClazz.newInstance());
301+
if(s instanceof Initialize){
302+
((Initialize)s).init();
303+
}
304+
return s;
305+
}
306+
266307
private static ClassLoader findClassLoader() {
267308
// 不能使用TCCL,在pandora容器中会导致无法加载plugin中的类
268309
return EnhancedServiceLoader.class.getClassLoader();

common/src/main/java/com/alibaba/fescar/common/thread/RejectedPolicies.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Policies for RejectedExecutionHandler
2525
*
26-
* Created by guoyao on 2019/2/26.
26+
* @author guoyao
2727
*/
2828
public final class RejectedPolicies {
2929

common/src/main/java/com/alibaba/fescar/common/util/BlobUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
/**
2828
* The type Blob utils.
29+
*
30+
* @author jimin.jm @alibaba-inc.com
2931
*/
3032
public class BlobUtils {
3133

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fescar.common.util;
18+
19+
import java.util.Collection;
20+
21+
/**
22+
* The type Collection utils.
23+
*
24+
* @author zhangsen
25+
*/
26+
public class CollectionUtils {
27+
28+
/**
29+
* Is empty boolean.
30+
*
31+
* @param col the col
32+
* @return the boolean
33+
*/
34+
public static boolean isEmpty(Collection col){
35+
return !isNotEmpty(col);
36+
}
37+
38+
/**
39+
* Is not empty boolean.
40+
*
41+
* @param col the col
42+
* @return the boolean
43+
*/
44+
public static boolean isNotEmpty(Collection col){
45+
return col != null && col.size() > 0;
46+
}
47+
}

0 commit comments

Comments
 (0)