Skip to content

Commit

Permalink
Merge pull request #3 from seata/develop
Browse files Browse the repository at this point in the history
V1.3.0
  • Loading branch information
igit-cn committed Jul 17, 2020
2 parents 1b4ea19 + fa080ed commit d52d0b4
Show file tree
Hide file tree
Showing 319 changed files with 11,252 additions and 6,940 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ For more details about principle and design, please go to [Seata wiki page](http

## Maven dependency
```xml
<seata.version>1.2.0</seata.version>
<seata.version>1.3.0</seata.version>

<dependency>
<groupId>io.seata</groupId>
Expand Down
3 changes: 1 addition & 2 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>

<name>Seata All-in-one ${project.version}</name>
<url>http://seata.io</url>
Expand Down Expand Up @@ -461,7 +461,6 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
Expand Down
18 changes: 17 additions & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>io.seata</groupId>
<artifactId>seata-bom</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>

<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down Expand Up @@ -123,6 +123,7 @@
<kryo-serializers.version>0.42</kryo-serializers.version>
<hessian.version>4.0.63</hessian.version>
<fst.version>2.57</fst.version>
<groovy.version>2.4.4</groovy.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -510,6 +511,21 @@
<artifactId>lz4-java</artifactId>
<version>${lz4.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -466,7 +468,7 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition>
while (urls.hasMoreElements()) {
java.net.URL url = urls.nextElement();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), Constants.DEFAULT_CHARSET))) {
String line = null;
String line;
while ((line = reader.readLine()) != null) {
final int ci = line.indexOf('#');
if (ci >= 0) {
Expand All @@ -475,10 +477,11 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition>
line = line.trim();
if (line.length() > 0) {
try {
Class<?> clazz = Class.forName(line, true, loader);
ExtensionDefinition extensionDefinition = getUnloadedExtensionDefinition(clazz);
ExtensionDefinition extensionDefinition = getUnloadedExtensionDefinition(line, loader);
if (extensionDefinition == null) {
LOGGER.warn("The same extension {} has already been loaded, skipped", line);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The same extension {} has already been loaded, skipped", line);
}
continue;
}
extensions.add(extensionDefinition);
Expand All @@ -488,24 +491,26 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition>
}
}
} catch (Throwable e) {
LOGGER.warn(e.getMessage());
LOGGER.warn("load clazz instance error: {}", e.getMessage());
}
}
}
}

private ExtensionDefinition getUnloadedExtensionDefinition(Class<?> clazz) {
String serviceName = null;
Integer priority = 0;
Scope scope = Scope.SINGLETON;
LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class);
if (loadLevel != null) {
serviceName = loadLevel.name();
priority = loadLevel.order();
scope = loadLevel.scope();
}
private ExtensionDefinition getUnloadedExtensionDefinition(String className, ClassLoader loader)
throws ClassNotFoundException {
//Check whether the definition has been loaded
if (!classToDefinitionMap.containsKey(clazz)) {
if (!isDefinitionContainsClazz(className, loader)) {
Class<?> clazz = Class.forName(className, true, loader);
String serviceName = null;
Integer priority = 0;
Scope scope = Scope.SINGLETON;
LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class);
if (loadLevel != null) {
serviceName = loadLevel.name();
priority = loadLevel.order();
scope = loadLevel.scope();
}
ExtensionDefinition result = new ExtensionDefinition(serviceName, priority, scope, clazz);
classToDefinitionMap.put(clazz, result);
if (serviceName != null) {
Expand All @@ -516,6 +521,18 @@ private ExtensionDefinition getUnloadedExtensionDefinition(Class<?> clazz) {
return null;
}

private boolean isDefinitionContainsClazz(String className, ClassLoader loader) {
for (Map.Entry<Class<?>, ExtensionDefinition> entry : classToDefinitionMap.entrySet()) {
if (!entry.getKey().getName().equals(className)) {
continue;
}
if (Objects.equals(entry.getValue().getServiceClass().getClassLoader(), loader)) {
return true;
}
}
return false;
}

private ExtensionDefinition getDefaultExtensionDefinition() {
List<ExtensionDefinition> currentDefinitions = definitionsHolder.get();
if (currentDefinitions != null && currentDefinitions.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static List<String> toUpperList(List<String> sourceList) {
if (isEmpty(sourceList)) { return sourceList; }
List<String> destList = new ArrayList<>(sourceList.size());
for (String element : sourceList) {
if (null != element) {
if (element != null) {
destList.add(element.toUpperCase());
} else {
destList.add(null);
Expand Down
17 changes: 14 additions & 3 deletions common/src/main/java/io/seata/common/util/IdWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/
package io.seata.common.util;

import java.util.concurrent.ThreadLocalRandom;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* @author funkye
Expand Down Expand Up @@ -144,13 +144,24 @@ public static IdWorker getInstance() {
if (idWorker == null) {
synchronized (IdWorker.class) {
if (idWorker == null) {
init(ThreadLocalRandom.current().nextLong(1024));
init(initWorkerId());
}
}
}
return idWorker;
}

public static long initWorkerId() {
InetAddress address;
try {
address = InetAddress.getLocalHost();
} catch (final UnknownHostException e) {
throw new IllegalStateException("Cannot get LocalHost InetAddress, please check your network!",e);
}
byte[] ipAddressByteArray = address.getAddress();
return ((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE) + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF);
}

public static void init(Long serverNodeId) {
if (idWorker == null) {
synchronized (IdWorker.class) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/io/seata/common/util/NetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class NetUtil {
* @return the string
*/
public static String toStringAddress(SocketAddress address) {
if (null == address) {
if (address == null) {
return StringUtils.EMPTY;
}
return toStringAddress((InetSocketAddress) address);
Expand Down Expand Up @@ -193,7 +193,7 @@ private static InetAddress getLocalAddress0() {
* @param address the address
*/
public static void validAddress(InetSocketAddress address) {
if (null == address.getHostName() || 0 == address.getPort()) {
if (address.getHostName() == null || 0 == address.getPort()) {
throw new IllegalArgumentException("invalid address:" + address);
}
}
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/io/seata/common/util/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public static Long toLong(String str, final Long defaultValue) {
return defaultValue;
}
}

public static Long toLong(String str) {
if (StringUtils.isNotBlank(str)) {
return Long.valueOf(str);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void testNestedException9() {
}

private static void exceptionAsserts(FrameworkException exception, String expectMessage) {
if (null == expectMessage) {
if (expectMessage == null) {
expectMessage = FrameworkErrorCode.UnknownAppError.getErrMessage();
}
assertThat(exception).isInstanceOf(FrameworkException.class).hasMessage(expectMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public class ApolloConfiguration extends AbstractConfiguration {

private ApolloConfiguration() {
readyApolloConfig();
if (null == config) {
if (config == null) {
synchronized (ApolloConfiguration.class) {
if (null == config) {
if (config == null) {
config = ConfigService.getConfig(FILE_CONFIG.getConfig(getApolloNamespaceKey(), DEFAULT_NAMESPACE));
configOperateExecutor = new ThreadPoolExecutor(CORE_CONFIG_OPERATE_THREAD,
MAX_CONFIG_OPERATE_THREAD, Integer.MAX_VALUE, TimeUnit.MILLISECONDS,
Expand Down Expand Up @@ -97,9 +97,9 @@ private ApolloConfiguration() {
* @return the instance
*/
public static ApolloConfiguration getInstance() {
if (null == instance) {
if (instance == null) {
synchronized (ApolloConfiguration.class) {
if (null == instance) {
if (instance == null) {
instance = new ApolloConfiguration();
}
}
Expand All @@ -108,7 +108,7 @@ public static ApolloConfiguration getInstance() {
}

@Override
public String getConfig(String dataId, String defaultValue, long timeoutMills) {
public String getLatestConfig(String dataId, String defaultValue, long timeoutMills) {
String value;
if ((value = getConfigFromSysPro(dataId)) != null) {
return value;
Expand Down Expand Up @@ -139,7 +139,7 @@ public boolean removeConfig(String dataId, long timeoutMills) {

@Override
public void addConfigListener(String dataId, ConfigurationChangeListener listener) {
if (null == dataId || null == listener) {
if (dataId == null || listener == null) {
return;
}
LISTENER_SERVICE_MAP.putIfAbsent(dataId, new ConcurrentSet<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ private ConsulConfiguration() {
* @return instance
*/
public static ConsulConfiguration getInstance() {
if (null == instance) {
if (instance == null) {
synchronized (ConsulConfiguration.class) {
if (null == instance) {
if (instance == null) {
instance = new ConsulConfiguration();
}
}
Expand All @@ -91,7 +91,7 @@ public static ConsulConfiguration getInstance() {
}

@Override
public String getConfig(String dataId, String defaultValue, long timeoutMills) {
public String getLatestConfig(String dataId, String defaultValue, long timeoutMills) {
String value;
if ((value = getConfigFromSysPro(dataId)) != null) {
return value;
Expand Down Expand Up @@ -131,7 +131,7 @@ public boolean removeConfig(String dataId, long timeoutMills) {

@Override
public void addConfigListener(String dataId, ConfigurationChangeListener listener) {
if (null == dataId || null == listener) {
if (dataId == null || listener == null) {
return;
}
configListenersMap.putIfAbsent(dataId, new ConcurrentSet<>());
Expand Down Expand Up @@ -173,9 +173,9 @@ public String getTypeName() {
* @return client
*/
private static ConsulClient getConsulClient() {
if (null == client) {
if (client == null) {
synchronized (ConsulConfiguration.class) {
if (null == client) {
if (client == null) {
String serverAddr = FILE_CONFIG.getConfig(FILE_CONFIG_KEY_PREFIX + SERVER_ADDR_KEY);
InetSocketAddress inetSocketAddress = NetUtil.toInetSocketAddress(serverAddr);
client = new ConsulClient(inetSocketAddress.getHostName(), inetSocketAddress.getPort());
Expand All @@ -192,7 +192,7 @@ private static ConsulClient getConsulClient() {
* @param configFuture
*/
private void complete(Response response, ConfigFuture configFuture) {
if (null != response && null != response.getValue()) {
if (response != null && response.getValue() != null) {
Object value = response.getValue();
if (value instanceof GetValue) {
configFuture.setResult(((GetValue)value).getDecodedValue());
Expand Down Expand Up @@ -228,7 +228,7 @@ public ConsulListener(String dataId, ConfigurationChangeListener listener) {

@Override
public void onChangeEvent(ConfigurationChangeEvent event) {
if (null != listener) {
if (listener != null) {
while (true) {
QueryParams queryParams = new QueryParams(DEFAULT_WATCH_TIMEOUT, consulIndex);
Response<GetValue> response = getConsulClient().getKVValue(this.dataId, queryParams);
Expand Down
4 changes: 4 additions & 0 deletions config/seata-config-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package io.seata.config;


import io.seata.common.util.DurationUtil;

import java.time.Duration;
import io.seata.common.util.DurationUtil;

/**
* The type Abstract configuration.
Expand Down Expand Up @@ -122,6 +120,11 @@ public String getConfig(String dataId, long timeoutMills) {
return getConfig(dataId, null, timeoutMills);
}

@Override
public String getConfig(String dataId, String content, long timeoutMills) {
return getLatestConfig(dataId, content, timeoutMills);
}

@Override
public String getConfig(String dataId) {
return getConfig(dataId, DEFAULT_CONFIG_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ public interface Configuration {
*/
boolean putConfig(String dataId, String content, long timeoutMills);

/**
*
* @param dataId the data id
* @param defaultValue the default value
* @param timeoutMills the timeout mills
* @return the Latest config
*/
String getLatestConfig(String dataId, String defaultValue, long timeoutMills);

/**
* Put config boolean.
*
Expand Down
Loading

0 comments on commit d52d0b4

Please sign in to comment.