Skip to content

Commit

Permalink
optimize: optimize config compatible module (apache#6403)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly authored Apr 30, 2024
1 parent 8c3224f commit 4f16097
Show file tree
Hide file tree
Showing 22 changed files with 1,717 additions and 88 deletions.
6 changes: 2 additions & 4 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,12 @@ Add changes here for all PR submitted to the 2.x branch.
retry mechanism
- [[#6387](https://github.com/apache/incubator-seata/pull/6387)] optimize tcc use compatible
- [[#6402](https://github.com/apache/incubator-seata/pull/6402)] optimize rm-datasource use compatible
- [[#6403](https://github.com/apache/incubator-seata/pull/6403)] optimize config compatible module
- [[#6419](https://github.com/apache/incubator-seata/pull/6419)] optimize integration-tx-api compatible
- [[#6427](https://github.com/apache/incubator-seata/pull/6427)] support spi、saga、spring module compatible
- [[#6442](https://github.com/apache/incubator-seata/pull/6442)] clarify if conditions
- [[#6487](https://github.com/apache/incubator-seata/pull/6487)] fix typo and package name

### refactor:
- [[#6269](https://github.com/apache/incubator-seata/pull/6269)] standardize Seata Exception
- [[#6442](https://github.com/apache/incubator-seata/pull/6442)] clarify if conditions
- [[#6405](https://github.com/apache/incubator-seata/pull/6405)] fix kotlin compile failure
- [[#6412](https://github.com/apache/incubator-seata/pull/6412)] optimize core compatible module
- [[#6429](https://github.com/apache/incubator-seata/pull/6429)] remove repetitive words
Expand Down Expand Up @@ -153,7 +152,6 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6484](https://github.com/apache/incubator-seata/pull/6484)] fix FileConfigurationTest and MockServerTest fail

### refactor:

- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] refactor Saga designer using diagram-js
- [[#6269](https://github.com/apache/incubator-seata/pull/6269)] standardize Seata Exception
- [[#6420](https://github.com/apache/incubator-seata/pull/6420)] refactor Configuration Cache
Expand Down
4 changes: 3 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
- [[#6391](https://github.com/apache/incubator-seata/pull/6091)] 禁止重复注册TCC资源
- [[#6393](https://github.com/apache/incubator-seata/pull/6393)] 元数据同步前判断版本,并增加重试功能
- [[#6387](https://github.com/apache/incubator-seata/pull/6387)] 优化tcc使用兼容
- [[#6403](https://github.com/apache/incubator-seata/pull/6403)] 优化 Config 兼容模块
- [[#6402](https://github.com/apache/incubator-seata/pull/6402)] 优化rm-datasource向下兼容
- [[#6419](https://github.com/apache/incubator-seata/pull/6419)] 优化integration-tx-api向下兼容
- [[#6427](https://github.com/apache/incubator-seata/pull/6427)] 支持spi、saga、spring模块的向下兼容
Expand All @@ -129,6 +130,7 @@
- [[#6412](https://github.com/apache/incubator-seata/pull/6412)] 优化 core 兼容模块
- [[#6429](https://github.com/apache/incubator-seata/pull/6429)] 移除重复注释


### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞
- [[#6144](https://github.com/apache/incubator-seata/pull/6144)] 升级Nacos依赖版本至1.4.6
Expand All @@ -151,10 +153,10 @@
- [[#6484](https://github.com/apache/incubator-seata/pull/6484)] 修复FileConfigurationTest和MockServerTest失败

### refactor:

- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] 使用diagram-js重构Saga设计器
- [[#6269](https://github.com/apache/incubator-seata/pull/6269)] 统一Seata异常规范
- [[#6420](https://github.com/apache/incubator-seata/pull/6420)] 优化配置缓存
- [[#6269](https://github.com/apache/incubator-seata/pull/6269)] 统一Seata异常规范

非常感谢以下 contributors 的代码贡献。若有无意遗漏,请报告。

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* The type String utils.
*
* Compatible for dubbo dubbo-filter-seata
* Notes:
* https://github.com/apache/dubbo-spi-extensions/blob/master/dubbo-filter-extensions/dubbo-filter-seata/src/main
* /java/org/apache/dubbo/seata/SeataTransactionPropagationProviderFilter.java
*/
public class StringUtils {
/**
Expand Down
12 changes: 12 additions & 0 deletions compatible/src/main/java/io/seata/core/context/RootContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
*/
public class RootContext {

/**
* The constant KEY_XID.
* used for apache dubbo
*/
public static final String KEY_XID = "TX_XID";

/**
* The constant KEY_BRANCH_TYPE
* * used for apache dubbo
*/
public static final String KEY_BRANCH_TYPE = "TX_BRANCH_TYPE";

private static BranchType convertIoSeata(org.apache.seata.core.model.BranchType branchType) {
return BranchType.get(branchType.name());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.config;

import java.time.Duration;

import org.apache.seata.common.util.DurationUtil;
import org.apache.seata.common.util.StringUtils;

public abstract class AbstractConfiguration implements Configuration {
/**
* The constant DEFAULT_CONFIG_TIMEOUT.
*/
protected static final long DEFAULT_CONFIG_TIMEOUT = 5 * 1000;

/**
* The constant DEFAULT_XXX.
*/
public static final short DEFAULT_SHORT = (short)0;
public static final int DEFAULT_INT = 0;
public static final long DEFAULT_LONG = 0L;
public static final Duration DEFAULT_DURATION = Duration.ZERO;
public static final boolean DEFAULT_BOOLEAN = false;

@Override
public short getShort(String dataId, short defaultValue, long timeoutMills) {
String result = getConfig(dataId, timeoutMills);
return StringUtils.isBlank(result) ? defaultValue : Short.parseShort(result);
}

@Override
public short getShort(String dataId, short defaultValue) {
return getShort(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public short getShort(String dataId) {
return getShort(dataId, DEFAULT_SHORT);
}

@Override
public int getInt(String dataId, int defaultValue, long timeoutMills) {
String result = getConfig(dataId, timeoutMills);
return StringUtils.isBlank(result) ? defaultValue : Integer.parseInt(result);
}

@Override
public int getInt(String dataId, int defaultValue) {
return getInt(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public int getInt(String dataId) {
return getInt(dataId, DEFAULT_INT);
}

@Override
public long getLong(String dataId, long defaultValue, long timeoutMills) {
String result = getConfig(dataId, timeoutMills);
return StringUtils.isBlank(result) ? defaultValue : Long.parseLong(result);
}

@Override
public long getLong(String dataId, long defaultValue) {
return getLong(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public long getLong(String dataId) {
return getLong(dataId, DEFAULT_LONG);
}

@Override
public Duration getDuration(String dataId) {
return getDuration(dataId, DEFAULT_DURATION);
}

@Override
public Duration getDuration(String dataId, Duration defaultValue) {
return getDuration(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public Duration getDuration(String dataId, Duration defaultValue, long timeoutMills) {
String result = getConfig(dataId, timeoutMills);
return StringUtils.isBlank(result) ? defaultValue : DurationUtil.parse(result);
}

@Override
public boolean getBoolean(String dataId, boolean defaultValue, long timeoutMills) {
String result = getConfig(dataId, timeoutMills);
return StringUtils.isBlank(result) ? defaultValue : Boolean.parseBoolean(result);
}

@Override
public boolean getBoolean(String dataId, boolean defaultValue) {
return getBoolean(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public boolean getBoolean(String dataId) {
return getBoolean(dataId, DEFAULT_BOOLEAN);
}

@Override
public String getConfig(String dataId, String defaultValue) {
return getConfig(dataId, defaultValue, DEFAULT_CONFIG_TIMEOUT);
}

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

@Override
public String getConfig(String dataId, String content, long timeoutMills) {
String value = getConfigFromSys(dataId);
if (value != null) {
return value;
}
return getLatestConfig(dataId, content, timeoutMills);
}

@Override
public String getConfig(String dataId) {
return getConfig(dataId, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public boolean putConfig(String dataId, String content) {
return putConfig(dataId, content, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public boolean putConfigIfAbsent(String dataId, String content) {
return putConfigIfAbsent(dataId, content, DEFAULT_CONFIG_TIMEOUT);
}

@Override
public boolean removeConfig(String dataId) {
return removeConfig(dataId, DEFAULT_CONFIG_TIMEOUT);
}

/**
* Gets type name.
*
* @return the type name
*/
public abstract String getTypeName();
}
Loading

0 comments on commit 4f16097

Please sign in to comment.