chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
71
core/pom.xml
Normal file
71
core/pom.xml
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-core ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-discovery-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-pool</groupId>
|
||||
<artifactId>commons-pool</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
80
core/src/main/java/io/seata/core/README.md
Normal file
80
core/src/main/java/io/seata/core/README.md
Normal file
@@ -0,0 +1,80 @@
|
||||
## request
|
||||
|
||||
rm client -> server
|
||||
|
||||
```
|
||||
RegisterRMRequest
|
||||
|
||||
MergedWarpMessage
|
||||
|
||||
BranchRegisterRequest
|
||||
BranchReportRequest
|
||||
GlobalLockQueryRequest
|
||||
```
|
||||
|
||||
tm client -> server
|
||||
|
||||
```
|
||||
RegisterTMRequest
|
||||
|
||||
MergedWarpMessage
|
||||
|
||||
GlobalBeginRequest
|
||||
GlobalCommitRequest
|
||||
GlobalRollbackRequest
|
||||
GlobalStatusRequest
|
||||
GlobalReportRequest
|
||||
```
|
||||
|
||||
server -> rm client
|
||||
|
||||
```
|
||||
BranchCommitRequest
|
||||
BranchRollbackRequest
|
||||
UndoLogDeleteRequest
|
||||
```
|
||||
|
||||
server -> tm client
|
||||
|
||||
```
|
||||
// null
|
||||
```
|
||||
|
||||
## response
|
||||
|
||||
Server -> rm client
|
||||
|
||||
```
|
||||
RegisterRMResponse
|
||||
|
||||
MergeResultMessage
|
||||
BranchRegisterResponse
|
||||
BranchReportResponse
|
||||
GlobalLockQueryResponse
|
||||
```
|
||||
|
||||
Server -> tm client
|
||||
|
||||
```
|
||||
RegisterTMResponse
|
||||
|
||||
MergeResultMessage
|
||||
GlobalBeginResponse
|
||||
GlobalCommitResponse
|
||||
GlobalReportResponse
|
||||
GlobalRollbackResponse
|
||||
```
|
||||
|
||||
rm client -> server
|
||||
|
||||
```
|
||||
BranchCommitResponse
|
||||
BranchRollbackResponse
|
||||
```
|
||||
|
||||
tm client -> server
|
||||
|
||||
```
|
||||
// null
|
||||
```
|
||||
|
||||
24
core/src/main/java/io/seata/core/auth/AuthSigner.java
Normal file
24
core/src/main/java/io/seata/core/auth/AuthSigner.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.auth;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
public interface AuthSigner {
|
||||
String sign(String data, String key);
|
||||
}
|
||||
30
core/src/main/java/io/seata/core/auth/DefaultAuthSigner.java
Normal file
30
core/src/main/java/io/seata/core/auth/DefaultAuthSigner.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.auth;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
|
||||
/**
|
||||
* @author slievrly
|
||||
*/
|
||||
@LoadLevel(name = "defaultAuthSigner", order = 100)
|
||||
public class DefaultAuthSigner implements AuthSigner {
|
||||
@Override
|
||||
public String sign(String data, String key) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
37
core/src/main/java/io/seata/core/compressor/Compressor.java
Normal file
37
core/src/main/java/io/seata/core/compressor/Compressor.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.compressor;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public interface Compressor {
|
||||
|
||||
/**
|
||||
* compress byte[] to byte[].
|
||||
* @param bytes the bytes
|
||||
* @return the byte[]
|
||||
*/
|
||||
byte[] compress(byte[] bytes);
|
||||
|
||||
/**
|
||||
* decompress byte[] to byte[].
|
||||
* @param bytes the bytes
|
||||
* @return the byte[]
|
||||
*/
|
||||
byte[] decompress(byte[] bytes);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.compressor;
|
||||
|
||||
import io.seata.common.loader.EnhancedServiceLoader;
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.common.util.CollectionUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* the type compressor factory
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public class CompressorFactory {
|
||||
|
||||
/**
|
||||
* The constant COMPRESSOR_MAP.
|
||||
*/
|
||||
protected static final Map<CompressorType, Compressor> COMPRESSOR_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
COMPRESSOR_MAP.put(CompressorType.NONE, new NoneCompressor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get compressor by code.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the compressor
|
||||
*/
|
||||
public static Compressor getCompressor(byte code) {
|
||||
CompressorType type = CompressorType.getByCode(code);
|
||||
return CollectionUtils.computeIfAbsent(COMPRESSOR_MAP, type,
|
||||
key -> EnhancedServiceLoader.load(Compressor.class, type.name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* None compressor
|
||||
*/
|
||||
@LoadLevel(name = "NONE")
|
||||
public static class NoneCompressor implements Compressor {
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
102
core/src/main/java/io/seata/core/compressor/CompressorType.java
Normal file
102
core/src/main/java/io/seata/core/compressor/CompressorType.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.compressor;
|
||||
|
||||
/**
|
||||
* @author Geng Zhang
|
||||
*/
|
||||
public enum CompressorType {
|
||||
|
||||
/**
|
||||
* Not compress
|
||||
*/
|
||||
NONE((byte) 0),
|
||||
|
||||
/**
|
||||
* The gzip.
|
||||
*/
|
||||
GZIP((byte) 1),
|
||||
|
||||
/**
|
||||
* The zip.
|
||||
*/
|
||||
ZIP((byte) 2),
|
||||
|
||||
/**
|
||||
* The sevenz.
|
||||
*/
|
||||
SEVENZ((byte) 3),
|
||||
|
||||
/**
|
||||
* The bzip2.
|
||||
*/
|
||||
BZIP2((byte) 4),
|
||||
|
||||
/**
|
||||
* The lz4.
|
||||
*/
|
||||
LZ4((byte) 5),
|
||||
|
||||
/**
|
||||
* The deflater.
|
||||
*/
|
||||
DEFLATER((byte) 6);
|
||||
|
||||
private final byte code;
|
||||
|
||||
CompressorType(final byte code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets result code.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the result code
|
||||
*/
|
||||
public static CompressorType getByCode(int code) {
|
||||
for (CompressorType b : CompressorType.values()) {
|
||||
if (code == b.code) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown codec:" + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets result code.
|
||||
*
|
||||
* @param name the code
|
||||
* @return the result code
|
||||
*/
|
||||
public static CompressorType getByName(String name) {
|
||||
for (CompressorType b : CompressorType.values()) {
|
||||
if (b.name().equalsIgnoreCase(name)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown codec:" + name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public byte getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
/**
|
||||
* client table columns name.
|
||||
*
|
||||
* @author zjinlei
|
||||
*/
|
||||
public interface ClientTableColumnsName {
|
||||
|
||||
/**
|
||||
* The constant undo_log column name xid
|
||||
* this field is not use in mysql
|
||||
*/
|
||||
String UNDO_LOG_ID = "id";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name xid
|
||||
*/
|
||||
String UNDO_LOG_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name branch_id
|
||||
*/
|
||||
String UNDO_LOG_BRANCH_XID = "branch_id";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name context
|
||||
*/
|
||||
String UNDO_LOG_CONTEXT = "context";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name rollback_info
|
||||
*/
|
||||
String UNDO_LOG_ROLLBACK_INFO = "rollback_info";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name log_status
|
||||
*/
|
||||
String UNDO_LOG_LOG_STATUS = "log_status";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name log_created
|
||||
*/
|
||||
String UNDO_LOG_LOG_CREATED = "log_created";
|
||||
|
||||
/**
|
||||
* The constant undo_log column name log_modified
|
||||
*/
|
||||
String UNDO_LOG_LOG_MODIFIED = "log_modified";
|
||||
}
|
||||
@@ -0,0 +1,660 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
/**
|
||||
* The type Configuration keys.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public interface ConfigurationKeys {
|
||||
|
||||
/**
|
||||
* The constant SEATA_PREFIX.
|
||||
*/
|
||||
String SEATA_PREFIX = "seata.";
|
||||
|
||||
/**
|
||||
* The constant SERVICE_PREFIX.
|
||||
*/
|
||||
String SERVICE_PREFIX = "service.";
|
||||
|
||||
/**
|
||||
* The constant STORE_PREFIX.
|
||||
*/
|
||||
String STORE_PREFIX = "store.";
|
||||
|
||||
/**
|
||||
* The constant STORE_MODE.
|
||||
*/
|
||||
String STORE_MODE = STORE_PREFIX + "mode";
|
||||
|
||||
/**
|
||||
* The constant STORE_PUBLIC_KEY.
|
||||
*/
|
||||
public static final String STORE_PUBLIC_KEY = STORE_PREFIX + "publicKey";
|
||||
|
||||
/**
|
||||
* The constant STORE_FILE_PREFIX
|
||||
*/
|
||||
String STORE_FILE_PREFIX = STORE_PREFIX + "file.";
|
||||
|
||||
/**
|
||||
* The constant STORE_FILE_DIR
|
||||
*/
|
||||
String STORE_FILE_DIR = STORE_FILE_PREFIX + "dir";
|
||||
|
||||
/**
|
||||
* The constant SERVICE_GROUP_MAPPING_PREFIX.
|
||||
*/
|
||||
String SERVICE_GROUP_MAPPING_PREFIX = SERVICE_PREFIX + "vgroupMapping.";
|
||||
/**
|
||||
* The constant GROUPLIST_POSTFIX.
|
||||
*/
|
||||
String GROUPLIST_POSTFIX = ".grouplist";
|
||||
/**
|
||||
* The constant SERVER_NODE_SPLIT_CHAR.
|
||||
*/
|
||||
String SERVER_NODE_SPLIT_CHAR = System.getProperty("line.separator");
|
||||
|
||||
/**
|
||||
* The constant ENABLE_DEGRADE_POSTFIX.
|
||||
*/
|
||||
String ENABLE_DEGRADE_POSTFIX = "enableDegrade";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_PREFIX.
|
||||
*/
|
||||
String CLIENT_PREFIX = "client.";
|
||||
|
||||
/**
|
||||
* The constant SERVER_PREFIX.
|
||||
*/
|
||||
String SERVER_PREFIX = "server.";
|
||||
|
||||
/**
|
||||
* The constant TRANSPORT_PREFIX.
|
||||
*/
|
||||
String TRANSPORT_PREFIX = "transport.";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_RM_PREFIX.
|
||||
*/
|
||||
String CLIENT_RM_PREFIX = CLIENT_PREFIX + "rm.";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_ASYNC_COMMIT_BUFFER_LIMIT.
|
||||
*/
|
||||
String CLIENT_ASYNC_COMMIT_BUFFER_LIMIT = CLIENT_RM_PREFIX + "asyncCommitBufferLimit";
|
||||
/**
|
||||
* The constant CLIENT_RM_LOCK_PREFIX.
|
||||
*/
|
||||
String CLIENT_RM_LOCK_PREFIX = CLIENT_RM_PREFIX + "lock.";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_LOCK_RETRY_TIMES.
|
||||
*/
|
||||
String CLIENT_LOCK_RETRY_TIMES = CLIENT_RM_LOCK_PREFIX + "retryTimes";
|
||||
/**
|
||||
* The constant CLIENT_LOCK_RETRY_INTERVAL.
|
||||
*/
|
||||
String CLIENT_LOCK_RETRY_INTERVAL = CLIENT_RM_LOCK_PREFIX + "retryInterval";
|
||||
/**
|
||||
* The constant CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT.
|
||||
*/
|
||||
String CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT = CLIENT_RM_LOCK_PREFIX + "retryPolicyBranchRollbackOnConflict";
|
||||
|
||||
|
||||
/**
|
||||
* The constant SERVICE_SESSION_RELOAD_READ_SIZE
|
||||
*/
|
||||
String SERVICE_SESSION_RELOAD_READ_SIZE = STORE_FILE_PREFIX + "sessionReloadReadSize";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_REPORT_SUCCESS_ENABLE.
|
||||
*/
|
||||
String CLIENT_REPORT_SUCCESS_ENABLE = CLIENT_RM_PREFIX + "reportSuccessEnable";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SAGA_BRANCH_REGISTER_ENABLE.
|
||||
*/
|
||||
String CLIENT_SAGA_BRANCH_REGISTER_ENABLE = CLIENT_RM_PREFIX + "sagaBranchRegisterEnable";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SAGA_JSON_PARSER.
|
||||
*/
|
||||
String CLIENT_SAGA_JSON_PARSER = CLIENT_RM_PREFIX + "sagaJsonParser";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE.
|
||||
*/
|
||||
String CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE = CLIENT_RM_PREFIX + "sagaRetryPersistModeUpdate";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE.
|
||||
*/
|
||||
String CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE = CLIENT_RM_PREFIX + "sagaCompensatePersistModeUpdate";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_REPORT_RETRY_COUNT.
|
||||
*/
|
||||
String CLIENT_REPORT_RETRY_COUNT = CLIENT_RM_PREFIX + "reportRetryCount";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_TABLE_META_CHECK_ENABLE.
|
||||
*/
|
||||
String CLIENT_TABLE_META_CHECK_ENABLE = CLIENT_RM_PREFIX + "tableMetaCheckEnable";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_TABLE_META_CHECKER_INTERVAL.
|
||||
*/
|
||||
String CLIENT_TABLE_META_CHECKER_INTERVAL = CLIENT_RM_PREFIX + "tableMetaCheckerInterval";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_TM_PREFIX.
|
||||
*/
|
||||
String CLIENT_TM_PREFIX = CLIENT_PREFIX + "tm.";
|
||||
/**
|
||||
* The constant CLIENT_TM_COMMIT_RETRY_TIMES.
|
||||
*/
|
||||
String CLIENT_TM_COMMIT_RETRY_COUNT = CLIENT_TM_PREFIX + "commitRetryCount";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_TM_ROLLBACK_RETRY_TIMES.
|
||||
*/
|
||||
String CLIENT_TM_ROLLBACK_RETRY_COUNT = CLIENT_TM_PREFIX + "rollbackRetryCount";
|
||||
|
||||
/**
|
||||
* The constant DEFAULT_GLOBAL_TRANSACTION_TIMEOUT.
|
||||
*/
|
||||
String DEFAULT_GLOBAL_TRANSACTION_TIMEOUT = CLIENT_TM_PREFIX + "defaultGlobalTransactionTimeout";
|
||||
|
||||
/**
|
||||
* The constant SERIALIZE_FOR_RPC.
|
||||
*/
|
||||
String SERIALIZE_FOR_RPC = TRANSPORT_PREFIX + "serialization";
|
||||
|
||||
/**
|
||||
* The constant COMPRESSOR_FOR_RPC.
|
||||
*
|
||||
* @since 0.7.0
|
||||
*/
|
||||
String COMPRESSOR_FOR_RPC = TRANSPORT_PREFIX + "compressor";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_PREFIX.
|
||||
*/
|
||||
String STORE_DB_PREFIX = "store.db.";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_PREFIX.
|
||||
*/
|
||||
String STORE_REDIS_PREFIX = "store.redis.";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_GLOBAL_TABLE.
|
||||
*/
|
||||
String STORE_DB_GLOBAL_TABLE = STORE_DB_PREFIX + "globalTable";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_BRANCH_TABLE.
|
||||
*/
|
||||
String STORE_DB_BRANCH_TABLE = STORE_DB_PREFIX + "branchTable";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_DATASOURCE_TYPE.
|
||||
*/
|
||||
String STORE_DB_DATASOURCE_TYPE = STORE_DB_PREFIX + "datasource";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_TYPE.
|
||||
*/
|
||||
String STORE_DB_TYPE = STORE_DB_PREFIX + "dbType";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_DRIVER_CLASS_NAME.
|
||||
*/
|
||||
String STORE_DB_DRIVER_CLASS_NAME = STORE_DB_PREFIX + "driverClassName";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_MAX_WAIT.
|
||||
*/
|
||||
String STORE_DB_MAX_WAIT = STORE_DB_PREFIX + "maxWait";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_URL.
|
||||
*/
|
||||
String STORE_DB_URL = STORE_DB_PREFIX + "url";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_USER.
|
||||
*/
|
||||
String STORE_DB_USER = STORE_DB_PREFIX + "user";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_PASSWORD.
|
||||
*/
|
||||
String STORE_DB_PASSWORD = STORE_DB_PREFIX + "password";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_MIN_CONN.
|
||||
*/
|
||||
String STORE_DB_MIN_CONN = STORE_DB_PREFIX + "minConn";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_MAX_CONN.
|
||||
*/
|
||||
String STORE_DB_MAX_CONN = STORE_DB_PREFIX + "maxConn";
|
||||
|
||||
/**
|
||||
* The constant STORE_DB_LOG_QUERY_LIMIT.
|
||||
*/
|
||||
String STORE_DB_LOG_QUERY_LIMIT = STORE_DB_PREFIX + "queryLimit";
|
||||
|
||||
/**
|
||||
* The constant LOCK_DB_TABLE.
|
||||
*/
|
||||
String LOCK_DB_TABLE = STORE_DB_PREFIX + "lockTable";
|
||||
|
||||
/**
|
||||
* The constant SERVER_PORT.
|
||||
*/
|
||||
String SERVER_PORT = SERVER_PREFIX + "port";
|
||||
|
||||
/**
|
||||
* The constant RECOVERY_PREFIX.
|
||||
*/
|
||||
String RECOVERY_PREFIX = SERVER_PREFIX + "recovery.";
|
||||
/**
|
||||
* The constant COMMITING_RETRY_PERIOD.
|
||||
*/
|
||||
String COMMITING_RETRY_PERIOD = RECOVERY_PREFIX + "committingRetryPeriod";
|
||||
|
||||
/**
|
||||
* The constant ASYN_COMMITING_RETRY_PERIOD.
|
||||
*/
|
||||
String ASYN_COMMITING_RETRY_PERIOD = RECOVERY_PREFIX + "asynCommittingRetryPeriod";
|
||||
|
||||
/**
|
||||
* The constant ROLLBACKING_RETRY_PERIOD.
|
||||
*/
|
||||
String ROLLBACKING_RETRY_PERIOD = RECOVERY_PREFIX + "rollbackingRetryPeriod";
|
||||
|
||||
/**
|
||||
* The constant TIMEOUT_RETRY_PERIOD.
|
||||
*/
|
||||
String TIMEOUT_RETRY_PERIOD = RECOVERY_PREFIX + "timeoutRetryPeriod";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_UNDO_PREFIX.
|
||||
*/
|
||||
String CLIENT_UNDO_PREFIX = "client.undo.";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_DATA_VALIDATION.
|
||||
*/
|
||||
String TRANSACTION_UNDO_DATA_VALIDATION = CLIENT_UNDO_PREFIX + "dataValidation";
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_LOG_SERIALIZATION.
|
||||
*/
|
||||
String TRANSACTION_UNDO_LOG_SERIALIZATION = CLIENT_UNDO_PREFIX + "logSerialization";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_ONLY_CARE_UPDATE_COLUMNS.
|
||||
*/
|
||||
String TRANSACTION_UNDO_ONLY_CARE_UPDATE_COLUMNS = CLIENT_UNDO_PREFIX + "onlyCareUpdateColumns";
|
||||
|
||||
/**
|
||||
* the constant CLIENT_UNDO_COMPRESS_PREFIX
|
||||
*/
|
||||
String CLIENT_UNDO_COMPRESS_PREFIX = CLIENT_UNDO_PREFIX + "compress.";
|
||||
|
||||
/**
|
||||
* the constant CLIENT_UNDO_COMPRESS_TYPE
|
||||
*/
|
||||
String CLIENT_UNDO_COMPRESS_TYPE = CLIENT_UNDO_COMPRESS_PREFIX + "type";
|
||||
|
||||
/**
|
||||
* the constant CLIENT_UNDO_COMPRESS_ENABLE
|
||||
*/
|
||||
String CLIENT_UNDO_COMPRESS_ENABLE = CLIENT_UNDO_COMPRESS_PREFIX + "enable";
|
||||
|
||||
/**
|
||||
* the constant CLIENT_UNDO_COMPRESS_THRESHOLD
|
||||
*/
|
||||
String CLIENT_UNDO_COMPRESS_THRESHOLD = CLIENT_UNDO_COMPRESS_PREFIX + "threshold";
|
||||
|
||||
/**
|
||||
* The constant METRICS_PREFIX.
|
||||
*/
|
||||
String METRICS_PREFIX = "metrics.";
|
||||
|
||||
/**
|
||||
* The constant METRICS_ENABLED.
|
||||
*/
|
||||
String METRICS_ENABLED = "enabled";
|
||||
|
||||
/**
|
||||
* The constant METRICS_REGISTRY_TYPE.
|
||||
*/
|
||||
String METRICS_REGISTRY_TYPE = "registryType";
|
||||
|
||||
/**
|
||||
* The constant METRICS_EXPORTER_LIST.
|
||||
*/
|
||||
String METRICS_EXPORTER_LIST = "exporterList";
|
||||
/**
|
||||
* The constant METRICS_EXPORTER_PROMETHEUS_PORT
|
||||
*/
|
||||
String METRICS_EXPORTER_PROMETHEUS_PORT = "exporterPrometheusPort";
|
||||
|
||||
/**
|
||||
* The constant SERVER_UNDO_PREFIX.
|
||||
*/
|
||||
String SERVER_UNDO_PREFIX = SERVER_PREFIX + "undo.";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_LOG_SAVE_DAYS.
|
||||
*/
|
||||
String TRANSACTION_UNDO_LOG_SAVE_DAYS = SERVER_UNDO_PREFIX + "logSaveDays";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_LOG_DELETE_PERIOD
|
||||
*/
|
||||
String TRANSACTION_UNDO_LOG_DELETE_PERIOD = SERVER_UNDO_PREFIX + "logDeletePeriod";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_LOG_TABLE
|
||||
*/
|
||||
String TRANSACTION_UNDO_LOG_TABLE = CLIENT_UNDO_PREFIX + "logTable";
|
||||
/**
|
||||
* The constant LOG_PREFIX
|
||||
*/
|
||||
String LOG_PREFIX = "log.";
|
||||
|
||||
/**
|
||||
* The constant TRANSACTION_UNDO_LOG_EXCEPTION_RATE
|
||||
*/
|
||||
String TRANSACTION_LOG_EXCEPTION_RATE = LOG_PREFIX + "exceptionRate";
|
||||
|
||||
/**
|
||||
* The constant MAX_COMMIT_RETRY_TIMEOUT.
|
||||
*/
|
||||
String MAX_COMMIT_RETRY_TIMEOUT = SERVER_PREFIX + "maxCommitRetryTimeout";
|
||||
|
||||
/**
|
||||
* The constant MAX_ROLLBACK_RETRY_TIMEOUT.
|
||||
*/
|
||||
String MAX_ROLLBACK_RETRY_TIMEOUT = SERVER_PREFIX + "maxRollbackRetryTimeout";
|
||||
|
||||
/**
|
||||
* The constant ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE.
|
||||
*/
|
||||
String ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE = SERVER_PREFIX + "rollbackRetryTimeoutUnlockEnable";
|
||||
|
||||
/**
|
||||
* the constant RETRY_DEAD_THRESHOLD
|
||||
*/
|
||||
String RETRY_DEAD_THRESHOLD = SERVER_PREFIX + "retryDeadThreshold";
|
||||
|
||||
/**
|
||||
* The constant MIN_SERVER_POOL_SIZE.
|
||||
*/
|
||||
String MIN_SERVER_POOL_SIZE = TRANSPORT_PREFIX + "minServerPoolSize";
|
||||
|
||||
/**
|
||||
* The constant MAX_SERVER_POOL_SIZE.
|
||||
*/
|
||||
String MAX_SERVER_POOL_SIZE = TRANSPORT_PREFIX + "maxServerPoolSize";
|
||||
|
||||
/**
|
||||
* The constant MAX_TASK_QUEUE_SIZE.
|
||||
*/
|
||||
String MAX_TASK_QUEUE_SIZE = TRANSPORT_PREFIX + "maxTaskQueueSize";
|
||||
|
||||
/**
|
||||
* The constant KEEP_ALIVE_TIME.
|
||||
*/
|
||||
String KEEP_ALIVE_TIME = TRANSPORT_PREFIX + "keepAliveTime";
|
||||
|
||||
/**
|
||||
* The constant TRANSPORT_TYPE
|
||||
*/
|
||||
String TRANSPORT_TYPE = TRANSPORT_PREFIX + "type";
|
||||
|
||||
/**
|
||||
* The constant TRANSPORT_SERVER
|
||||
*/
|
||||
String TRANSPORT_SERVER = TRANSPORT_PREFIX + "server";
|
||||
|
||||
/**
|
||||
* The constant TRANSPORT_HEARTBEAT
|
||||
*/
|
||||
String TRANSPORT_HEARTBEAT = TRANSPORT_PREFIX + "heartbeat";
|
||||
|
||||
/**
|
||||
* The constant THREAD_FACTORY_PREFIX
|
||||
*/
|
||||
String THREAD_FACTORY_PREFIX = TRANSPORT_PREFIX + "threadFactory.";
|
||||
|
||||
/**
|
||||
* The constant BOSS_THREAD_PREFIX
|
||||
*/
|
||||
String BOSS_THREAD_PREFIX = THREAD_FACTORY_PREFIX + "bossThreadPrefix";
|
||||
|
||||
/**
|
||||
* The constant WORKER_THREAD_PREFIX
|
||||
*/
|
||||
String WORKER_THREAD_PREFIX = THREAD_FACTORY_PREFIX + "workerThreadPrefix";
|
||||
|
||||
/**
|
||||
* The constant SERVER_EXECUTOR_THREAD_PREFIX
|
||||
*/
|
||||
String SERVER_EXECUTOR_THREAD_PREFIX = THREAD_FACTORY_PREFIX + "serverExecutorThreadPrefix";
|
||||
|
||||
/**
|
||||
* The constant SHARE_BOSS_WORKER
|
||||
*/
|
||||
String SHARE_BOSS_WORKER = THREAD_FACTORY_PREFIX + "shareBossWorker";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SELECTOR_THREAD_PREFIX
|
||||
*/
|
||||
String CLIENT_SELECTOR_THREAD_PREFIX = THREAD_FACTORY_PREFIX + "clientSelectorThreadPrefix";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_SELECTOR_THREAD_SIZE
|
||||
*/
|
||||
String CLIENT_SELECTOR_THREAD_SIZE = THREAD_FACTORY_PREFIX + "clientSelectorThreadSize";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_WORKER_THREAD_PREFIX
|
||||
*/
|
||||
String CLIENT_WORKER_THREAD_PREFIX = THREAD_FACTORY_PREFIX + "clientWorkerThreadPrefix";
|
||||
|
||||
/**
|
||||
* The constant BOSS_THREAD_SIZE
|
||||
*/
|
||||
String BOSS_THREAD_SIZE = THREAD_FACTORY_PREFIX + "bossThreadSize";
|
||||
|
||||
/**
|
||||
* The constant WORKER_THREAD_SIZE
|
||||
*/
|
||||
String WORKER_THREAD_SIZE = THREAD_FACTORY_PREFIX + "workerThreadSize";
|
||||
|
||||
/**
|
||||
* The constant SHUTDOWN_PREFIX
|
||||
*/
|
||||
String SHUTDOWN_PREFIX = TRANSPORT_PREFIX + "shutdown.";
|
||||
|
||||
/**
|
||||
* The constant SHUTDOWN_WAIT
|
||||
*/
|
||||
String SHUTDOWN_WAIT = SHUTDOWN_PREFIX + "wait";
|
||||
|
||||
/**
|
||||
* The constant ENABLE_CLIENT_BATCH_SEND_REQUEST
|
||||
*/
|
||||
String ENABLE_CLIENT_BATCH_SEND_REQUEST = TRANSPORT_PREFIX + "enableClientBatchSendRequest";
|
||||
|
||||
/**
|
||||
* The constant DISABLE_GLOBAL_TRANSACTION.
|
||||
*/
|
||||
String DISABLE_GLOBAL_TRANSACTION = SERVICE_PREFIX + "disableGlobalTransaction";
|
||||
|
||||
/**
|
||||
* The constant SQL_PARSER_TYPE.
|
||||
*/
|
||||
String SQL_PARSER_TYPE = CLIENT_RM_PREFIX + "sqlParserType";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_MODE.
|
||||
*/
|
||||
String STORE_REDIS_MODE = STORE_REDIS_PREFIX + "mode";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_HOST.
|
||||
*/
|
||||
String STORE_REDIS_HOST = STORE_REDIS_PREFIX + "host";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_PORT.
|
||||
*/
|
||||
String STORE_REDIS_PORT = STORE_REDIS_PREFIX + "port";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_SINGLE_PREFIX.
|
||||
*/
|
||||
String STORE_REDIS_SINGLE_PREFIX = STORE_REDIS_PREFIX + "single.";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_SINGLE_HOST.
|
||||
*/
|
||||
String STORE_REDIS_SINGLE_HOST = STORE_REDIS_SINGLE_PREFIX + "host";
|
||||
|
||||
/**
|
||||
* The constant STORE_MIN_Conn.
|
||||
*/
|
||||
String STORE_REDIS_MIN_CONN = STORE_REDIS_PREFIX + "minConn";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_SINGLE_PORT.
|
||||
*/
|
||||
String STORE_REDIS_SINGLE_PORT = STORE_REDIS_SINGLE_PREFIX + "port";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_MAX_CONN.
|
||||
*/
|
||||
String STORE_REDIS_MAX_CONN = STORE_REDIS_PREFIX + "maxConn";
|
||||
|
||||
/**
|
||||
* the constant STORE_REDIS_MAX_TOTAL
|
||||
*/
|
||||
String STORE_REDIS_MAX_TOTAL = STORE_REDIS_PREFIX + "maxTotal";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_DATABASE.
|
||||
*/
|
||||
String STORE_REDIS_DATABASE = STORE_REDIS_PREFIX + "database";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_PASSWORD.
|
||||
*/
|
||||
String STORE_REDIS_PASSWORD = STORE_REDIS_PREFIX + "password";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_QUERY_LIMIT.
|
||||
*/
|
||||
String STORE_REDIS_QUERY_LIMIT = STORE_REDIS_PREFIX + "queryLimit";
|
||||
|
||||
/**
|
||||
* The constant REDIS_SENTINEL_MODE.
|
||||
*/
|
||||
String REDIS_SENTINEL_MODE = "sentinel";
|
||||
|
||||
/**
|
||||
* The constant REDIS_SINGLE_MODE.
|
||||
*/
|
||||
String REDIS_SINGLE_MODE = "single";
|
||||
|
||||
/**
|
||||
* The constant STORE_REDIS_SENTINEL_PREFIX.
|
||||
*/
|
||||
String STORE_REDIS_SENTINEL_PREFIX = STORE_REDIS_PREFIX + "sentinel.";
|
||||
|
||||
/**
|
||||
* STORE_REDIS_SENTINEL_MASTERNAME.
|
||||
*/
|
||||
String STORE_REDIS_SENTINEL_MASTERNAME = STORE_REDIS_SENTINEL_PREFIX + "masterName";
|
||||
|
||||
/**
|
||||
* STORE_REDIS_SENTINEL_HOST.
|
||||
*/
|
||||
String STORE_REDIS_SENTINEL_HOST = STORE_REDIS_SENTINEL_PREFIX + "sentinelHosts";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_DEGRADE_CHECK_PERIOD.
|
||||
*/
|
||||
String CLIENT_DEGRADE_CHECK_PERIOD = CLIENT_TM_PREFIX + "degradeCheckPeriod";
|
||||
|
||||
/**
|
||||
* The constant CLIENT_DEGRADE_CHECK.
|
||||
*/
|
||||
String CLIENT_DEGRADE_CHECK = CLIENT_TM_PREFIX + "degradeCheck";
|
||||
/**
|
||||
* The constant CLIENT_DEGRADE_CHECK_ALLOW_TIMES.
|
||||
*/
|
||||
String CLIENT_DEGRADE_CHECK_ALLOW_TIMES = CLIENT_TM_PREFIX + "degradeCheckAllowTimes";
|
||||
|
||||
/**
|
||||
* The constant SEATA_ACCESS_KEY.
|
||||
*/
|
||||
String SEATA_ACCESS_KEY = SEATA_PREFIX + "accesskey";
|
||||
|
||||
/**
|
||||
* The constant SEATA_SECRET_KEY.
|
||||
*/
|
||||
String SEATA_SECRET_KEY = SEATA_PREFIX + "secretkey";
|
||||
|
||||
/**
|
||||
* The constant EXTRA_DATA_SPLIT_CHAR.
|
||||
*/
|
||||
String EXTRA_DATA_SPLIT_CHAR = "\n";
|
||||
/**
|
||||
* The constant EXTRA_DATA_KV_CHAR.
|
||||
*/
|
||||
String EXTRA_DATA_KV_CHAR = "=";
|
||||
|
||||
/**
|
||||
* The constant SERVER_ENABLE_CHECK_AUTH.
|
||||
*/
|
||||
String SERVER_ENABLE_CHECK_AUTH = SERVER_PREFIX + "enableCheckAuth";
|
||||
|
||||
/**
|
||||
* The constant APPLICATION_ID.
|
||||
*/
|
||||
String APPLICATION_ID = "applicationId";
|
||||
|
||||
/**
|
||||
* The constant TX_SERVICE_GROUP.
|
||||
*/
|
||||
String TX_SERVICE_GROUP = "txServiceGroup";
|
||||
|
||||
/**
|
||||
* The constant DATA_SOURCE_PROXY_MODE.
|
||||
*/
|
||||
String DATA_SOURCE_PROXY_MODE = "dataSourceProxyMode";
|
||||
}
|
||||
92
core/src/main/java/io/seata/core/constants/DBType.java
Normal file
92
core/src/main/java/io/seata/core/constants/DBType.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
import io.seata.common.util.StringUtils;
|
||||
|
||||
/**
|
||||
* database type
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public enum DBType {
|
||||
|
||||
/**
|
||||
* Mysql db type.
|
||||
*/
|
||||
MYSQL,
|
||||
|
||||
/**
|
||||
* Oracle db type.
|
||||
*/
|
||||
ORACLE,
|
||||
|
||||
/**
|
||||
* Db 2 db type.
|
||||
*/
|
||||
DB2,
|
||||
|
||||
/**
|
||||
* Sqlserver db type.
|
||||
*/
|
||||
SQLSERVER,
|
||||
|
||||
/**
|
||||
* Sybaee db type.
|
||||
*/
|
||||
SYBAEE,
|
||||
|
||||
/**
|
||||
* H2 db type.
|
||||
*/
|
||||
H2,
|
||||
|
||||
/**
|
||||
* Sqlite db type.
|
||||
*/
|
||||
SQLITE,
|
||||
|
||||
/**
|
||||
* Access db type.
|
||||
*/
|
||||
ACCESS,
|
||||
|
||||
/**
|
||||
* Postgresql db type.
|
||||
*/
|
||||
POSTGRESQL,
|
||||
|
||||
/**
|
||||
* Oceanbase db type.
|
||||
*/
|
||||
OCEANBASE;
|
||||
|
||||
/**
|
||||
* Valueof db type.
|
||||
*
|
||||
* @param dbType the db type
|
||||
* @return the db type
|
||||
*/
|
||||
public static DBType valueof(String dbType) {
|
||||
for (DBType dt : values()) {
|
||||
if (StringUtils.equalsIgnoreCase(dt.name(), dbType)) {
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown dbtype:" + dbType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
/**
|
||||
* DubboConstants
|
||||
*
|
||||
* @author funkye
|
||||
*/
|
||||
public class DubboConstants {
|
||||
|
||||
public static final String PROVIDER = "provider";
|
||||
|
||||
public static final String CONSUMER = "consumer";
|
||||
|
||||
public static boolean ALIBABADUBBO;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.apache.dubbo.rpc.RpcContext");
|
||||
} catch (ClassNotFoundException e) {
|
||||
ALIBABADUBBO = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
/**
|
||||
* The redis key constants
|
||||
*
|
||||
* @author wangzhongxiang
|
||||
*/
|
||||
public class RedisKeyConstants {
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name xid
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name transactionId
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_TRANSACTION_ID = "transactionId";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name status
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name applicationId
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_APPLICATION_ID = "applicationId";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name transactionServiceGroup
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_TRANSACTION_SERVICE_GROUP = "transactionServiceGroup";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name transactionName
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_TRANSACTION_NAME = "transactionName";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name timeout
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_TIMEOUT = "timeout";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name beginTime
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_BEGIN_TIME = "beginTime";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name applicationData
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_APPLICATION_DATA = "applicationData";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name gmtCreate
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_GMT_CREATE = "gmtCreate";
|
||||
|
||||
/**
|
||||
* The constant redis key of global transaction name gmtModified
|
||||
*/
|
||||
public static final String REDIS_KEY_GLOBAL_GMT_MODIFIED = "gmtModified";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name branchId
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_BRANCH_ID = "branchId";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name xid
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name transactionId
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_TRANSACTION_ID = "transactionId";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name resourceGroupId
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_RESOURCE_GROUP_ID = "resourceGroupId";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name resourceId
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_RESOURCE_ID = "resourceId";
|
||||
|
||||
/**REDIS_
|
||||
* The constant redis key of branch transaction name branchType
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_BRANCH_TYPE = "branchType";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name status
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name beginTime
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_BEGIN_TIME = "beginTime";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name applicationData
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_APPLICATION_DATA = "applicationData";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name clientId
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_CLIENT_ID = "clientId";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name gmtCreate
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_GMT_CREATE = "gmtCreate";
|
||||
|
||||
/**
|
||||
* The constant redis key of branch transaction name gmtModified
|
||||
*/
|
||||
public static final String REDIS_KEY_BRANCH_GMT_MODIFIED = "gmtModified";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.constants;
|
||||
|
||||
/**
|
||||
* server table columns name.
|
||||
*
|
||||
* @author zjinlei
|
||||
*/
|
||||
public interface ServerTableColumnsName {
|
||||
|
||||
/**
|
||||
* The constant global_table column name xid
|
||||
*/
|
||||
String GLOBAL_TABLE_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant global_table column name transaction_id
|
||||
*/
|
||||
String GLOBAL_TABLE_TRANSACTION_ID = "transaction_id";
|
||||
|
||||
/**
|
||||
* The constant global_table column name status
|
||||
*/
|
||||
String GLOBAL_TABLE_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The constant global_table column name application_id
|
||||
*/
|
||||
String GLOBAL_TABLE_APPLICATION_ID = "application_id";
|
||||
|
||||
/**
|
||||
* The constant global_table column name transaction_service_group
|
||||
*/
|
||||
String GLOBAL_TABLE_TRANSACTION_SERVICE_GROUP = "transaction_service_group";
|
||||
|
||||
/**
|
||||
* The constant global_table column name transaction_name
|
||||
*/
|
||||
String GLOBAL_TABLE_TRANSACTION_NAME = "transaction_name";
|
||||
|
||||
/**
|
||||
* The constant global_table column name timeout
|
||||
*/
|
||||
String GLOBAL_TABLE_TIMEOUT = "timeout";
|
||||
|
||||
/**
|
||||
* The constant global_table column name begin_time
|
||||
*/
|
||||
String GLOBAL_TABLE_BEGIN_TIME = "begin_time";
|
||||
|
||||
/**
|
||||
* The constant global_table column name application_data
|
||||
*/
|
||||
String GLOBAL_TABLE_APPLICATION_DATA = "application_data";
|
||||
|
||||
/**
|
||||
* The constant global_table column name gmt_create
|
||||
*/
|
||||
String GLOBAL_TABLE_GMT_CREATE = "gmt_create";
|
||||
|
||||
/**
|
||||
* The constant global_table column name gmt_modified
|
||||
*/
|
||||
String GLOBAL_TABLE_GMT_MODIFIED = "gmt_modified";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The constant branch_table column name branch_id
|
||||
*/
|
||||
String BRANCH_TABLE_BRANCH_ID = "branch_id";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name xid
|
||||
*/
|
||||
String BRANCH_TABLE_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name transaction_id
|
||||
*/
|
||||
String BRANCH_TABLE_TRANSACTION_ID = "transaction_id";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name resource_group_id
|
||||
*/
|
||||
String BRANCH_TABLE_RESOURCE_GROUP_ID = "resource_group_id";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name resource_id
|
||||
*/
|
||||
String BRANCH_TABLE_RESOURCE_ID = "resource_id";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name branch_type
|
||||
*/
|
||||
String BRANCH_TABLE_BRANCH_TYPE = "branch_type";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name status
|
||||
*/
|
||||
String BRANCH_TABLE_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name begin_time
|
||||
*/
|
||||
String BRANCH_TABLE_BEGIN_TIME = "begin_time";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name application_data
|
||||
*/
|
||||
String BRANCH_TABLE_APPLICATION_DATA = "application_data";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name client_id
|
||||
*/
|
||||
String BRANCH_TABLE_CLIENT_ID = "client_id";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name gmt_create
|
||||
*/
|
||||
String BRANCH_TABLE_GMT_CREATE = "gmt_create";
|
||||
|
||||
/**
|
||||
* The constant branch_table column name gmt_modified
|
||||
*/
|
||||
String BRANCH_TABLE_GMT_MODIFIED = "gmt_modified";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The constant lock_table column name row_key
|
||||
*/
|
||||
String LOCK_TABLE_ROW_KEY = "row_key";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name xid
|
||||
*/
|
||||
String LOCK_TABLE_XID = "xid";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name transaction_id
|
||||
*/
|
||||
String LOCK_TABLE_TRANSACTION_ID = "transaction_id";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name branch_id
|
||||
*/
|
||||
String LOCK_TABLE_BRANCH_ID = "branch_id";
|
||||
|
||||
|
||||
/**
|
||||
* The constant lock_table column name resource_id
|
||||
*/
|
||||
String LOCK_TABLE_RESOURCE_ID = "resource_id";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name table_name
|
||||
*/
|
||||
String LOCK_TABLE_TABLE_NAME = "table_name";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name pk
|
||||
*/
|
||||
String LOCK_TABLE_PK = "pk";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name gmt_create
|
||||
*/
|
||||
String LOCK_TABLE_GMT_CREATE = "gmt_create";
|
||||
|
||||
/**
|
||||
* The constant lock_table column name gmt_modified
|
||||
*/
|
||||
String LOCK_TABLE_GMT_MODIFIED = "gmt_modified";
|
||||
}
|
||||
62
core/src/main/java/io/seata/core/context/ContextCore.java
Normal file
62
core/src/main/java/io/seata/core/context/ContextCore.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The interface Context core.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface ContextCore {
|
||||
|
||||
/**
|
||||
* Put value.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return the previous value associated with the key, or null if there was no mapping for the key
|
||||
*/
|
||||
@Nullable
|
||||
Object put(String key, Object value);
|
||||
|
||||
/**
|
||||
* Get value.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the value
|
||||
*/
|
||||
@Nullable
|
||||
Object get(String key);
|
||||
|
||||
/**
|
||||
* Remove value.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the removed value or null
|
||||
*/
|
||||
@Nullable
|
||||
Object remove(String key);
|
||||
|
||||
/**
|
||||
* entries
|
||||
*
|
||||
* @return the key-value map
|
||||
*/
|
||||
Map<String, Object> entries();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import io.seata.common.loader.EnhancedServiceLoader;
|
||||
|
||||
/**
|
||||
* The type Context core loader.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class ContextCoreLoader {
|
||||
|
||||
private ContextCoreLoader() {
|
||||
|
||||
}
|
||||
|
||||
private static class ContextCoreHolder {
|
||||
private static final ContextCore INSTANCE = Optional.ofNullable(EnhancedServiceLoader.load(ContextCore.class)).orElse(new ThreadLocalContextCore());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load context core.
|
||||
*
|
||||
* @return the context core
|
||||
*/
|
||||
public static ContextCore load() {
|
||||
return ContextCoreHolder.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import io.netty.util.concurrent.FastThreadLocal;
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Fast Thread local context core.
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
@LoadLevel(name = "FastThreadLocalContextCore", order = Integer.MIN_VALUE + 1)
|
||||
public class FastThreadLocalContextCore implements ContextCore {
|
||||
|
||||
private FastThreadLocal<Map<String, Object>> fastThreadLocal = new FastThreadLocal<Map<String, Object>>() {
|
||||
@Override
|
||||
protected Map<String, Object> initialValue() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
return fastThreadLocal.get().put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return fastThreadLocal.get().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(String key) {
|
||||
return fastThreadLocal.get().remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> entries() {
|
||||
return fastThreadLocal.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import io.seata.core.model.GlobalLockConfig;
|
||||
|
||||
/** use this class to access current GlobalLockConfig from anywhere
|
||||
* @author selfishlover
|
||||
*/
|
||||
public class GlobalLockConfigHolder {
|
||||
|
||||
private static ThreadLocal<GlobalLockConfig> holder = new ThreadLocal<>();
|
||||
|
||||
public static GlobalLockConfig getCurrentGlobalLockConfig() {
|
||||
return holder.get();
|
||||
}
|
||||
|
||||
public static GlobalLockConfig setAndReturnPrevious(GlobalLockConfig config) {
|
||||
GlobalLockConfig previous = holder.get();
|
||||
holder.set(config);
|
||||
return previous;
|
||||
}
|
||||
|
||||
public static void remove() {
|
||||
holder.remove();
|
||||
}
|
||||
}
|
||||
255
core/src/main/java/io/seata/core/context/RootContext.java
Normal file
255
core/src/main/java/io/seata/core/context/RootContext.java
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
import io.seata.common.util.StringUtils;
|
||||
import io.seata.core.model.BranchType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import static io.seata.core.model.BranchType.AT;
|
||||
import static io.seata.core.model.BranchType.XA;
|
||||
|
||||
/**
|
||||
* The type Root context.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RootContext {
|
||||
|
||||
private RootContext() {
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RootContext.class);
|
||||
|
||||
/**
|
||||
* The constant KEY_XID.
|
||||
*/
|
||||
public static final String KEY_XID = "TX_XID";
|
||||
|
||||
/**
|
||||
* The constant MDC_KEY_XID for logback
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static final String MDC_KEY_XID = "X-TX-XID";
|
||||
|
||||
/**
|
||||
* The constant MDC_KEY_BRANCH_ID for logback
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static final String MDC_KEY_BRANCH_ID = "X-TX-BRANCH-ID";
|
||||
|
||||
/**
|
||||
* The constant KEY_BRANCH_TYPE
|
||||
*/
|
||||
public static final String KEY_BRANCH_TYPE = "TX_BRANCH_TYPE";
|
||||
|
||||
/**
|
||||
* The constant KEY_GLOBAL_LOCK_FLAG, VALUE_GLOBAL_LOCK_FLAG
|
||||
*/
|
||||
public static final String KEY_GLOBAL_LOCK_FLAG = "TX_LOCK";
|
||||
public static final Boolean VALUE_GLOBAL_LOCK_FLAG = true;
|
||||
|
||||
private static ContextCore CONTEXT_HOLDER = ContextCoreLoader.load();
|
||||
|
||||
private static BranchType DEFAULT_BRANCH_TYPE;
|
||||
|
||||
public static void setDefaultBranchType(BranchType defaultBranchType) {
|
||||
if (defaultBranchType != AT && defaultBranchType != XA) {
|
||||
throw new IllegalArgumentException("The default branch type must be " + AT + " or " + XA + "." +
|
||||
" the value of the argument is: " + defaultBranchType);
|
||||
}
|
||||
if (DEFAULT_BRANCH_TYPE != null && DEFAULT_BRANCH_TYPE != defaultBranchType && LOGGER.isWarnEnabled()) {
|
||||
LOGGER.warn("The `{}.DEFAULT_BRANCH_TYPE` has been set repeatedly. The value changes from {} to {}",
|
||||
RootContext.class.getSimpleName(), DEFAULT_BRANCH_TYPE, defaultBranchType);
|
||||
}
|
||||
DEFAULT_BRANCH_TYPE = defaultBranchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
@Nullable
|
||||
public static String getXID() {
|
||||
return (String) CONTEXT_HOLDER.get(KEY_XID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public static void bind(@Nonnull String xid) {
|
||||
if (StringUtils.isBlank(xid)) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("xid is blank, switch to unbind operation!");
|
||||
}
|
||||
unbind();
|
||||
} else {
|
||||
MDC.put(MDC_KEY_XID, xid);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("bind {}", xid);
|
||||
}
|
||||
CONTEXT_HOLDER.put(KEY_XID, xid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* declare local transactions will use global lock check for update/delete/insert/selectForUpdate SQL
|
||||
*/
|
||||
public static void bindGlobalLockFlag() {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Local Transaction Global Lock support enabled");
|
||||
}
|
||||
|
||||
//just put something not null
|
||||
CONTEXT_HOLDER.put(KEY_GLOBAL_LOCK_FLAG, VALUE_GLOBAL_LOCK_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind xid.
|
||||
*
|
||||
* @return the previous xid or null
|
||||
*/
|
||||
@Nullable
|
||||
public static String unbind() {
|
||||
String xid = (String) CONTEXT_HOLDER.remove(KEY_XID);
|
||||
if (xid != null) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("unbind {} ", xid);
|
||||
}
|
||||
MDC.remove(MDC_KEY_XID);
|
||||
}
|
||||
return xid;
|
||||
}
|
||||
|
||||
public static void unbindGlobalLockFlag() {
|
||||
Boolean lockFlag = (Boolean) CONTEXT_HOLDER.remove(KEY_GLOBAL_LOCK_FLAG);
|
||||
if (LOGGER.isDebugEnabled() && lockFlag != null) {
|
||||
LOGGER.debug("unbind global lock flag");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In global transaction boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean inGlobalTransaction() {
|
||||
return CONTEXT_HOLDER.get(KEY_XID) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* In tcc branch boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean inTccBranch() {
|
||||
return BranchType.TCC == getBranchType();
|
||||
}
|
||||
|
||||
/**
|
||||
* In saga branch boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean inSagaBranch() {
|
||||
return BranchType.SAGA == getBranchType();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the branch type
|
||||
*
|
||||
* @return the branch type String
|
||||
*/
|
||||
@Nullable
|
||||
public static BranchType getBranchType() {
|
||||
if (inGlobalTransaction()) {
|
||||
BranchType branchType = (BranchType) CONTEXT_HOLDER.get(KEY_BRANCH_TYPE);
|
||||
if (branchType != null) {
|
||||
return branchType;
|
||||
}
|
||||
//Returns the default branch type.
|
||||
return DEFAULT_BRANCH_TYPE != null ? DEFAULT_BRANCH_TYPE : BranchType.AT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* bind branch type
|
||||
*
|
||||
* @param branchType the branch type
|
||||
*/
|
||||
public static void bindBranchType(@Nonnull BranchType branchType) {
|
||||
if (branchType == null) {
|
||||
throw new IllegalArgumentException("branchType must be not null");
|
||||
}
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("bind branch type {}", branchType);
|
||||
}
|
||||
|
||||
CONTEXT_HOLDER.put(KEY_BRANCH_TYPE, branchType);
|
||||
}
|
||||
|
||||
/**
|
||||
* unbind branch type
|
||||
*
|
||||
* @return the previous branch type or null
|
||||
*/
|
||||
@Nullable
|
||||
public static BranchType unbindBranchType() {
|
||||
BranchType unbindBranchType = (BranchType) CONTEXT_HOLDER.remove(KEY_BRANCH_TYPE);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("unbind branch type {}", unbindBranchType);
|
||||
}
|
||||
return unbindBranchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* requires global lock check
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean requireGlobalLock() {
|
||||
return CONTEXT_HOLDER.get(KEY_GLOBAL_LOCK_FLAG) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert not in global transaction.
|
||||
*/
|
||||
public static void assertNotInGlobalTransaction() {
|
||||
if (inGlobalTransaction()) {
|
||||
throw new ShouldNeverHappenException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* entry map
|
||||
*
|
||||
* @return the key-value map
|
||||
*/
|
||||
public static Map<String, Object> entries() {
|
||||
return CONTEXT_HOLDER.entries();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
|
||||
/**
|
||||
* The type Thread local context core.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
@LoadLevel(name = "ThreadLocalContextCore", order = Integer.MIN_VALUE)
|
||||
public class ThreadLocalContextCore implements ContextCore {
|
||||
|
||||
private ThreadLocal<Map<String, Object>> threadLocal = ThreadLocal.withInitial(HashMap::new);
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
return threadLocal.get().put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return threadLocal.get().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(String key) {
|
||||
return threadLocal.get().remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> entries() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
}
|
||||
24
core/src/main/java/io/seata/core/event/Event.java
Normal file
24
core/src/main/java/io/seata/core/event/Event.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.event;
|
||||
|
||||
/**
|
||||
* The base interface for seata event.
|
||||
*
|
||||
* @author zhengyangyong
|
||||
*/
|
||||
public interface Event {
|
||||
}
|
||||
29
core/src/main/java/io/seata/core/event/EventBus.java
Normal file
29
core/src/main/java/io/seata/core/event/EventBus.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.event;
|
||||
|
||||
/**
|
||||
* The interface for event bus.
|
||||
*
|
||||
* @author zhengyangyong
|
||||
*/
|
||||
public interface EventBus {
|
||||
void register(Object subscriber);
|
||||
|
||||
void unregister(Object subscriber);
|
||||
|
||||
void post(Event event);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.event;
|
||||
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
|
||||
/**
|
||||
* Event data for global transaction.
|
||||
*
|
||||
* @author zhengyangyong
|
||||
*/
|
||||
public class GlobalTransactionEvent implements Event {
|
||||
public static final String ROLE_TC = "tc";
|
||||
|
||||
public static final String ROLE_TM = "tm";
|
||||
|
||||
public static final String ROLE_RM = "rm";
|
||||
|
||||
/**
|
||||
* Transaction Id
|
||||
*/
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* Source Role
|
||||
*/
|
||||
private final String role;
|
||||
|
||||
/**
|
||||
* Transaction Name
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* business applicationId
|
||||
*/
|
||||
private String applicationId;
|
||||
|
||||
/**
|
||||
* Transaction Service Group
|
||||
*/
|
||||
private String group;
|
||||
|
||||
/**
|
||||
* Transaction Begin Time
|
||||
*/
|
||||
private final Long beginTime;
|
||||
|
||||
/**
|
||||
* Transaction End Time (If Transaction do not committed or rollbacked, null)
|
||||
*/
|
||||
private final Long endTime;
|
||||
|
||||
/**
|
||||
* Transaction Status
|
||||
*/
|
||||
private final GlobalStatus status;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public Long getBeginTime() {
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
public Long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public GlobalStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public GlobalTransactionEvent(long id, String role, String name, String applicationId,
|
||||
String group, Long beginTime, Long endTime, GlobalStatus status) {
|
||||
this.id = id;
|
||||
this.role = role;
|
||||
this.name = name;
|
||||
this.applicationId = applicationId;
|
||||
this.group = group;
|
||||
this.beginTime = beginTime;
|
||||
this.endTime = endTime;
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
67
core/src/main/java/io/seata/core/event/GuavaEventBus.java
Normal file
67
core/src/main/java/io/seata/core/event/GuavaEventBus.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.event;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.seata.common.thread.NamedThreadFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Default event bus implement with Guava EventBus.
|
||||
*
|
||||
* @author zhengyangyong
|
||||
*/
|
||||
public class GuavaEventBus implements EventBus {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GuavaEventBus.class);
|
||||
private final com.google.common.eventbus.EventBus eventBus;
|
||||
|
||||
public GuavaEventBus(String identifier) {
|
||||
this(identifier, false);
|
||||
}
|
||||
|
||||
public GuavaEventBus(String identifier, boolean async) {
|
||||
if (!async) {
|
||||
this.eventBus = new com.google.common.eventbus.EventBus(identifier);
|
||||
} else {
|
||||
final ExecutorService eventExecutor = new ThreadPoolExecutor(1, 1, Integer.MAX_VALUE, TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>(2048), new NamedThreadFactory(identifier, 1), (r, executor) -> {
|
||||
|
||||
LOGGER.warn("eventBus executor queue is full, size:{}", executor.getQueue().size());
|
||||
});
|
||||
this.eventBus = new com.google.common.eventbus.AsyncEventBus(identifier, eventExecutor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Object subscriber) {
|
||||
this.eventBus.register(subscriber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Object subscriber) {
|
||||
this.eventBus.unregister(subscriber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void post(Event event) {
|
||||
this.eventBus.post(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
import io.seata.config.Configuration;
|
||||
import io.seata.config.ConfigurationFactory;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.AbstractTransactionRequest;
|
||||
import io.seata.core.protocol.transaction.AbstractTransactionResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The type Abstract exception handler.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractExceptionHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* The constant CONFIG.
|
||||
*/
|
||||
protected static final Configuration CONFIG = ConfigurationFactory.getInstance();
|
||||
|
||||
/**
|
||||
* The interface Callback.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param <S> the type parameter
|
||||
*/
|
||||
public interface Callback<T extends AbstractTransactionRequest, S extends AbstractTransactionResponse> {
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @throws TransactionException the transaction exception
|
||||
*/
|
||||
void execute(T request, S response) throws TransactionException;
|
||||
|
||||
/**
|
||||
* On success.
|
||||
*
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
*/
|
||||
void onSuccess(T request, S response);
|
||||
|
||||
/**
|
||||
* onTransactionException
|
||||
*
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @param exception the exception
|
||||
*/
|
||||
void onTransactionException(T request, S response, TransactionException exception);
|
||||
|
||||
/**
|
||||
* on other exception
|
||||
*
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
* @param exception the exception
|
||||
*/
|
||||
void onException(T request, S response, Exception exception);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The type Abstract callback.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param <S> the type parameter
|
||||
*/
|
||||
public abstract static class AbstractCallback<T extends AbstractTransactionRequest, S extends AbstractTransactionResponse>
|
||||
implements Callback<T, S> {
|
||||
|
||||
@Override
|
||||
public void onSuccess(T request, S response) {
|
||||
response.setResultCode(ResultCode.Success);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionException(T request, S response,
|
||||
TransactionException tex) {
|
||||
response.setTransactionExceptionCode(tex.getCode());
|
||||
response.setResultCode(ResultCode.Failed);
|
||||
response.setMsg("TransactionException[" + tex.getMessage() + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(T request, S response, Exception rex) {
|
||||
response.setResultCode(ResultCode.Failed);
|
||||
response.setMsg("RuntimeException[" + rex.getMessage() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception handle template.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param <S> the type parameter
|
||||
* @param callback the callback
|
||||
* @param request the request
|
||||
* @param response the response
|
||||
*/
|
||||
public <T extends AbstractTransactionRequest, S extends AbstractTransactionResponse> void exceptionHandleTemplate(Callback<T, S> callback, T request, S response) {
|
||||
try {
|
||||
callback.execute(request, response);
|
||||
callback.onSuccess(request, response);
|
||||
} catch (TransactionException tex) {
|
||||
LOGGER.error("Catch TransactionException while do RPC, request: {}", request, tex);
|
||||
callback.onTransactionException(request, response, tex);
|
||||
} catch (RuntimeException rex) {
|
||||
LOGGER.error("Catch RuntimeException while do RPC, request: {}", request, rex);
|
||||
callback.onException(request, response, rex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The type BranchTransaction exception.
|
||||
*
|
||||
* @author will
|
||||
*/
|
||||
public class BranchTransactionException extends TransactionException {
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
*/
|
||||
public BranchTransactionException(TransactionExceptionCode code) {
|
||||
super(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param cause the cause
|
||||
*/
|
||||
public BranchTransactionException(TransactionExceptionCode code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public BranchTransactionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
*/
|
||||
public BranchTransactionException(TransactionExceptionCode code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public BranchTransactionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public BranchTransactionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public BranchTransactionException(TransactionExceptionCode code, String message, Throwable cause) {
|
||||
super(code, message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The type GlobalTransaction exception.
|
||||
*
|
||||
* @author will
|
||||
*/
|
||||
public class GlobalTransactionException extends TransactionException {
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
*/
|
||||
public GlobalTransactionException(TransactionExceptionCode code) {
|
||||
super(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param cause the cause
|
||||
*/
|
||||
public GlobalTransactionException(TransactionExceptionCode code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public GlobalTransactionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
*/
|
||||
public GlobalTransactionException(TransactionExceptionCode code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public GlobalTransactionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public GlobalTransactionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public GlobalTransactionException(TransactionExceptionCode code, String message, Throwable cause) {
|
||||
super(code, message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The type RmTransaction exception.
|
||||
*
|
||||
* @author will
|
||||
*/
|
||||
public class RmTransactionException extends BranchTransactionException {
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
*/
|
||||
public RmTransactionException(TransactionExceptionCode code) {
|
||||
super(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param cause the cause
|
||||
*/
|
||||
public RmTransactionException(TransactionExceptionCode code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public RmTransactionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
*/
|
||||
public RmTransactionException(TransactionExceptionCode code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public RmTransactionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public RmTransactionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public RmTransactionException(TransactionExceptionCode code, String message, Throwable cause) {
|
||||
super(code, message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The type TmTransaction exception.
|
||||
*
|
||||
* @author will
|
||||
*/
|
||||
public class TmTransactionException extends GlobalTransactionException {
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
*/
|
||||
public TmTransactionException(TransactionExceptionCode code) {
|
||||
super(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TmTransactionException(TransactionExceptionCode code, Throwable cause) {
|
||||
super(code, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public TmTransactionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
*/
|
||||
public TmTransactionException(TransactionExceptionCode code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TmTransactionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TmTransactionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TmTransactionException(TransactionExceptionCode code, String message, Throwable cause) {
|
||||
super(code, message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The type Transaction exception.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class TransactionException extends Exception {
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
protected TransactionExceptionCode code = TransactionExceptionCode.Unknown;
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public TransactionExceptionCode getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
*/
|
||||
public TransactionException(TransactionExceptionCode code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TransactionException(TransactionExceptionCode code, Throwable cause) {
|
||||
super(cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public TransactionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
*/
|
||||
public TransactionException(TransactionExceptionCode code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TransactionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TransactionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Transaction exception.
|
||||
*
|
||||
* @param code the code
|
||||
* @param message the message
|
||||
* @param cause the cause
|
||||
*/
|
||||
public TransactionException(TransactionExceptionCode code, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.exception;
|
||||
|
||||
/**
|
||||
* The enum Transaction exception code.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public enum TransactionExceptionCode {
|
||||
|
||||
/**
|
||||
* Unknown transaction exception code.
|
||||
*/
|
||||
Unknown,
|
||||
|
||||
/**
|
||||
* BeginFailed
|
||||
*/
|
||||
BeginFailed,
|
||||
|
||||
/**
|
||||
* Lock key conflict transaction exception code.
|
||||
*/
|
||||
LockKeyConflict,
|
||||
|
||||
/**
|
||||
* Io transaction exception code.
|
||||
*/
|
||||
IO,
|
||||
|
||||
/**
|
||||
* Branch rollback failed retriable transaction exception code.
|
||||
*/
|
||||
BranchRollbackFailed_Retriable,
|
||||
|
||||
/**
|
||||
* Branch rollback failed unretriable transaction exception code.
|
||||
*/
|
||||
BranchRollbackFailed_Unretriable,
|
||||
|
||||
/**
|
||||
* Branch register failed transaction exception code.
|
||||
*/
|
||||
BranchRegisterFailed,
|
||||
|
||||
/**
|
||||
* Branch report failed transaction exception code.
|
||||
*/
|
||||
BranchReportFailed,
|
||||
|
||||
/**
|
||||
* Lockable check failed transaction exception code.
|
||||
*/
|
||||
LockableCheckFailed,
|
||||
|
||||
/**
|
||||
* Branch transaction not exist transaction exception code.
|
||||
*/
|
||||
BranchTransactionNotExist,
|
||||
|
||||
/**
|
||||
* Global transaction not exist transaction exception code.
|
||||
*/
|
||||
GlobalTransactionNotExist,
|
||||
|
||||
/**
|
||||
* Global transaction not active transaction exception code.
|
||||
*/
|
||||
GlobalTransactionNotActive,
|
||||
|
||||
/**
|
||||
* Global transaction status invalid transaction exception code.
|
||||
*/
|
||||
GlobalTransactionStatusInvalid,
|
||||
|
||||
/**
|
||||
* Failed to send branch commit request transaction exception code.
|
||||
*/
|
||||
FailedToSendBranchCommitRequest,
|
||||
|
||||
/**
|
||||
* Failed to send branch rollback request transaction exception code.
|
||||
*/
|
||||
FailedToSendBranchRollbackRequest,
|
||||
|
||||
/**
|
||||
* Failed to add branch transaction exception code.
|
||||
*/
|
||||
FailedToAddBranch,
|
||||
|
||||
/**
|
||||
* Failed to lock global transaction exception code.
|
||||
*/
|
||||
FailedLockGlobalTranscation,
|
||||
|
||||
/**
|
||||
* FailedWriteSession
|
||||
*/
|
||||
FailedWriteSession,
|
||||
|
||||
/**
|
||||
* Failed to store exception code
|
||||
*/
|
||||
FailedStore
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* Get transaction exception code.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the transaction exception code
|
||||
*/
|
||||
public static TransactionExceptionCode get(byte ordinal) {
|
||||
return get((int)ordinal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction exception code.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the transaction exception code
|
||||
*/
|
||||
public static TransactionExceptionCode get(int ordinal) {
|
||||
TransactionExceptionCode value = null;
|
||||
try {
|
||||
value = TransactionExceptionCode.values()[ordinal];
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Unknown TransactionExceptionCode[" + ordinal + "]");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
96
core/src/main/java/io/seata/core/lock/AbstractLocker.java
Normal file
96
core/src/main/java/io/seata/core/lock/AbstractLocker.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.lock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.seata.common.util.CollectionUtils;
|
||||
import io.seata.core.store.LockDO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The type Abstract locker.
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public abstract class AbstractLocker implements Locker {
|
||||
|
||||
/**
|
||||
* The constant LOGGER.
|
||||
*/
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractLocker.class);
|
||||
|
||||
/**
|
||||
* The constant LOCK_SPLIT.
|
||||
*/
|
||||
protected static final String LOCK_SPLIT = "^^^";
|
||||
|
||||
/**
|
||||
* Convert to lock do list.
|
||||
*
|
||||
* @param locks the locks
|
||||
* @return the list
|
||||
*/
|
||||
protected List<LockDO> convertToLockDO(List<RowLock> locks) {
|
||||
List<LockDO> lockDOs = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(locks)) {
|
||||
return lockDOs;
|
||||
}
|
||||
for (RowLock rowLock : locks) {
|
||||
LockDO lockDO = new LockDO();
|
||||
lockDO.setBranchId(rowLock.getBranchId());
|
||||
lockDO.setPk(rowLock.getPk());
|
||||
lockDO.setResourceId(rowLock.getResourceId());
|
||||
lockDO.setRowKey(getRowKey(rowLock.getResourceId(), rowLock.getTableName(), rowLock.getPk()));
|
||||
lockDO.setXid(rowLock.getXid());
|
||||
lockDO.setTransactionId(rowLock.getTransactionId());
|
||||
lockDO.setTableName(rowLock.getTableName());
|
||||
lockDOs.add(lockDO);
|
||||
}
|
||||
return lockDOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get row key string.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
* @param tableName the table name
|
||||
* @param pk the pk
|
||||
* @return the string
|
||||
*/
|
||||
protected String getRowKey(String resourceId, String tableName, String pk) {
|
||||
return new StringBuilder().append(resourceId).append(LOCK_SPLIT).append(tableName).append(LOCK_SPLIT).append(pk)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAllLocks() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releaseLock(String xid, Long branchId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releaseLock(String xid, List<Long> branchIds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
41
core/src/main/java/io/seata/core/lock/LocalDBLocker.java
Normal file
41
core/src/main/java/io/seata/core/lock/LocalDBLocker.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.lock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Local db locker.
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public class LocalDBLocker extends AbstractLocker {
|
||||
|
||||
@Override
|
||||
public boolean acquireLock(List<RowLock> rowLock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releaseLock(List<RowLock> rowLock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLockable(List<RowLock> rowLock) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
36
core/src/main/java/io/seata/core/lock/LockMode.java
Normal file
36
core/src/main/java/io/seata/core/lock/LockMode.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.lock;
|
||||
|
||||
/**
|
||||
* lock mode
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public enum LockMode {
|
||||
|
||||
/**
|
||||
* store the lock in user's database
|
||||
*/
|
||||
LOCAL,
|
||||
|
||||
/**
|
||||
* store the lock in seata's server
|
||||
*/
|
||||
REMOTE;
|
||||
|
||||
|
||||
}
|
||||
72
core/src/main/java/io/seata/core/lock/Locker.java
Normal file
72
core/src/main/java/io/seata/core/lock/Locker.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.lock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Locker.
|
||||
*/
|
||||
public interface Locker {
|
||||
|
||||
/**
|
||||
* Acquire lock boolean.
|
||||
*
|
||||
* @param rowLock the row lock
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean acquireLock(List<RowLock> rowLock) ;
|
||||
|
||||
/**
|
||||
* Release lock boolean.
|
||||
*
|
||||
* @param rowLock the row lock
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean releaseLock(List<RowLock> rowLock);
|
||||
|
||||
/**
|
||||
* Release lock boolean.
|
||||
*
|
||||
* @param xid the xid
|
||||
* @param branchId the branch id
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean releaseLock(String xid, Long branchId);
|
||||
|
||||
/**
|
||||
* Release lock boolean.
|
||||
*
|
||||
* @param xid the xid
|
||||
* @param branchIds the branch ids
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean releaseLock(String xid, List<Long> branchIds);
|
||||
|
||||
/**
|
||||
* Is lockable boolean.
|
||||
*
|
||||
* @param rowLock the row lock
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean isLockable(List<RowLock> rowLock);
|
||||
|
||||
/**
|
||||
* Clean all locks.
|
||||
*/
|
||||
void cleanAllLocks();
|
||||
}
|
||||
|
||||
192
core/src/main/java/io/seata/core/lock/RowLock.java
Normal file
192
core/src/main/java/io/seata/core/lock/RowLock.java
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.lock;
|
||||
|
||||
import io.seata.common.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The type Row lock.
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public class RowLock {
|
||||
|
||||
private String xid;
|
||||
|
||||
private Long transactionId;
|
||||
|
||||
private Long branchId;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String pk;
|
||||
|
||||
private String rowKey;
|
||||
|
||||
private String feature;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets transaction id.
|
||||
*
|
||||
* @return the transaction id
|
||||
*/
|
||||
public Long getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction id.
|
||||
*
|
||||
* @param transactionId the transaction id
|
||||
*/
|
||||
public void setTransactionId(Long transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch id.
|
||||
*
|
||||
* @return the branch id
|
||||
*/
|
||||
public Long getBranchId() {
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch id.
|
||||
*
|
||||
* @param branchId the branch id
|
||||
*/
|
||||
public void setBranchId(Long branchId) {
|
||||
this.branchId = branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource id.
|
||||
*
|
||||
* @return the resource id
|
||||
*/
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource id.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
*/
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets table name.
|
||||
*
|
||||
* @return the table name
|
||||
*/
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets table name.
|
||||
*
|
||||
* @param tableName the table name
|
||||
*/
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets pk.
|
||||
*
|
||||
* @return the pk
|
||||
*/
|
||||
public String getPk() {
|
||||
return pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets pk.
|
||||
*
|
||||
* @param pk the pk
|
||||
*/
|
||||
public void setPk(String pk) {
|
||||
this.pk = pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets row key.
|
||||
*
|
||||
* @return the row key
|
||||
*/
|
||||
public String getRowKey() {
|
||||
return rowKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets row key.
|
||||
*
|
||||
* @param rowKey the row key
|
||||
*/
|
||||
public void setRowKey(String rowKey) {
|
||||
this.rowKey = rowKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets feature.
|
||||
*
|
||||
* @return the feature
|
||||
*/
|
||||
public String getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets feature.
|
||||
*
|
||||
* @param feature the feature
|
||||
*/
|
||||
public void setFeature(String feature) {
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.toString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import io.seata.common.util.CollectionUtils;
|
||||
import io.seata.config.Configuration;
|
||||
import io.seata.config.ConfigurationFactory;
|
||||
import io.seata.core.constants.ConfigurationKeys;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import static io.seata.common.DefaultValues.DEFAULT_LOG_EXCEPTION_RATE;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public final class StackTraceLogger {
|
||||
|
||||
private static final Configuration CONFIG = ConfigurationFactory.getInstance();
|
||||
|
||||
private static final String STACK_TRACE_LOGGER_PREFIX = "[stacktrace]";
|
||||
|
||||
public static void info(Logger logger, Throwable cause, String format, Object[] args) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
if (needToPrintStackTrace()) {
|
||||
logger.info(STACK_TRACE_LOGGER_PREFIX + format, buildNewArgs(args, cause));
|
||||
} else {
|
||||
logger.info(format, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void warn(Logger logger, Throwable cause, String format, Object[] args) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
if (needToPrintStackTrace()) {
|
||||
logger.warn(STACK_TRACE_LOGGER_PREFIX + format, buildNewArgs(args, cause));
|
||||
} else {
|
||||
logger.warn(format, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void error(Logger logger, Throwable cause, String format, Object[] args) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
if (needToPrintStackTrace()) {
|
||||
logger.error(STACK_TRACE_LOGGER_PREFIX + format, buildNewArgs(args, cause));
|
||||
} else {
|
||||
logger.error(format, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getRate() {
|
||||
return CONFIG.getInt(ConfigurationKeys.TRANSACTION_LOG_EXCEPTION_RATE, DEFAULT_LOG_EXCEPTION_RATE);
|
||||
}
|
||||
|
||||
private static boolean needToPrintStackTrace() {
|
||||
int rate = getRate();
|
||||
return ThreadLocalRandom.current().nextInt(rate) == 0;
|
||||
}
|
||||
|
||||
private static Object[] buildNewArgs(Object[] args, Throwable cause) {
|
||||
if (CollectionUtils.isEmpty(args)) {
|
||||
return new Object[]{cause};
|
||||
} else {
|
||||
Object[] newArgs = Arrays.copyOf(args, args.length + 1);
|
||||
newArgs[args.length] = cause;
|
||||
return newArgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
136
core/src/main/java/io/seata/core/model/BranchStatus.java
Normal file
136
core/src/main/java/io/seata/core/model/BranchStatus.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
|
||||
/**
|
||||
* Status of branch transaction.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public enum BranchStatus {
|
||||
|
||||
/**
|
||||
* The Unknown.
|
||||
* description:Unknown branch status.
|
||||
*/
|
||||
Unknown(0),
|
||||
|
||||
/**
|
||||
* The Registered.
|
||||
* description:Registered to TC.
|
||||
*/
|
||||
Registered(1),
|
||||
|
||||
/**
|
||||
* The Phase one done.
|
||||
* description:Branch logic is successfully done at phase one.
|
||||
*/
|
||||
PhaseOne_Done(2),
|
||||
|
||||
/**
|
||||
* The Phase one failed.
|
||||
* description:Branch logic is failed at phase one.
|
||||
*/
|
||||
PhaseOne_Failed(3),
|
||||
|
||||
/**
|
||||
* The Phase one timeout.
|
||||
* description:Branch logic is NOT reported for a timeout.
|
||||
*/
|
||||
PhaseOne_Timeout(4),
|
||||
|
||||
/**
|
||||
* The Phase two committed.
|
||||
* description:Commit logic is successfully done at phase two.
|
||||
*/
|
||||
PhaseTwo_Committed(5),
|
||||
|
||||
/**
|
||||
* The Phase two commit failed retryable.
|
||||
* description:Commit logic is failed but retryable.
|
||||
*/
|
||||
PhaseTwo_CommitFailed_Retryable(6),
|
||||
|
||||
/**
|
||||
* The Phase two commit failed unretryable.
|
||||
* description:Commit logic is failed and NOT retryable.
|
||||
*/
|
||||
PhaseTwo_CommitFailed_Unretryable(7),
|
||||
|
||||
/**
|
||||
* The Phase two rollbacked.
|
||||
* description:Rollback logic is successfully done at phase two.
|
||||
*/
|
||||
PhaseTwo_Rollbacked(8),
|
||||
|
||||
/**
|
||||
* The Phase two rollback failed retryable.
|
||||
* description:Rollback logic is failed but retryable.
|
||||
*/
|
||||
PhaseTwo_RollbackFailed_Retryable(9),
|
||||
|
||||
/**
|
||||
* The Phase two rollback failed unretryable.
|
||||
* description:Rollback logic is failed but NOT retryable.
|
||||
*/
|
||||
PhaseTwo_RollbackFailed_Unretryable(10);
|
||||
|
||||
private int code;
|
||||
|
||||
BranchStatus(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get branch status.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the branch status
|
||||
*/
|
||||
public static BranchStatus get(byte code) {
|
||||
return get((int)code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get branch status.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the branch status
|
||||
*/
|
||||
public static BranchStatus get(int code) {
|
||||
BranchStatus value = null;
|
||||
try {
|
||||
value = BranchStatus.values()[code];
|
||||
} catch (Exception e) {
|
||||
throw new ShouldNeverHappenException("Unknown BranchStatus[" + code + "]");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
85
core/src/main/java/io/seata/core/model/BranchType.java
Normal file
85
core/src/main/java/io/seata/core/model/BranchType.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
/**
|
||||
* The enum Branch type.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public enum BranchType {
|
||||
|
||||
/**
|
||||
* The At.
|
||||
*/
|
||||
// AT Branch
|
||||
AT,
|
||||
|
||||
/**
|
||||
* The TCC.
|
||||
*/
|
||||
TCC,
|
||||
|
||||
/**
|
||||
* The SAGA.
|
||||
*/
|
||||
SAGA,
|
||||
|
||||
/**
|
||||
* The XA.
|
||||
*/
|
||||
XA;
|
||||
|
||||
/**
|
||||
* Get branch type.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the branch type
|
||||
*/
|
||||
public static BranchType get(byte ordinal) {
|
||||
return get((int)ordinal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get branch type.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the branch type
|
||||
*/
|
||||
public static BranchType get(int ordinal) {
|
||||
for (BranchType branchType : values()) {
|
||||
if (branchType.ordinal() == ordinal) {
|
||||
return branchType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown BranchType[" + ordinal + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get branch type.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the branch type
|
||||
*/
|
||||
public static BranchType get(String name) {
|
||||
for (BranchType branchType : values()) {
|
||||
if (branchType.name().equalsIgnoreCase(name)) {
|
||||
return branchType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown BranchType[" + name + "]");
|
||||
}
|
||||
}
|
||||
42
core/src/main/java/io/seata/core/model/GlobalLockConfig.java
Normal file
42
core/src/main/java/io/seata/core/model/GlobalLockConfig.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
/**
|
||||
* @author selfishlover
|
||||
*/
|
||||
public class GlobalLockConfig {
|
||||
|
||||
private int lockRetryInternal;
|
||||
|
||||
private int lockRetryTimes;
|
||||
|
||||
public int getLockRetryInternal() {
|
||||
return lockRetryInternal;
|
||||
}
|
||||
|
||||
public void setLockRetryInternal(int lockRetryInternal) {
|
||||
this.lockRetryInternal = lockRetryInternal;
|
||||
}
|
||||
|
||||
public int getLockRetryTimes() {
|
||||
return lockRetryTimes;
|
||||
}
|
||||
|
||||
public void setLockRetryTimes(int lockRetryTimes) {
|
||||
this.lockRetryTimes = lockRetryTimes;
|
||||
}
|
||||
}
|
||||
164
core/src/main/java/io/seata/core/model/GlobalStatus.java
Normal file
164
core/src/main/java/io/seata/core/model/GlobalStatus.java
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
|
||||
/**
|
||||
* Status of global transaction.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public enum GlobalStatus {
|
||||
|
||||
/**
|
||||
* Un known global status.
|
||||
*/
|
||||
// Unknown
|
||||
UnKnown(0),
|
||||
|
||||
/**
|
||||
* The Begin.
|
||||
*/
|
||||
// PHASE 1: can accept new branch registering.
|
||||
Begin(1),
|
||||
|
||||
/**
|
||||
* PHASE 2: Running Status: may be changed any time.
|
||||
*/
|
||||
// Committing.
|
||||
Committing(2),
|
||||
|
||||
/**
|
||||
* The Commit retrying.
|
||||
*/
|
||||
// Retrying commit after a recoverable failure.
|
||||
CommitRetrying(3),
|
||||
|
||||
/**
|
||||
* Rollbacking global status.
|
||||
*/
|
||||
// Rollbacking
|
||||
Rollbacking(4),
|
||||
|
||||
/**
|
||||
* The Rollback retrying.
|
||||
*/
|
||||
// Retrying rollback after a recoverable failure.
|
||||
RollbackRetrying(5),
|
||||
|
||||
/**
|
||||
* The Timeout rollbacking.
|
||||
*/
|
||||
// Rollbacking since timeout
|
||||
TimeoutRollbacking(6),
|
||||
|
||||
/**
|
||||
* The Timeout rollback retrying.
|
||||
*/
|
||||
// Retrying rollback (since timeout) after a recoverable failure.
|
||||
TimeoutRollbackRetrying(7),
|
||||
|
||||
/**
|
||||
* All branches can be async committed. The committing is NOT done yet, but it can be seen as committed for TM/RM
|
||||
* client.
|
||||
*/
|
||||
AsyncCommitting(8),
|
||||
|
||||
/**
|
||||
* PHASE 2: Final Status: will NOT change any more.
|
||||
*/
|
||||
// Finally: global transaction is successfully committed.
|
||||
Committed(9),
|
||||
|
||||
/**
|
||||
* The Commit failed.
|
||||
*/
|
||||
// Finally: failed to commit
|
||||
CommitFailed(10),
|
||||
|
||||
/**
|
||||
* The Rollbacked.
|
||||
*/
|
||||
// Finally: global transaction is successfully rollbacked.
|
||||
Rollbacked(11),
|
||||
|
||||
/**
|
||||
* The Rollback failed.
|
||||
*/
|
||||
// Finally: failed to rollback
|
||||
RollbackFailed(12),
|
||||
|
||||
/**
|
||||
* The Timeout rollbacked.
|
||||
*/
|
||||
// Finally: global transaction is successfully rollbacked since timeout.
|
||||
TimeoutRollbacked(13),
|
||||
|
||||
/**
|
||||
* The Timeout rollback failed.
|
||||
*/
|
||||
// Finally: failed to rollback since timeout
|
||||
TimeoutRollbackFailed(14),
|
||||
|
||||
/**
|
||||
* The Finished.
|
||||
*/
|
||||
// Not managed in session MAP any more
|
||||
Finished(15);
|
||||
|
||||
private int code;
|
||||
|
||||
GlobalStatus(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get global status.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the global status
|
||||
*/
|
||||
public static GlobalStatus get(byte code) {
|
||||
return get((int) code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global status.
|
||||
*
|
||||
* @param code the code
|
||||
* @return the global status
|
||||
*/
|
||||
public static GlobalStatus get(int code) {
|
||||
GlobalStatus value = null;
|
||||
try {
|
||||
value = GlobalStatus.values()[code];
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Unknown GlobalStatus[" + code + "]");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
48
core/src/main/java/io/seata/core/model/Resource.java
Normal file
48
core/src/main/java/io/seata/core/model/Resource.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
/**
|
||||
* Resource that can be managed by Resource Manager and involved into global transaction.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface Resource {
|
||||
|
||||
/**
|
||||
* Get the resource group id.
|
||||
* e.g. master and slave data-source should be with the same resource group id.
|
||||
*
|
||||
* @return resource group id.
|
||||
*/
|
||||
String getResourceGroupId();
|
||||
|
||||
/**
|
||||
* Get the resource id.
|
||||
* e.g. url of a data-source could be the id of the db data-source resource.
|
||||
*
|
||||
* @return resource id.
|
||||
*/
|
||||
String getResourceId();
|
||||
|
||||
/**
|
||||
* get resource type, AT, TCC, SAGA and XA
|
||||
*
|
||||
* @return branch type
|
||||
*/
|
||||
BranchType getBranchType();
|
||||
|
||||
}
|
||||
54
core/src/main/java/io/seata/core/model/ResourceManager.java
Normal file
54
core/src/main/java/io/seata/core/model/ResourceManager.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Resource Manager: common behaviors.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface ResourceManager extends ResourceManagerInbound, ResourceManagerOutbound {
|
||||
|
||||
/**
|
||||
* Register a Resource to be managed by Resource Manager.
|
||||
*
|
||||
* @param resource The resource to be managed.
|
||||
*/
|
||||
void registerResource(Resource resource);
|
||||
|
||||
/**
|
||||
* Unregister a Resource from the Resource Manager.
|
||||
*
|
||||
* @param resource The resource to be removed.
|
||||
*/
|
||||
void unregisterResource(Resource resource);
|
||||
|
||||
/**
|
||||
* Get all resources managed by this manager.
|
||||
*
|
||||
* @return resourceId -- Resource Map
|
||||
*/
|
||||
Map<String, Resource> getManagedResources();
|
||||
|
||||
/**
|
||||
* Get the BranchType.
|
||||
*
|
||||
* @return The BranchType of ResourceManager.
|
||||
*/
|
||||
BranchType getBranchType();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
import io.seata.core.exception.TransactionException;
|
||||
|
||||
/**
|
||||
* Resource Manager.
|
||||
*
|
||||
* Control a branch transaction commit or rollback.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface ResourceManagerInbound {
|
||||
|
||||
/**
|
||||
* Commit a branch transaction.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param xid Transaction id.
|
||||
* @param branchId Branch id.
|
||||
* @param resourceId Resource id.
|
||||
* @param applicationData Application data bind with this branch.
|
||||
* @return Status of the branch after committing.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Rollback a branch transaction.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param xid Transaction id.
|
||||
* @param branchId Branch id.
|
||||
* @param resourceId Resource id.
|
||||
* @param applicationData Application data bind with this branch.
|
||||
* @return Status of the branch after rollbacking.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
BranchStatus branchRollback(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
import io.seata.core.exception.TransactionException;
|
||||
|
||||
/**
|
||||
* Resource Manager: send outbound request to TC.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface ResourceManagerOutbound {
|
||||
|
||||
/**
|
||||
* Branch register long.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param resourceId the resource id
|
||||
* @param clientId the client id
|
||||
* @param xid the xid
|
||||
* @param applicationData the context
|
||||
* @param lockKeys the lock keys
|
||||
* @return the long
|
||||
* @throws TransactionException the transaction exception
|
||||
*/
|
||||
Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData, String lockKeys) throws
|
||||
TransactionException;
|
||||
|
||||
/**
|
||||
* Branch report.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param xid the xid
|
||||
* @param branchId the branch id
|
||||
* @param status the status
|
||||
* @param applicationData the application data
|
||||
* @throws TransactionException the transaction exception
|
||||
*/
|
||||
void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Lock query boolean.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
* @param resourceId the resource id
|
||||
* @param xid the xid
|
||||
* @param lockKeys the lock keys
|
||||
* @return the boolean
|
||||
* @throws TransactionException the transaction exception
|
||||
*/
|
||||
boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys)
|
||||
throws TransactionException;
|
||||
}
|
||||
76
core/src/main/java/io/seata/core/model/Result.java
Normal file
76
core/src/main/java/io/seata/core/model/Result.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
/**
|
||||
* Generic return result class
|
||||
*
|
||||
* @author zjinlei
|
||||
*/
|
||||
public class Result<T> {
|
||||
|
||||
private T result;
|
||||
|
||||
private String errMsg;
|
||||
|
||||
private Object[] errMsgParams;
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public Object[] getErrMsgParams() {
|
||||
return errMsgParams;
|
||||
}
|
||||
|
||||
public void setErrMsgParams(Object[] errMsgParams) {
|
||||
this.errMsgParams = errMsgParams;
|
||||
}
|
||||
|
||||
public Result(T result, String errMsg, Object[] errMsgParams) {
|
||||
this.result = result;
|
||||
this.errMsg = errMsg;
|
||||
this.errMsgParams = errMsgParams;
|
||||
}
|
||||
|
||||
public static Result<Boolean> ok() {
|
||||
return new Result<>(true, null, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> build(T result) {
|
||||
return new Result(result, null, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> build(T result, String errMsg) {
|
||||
return new Result(result, errMsg, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> buildWithParams(T result, String errMsg, Object... args) {
|
||||
return new Result(result, errMsg, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.model;
|
||||
|
||||
import io.seata.core.exception.TransactionException;
|
||||
|
||||
/**
|
||||
* Transaction Manager.
|
||||
*
|
||||
* Define a global transaction and control it.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface TransactionManager {
|
||||
|
||||
/**
|
||||
* Begin a new global transaction.
|
||||
*
|
||||
* @param applicationId ID of the application who begins this transaction.
|
||||
* @param transactionServiceGroup ID of the transaction service group.
|
||||
* @param name Give a name to the global transaction.
|
||||
* @param timeout Timeout of the global transaction.
|
||||
* @return XID of the global transaction
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
String begin(String applicationId, String transactionServiceGroup, String name, int timeout)
|
||||
throws TransactionException;
|
||||
|
||||
/**
|
||||
* Global commit.
|
||||
*
|
||||
* @param xid XID of the global transaction.
|
||||
* @return Status of the global transaction after committing.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
GlobalStatus commit(String xid) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Global rollback.
|
||||
*
|
||||
* @param xid XID of the global transaction
|
||||
* @return Status of the global transaction after rollbacking.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
GlobalStatus rollback(String xid) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Get current status of the give transaction.
|
||||
*
|
||||
* @param xid XID of the global transaction.
|
||||
* @return Current status of the global transaction.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
GlobalStatus getStatus(String xid) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Global report.
|
||||
*
|
||||
* @param xid XID of the global transaction.
|
||||
* @param globalStatus Status of the global transaction.
|
||||
* @return Status of the global transaction.
|
||||
* @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
|
||||
* out.
|
||||
*/
|
||||
GlobalStatus globalReport(String xid, GlobalStatus globalStatus) throws TransactionException;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
|
||||
/**
|
||||
* The type Abstract identify request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractIdentifyRequest extends AbstractMessage {
|
||||
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
protected String version = Version.getCurrent();
|
||||
|
||||
/**
|
||||
* The Application id.
|
||||
*/
|
||||
protected String applicationId;
|
||||
|
||||
/**
|
||||
* The Transaction service group.
|
||||
*/
|
||||
protected String transactionServiceGroup;
|
||||
|
||||
/**
|
||||
* The Extra data.
|
||||
*/
|
||||
protected String extraData;
|
||||
|
||||
/**
|
||||
* Instantiates a new Abstract identify request.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
*/
|
||||
public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup) {
|
||||
this(applicationId, transactionServiceGroup, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Abstract identify request.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public AbstractIdentifyRequest(String applicationId, String transactionServiceGroup, String extraData) {
|
||||
this.applicationId = applicationId;
|
||||
this.transactionServiceGroup = transactionServiceGroup;
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets version.
|
||||
*
|
||||
* @param version the version
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets application id.
|
||||
*
|
||||
* @return the application id
|
||||
*/
|
||||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets application id.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
*/
|
||||
public void setApplicationId(String applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets transaction service group.
|
||||
*
|
||||
* @return the transaction service group
|
||||
*/
|
||||
public String getTransactionServiceGroup() {
|
||||
return transactionServiceGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction service group.
|
||||
*
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
*/
|
||||
public void setTransactionServiceGroup(String transactionServiceGroup) {
|
||||
this.transactionServiceGroup = transactionServiceGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra data.
|
||||
*
|
||||
* @return the extra data
|
||||
*/
|
||||
public String getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra data.
|
||||
*
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public void setExtraData(String extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The type Abstract identify response.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractIdentifyResponse extends AbstractResultMessage {
|
||||
|
||||
private String version = Version.getCurrent();
|
||||
|
||||
private String extraData;
|
||||
|
||||
private boolean identified;
|
||||
|
||||
/**
|
||||
* Gets version.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets version.
|
||||
*
|
||||
* @param version the version
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra data.
|
||||
*
|
||||
* @return the extra data
|
||||
*/
|
||||
public String getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra data.
|
||||
*
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public void setExtraData(String extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is identified boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isIdentified() {
|
||||
return identified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets identified.
|
||||
*
|
||||
* @param identified the identified
|
||||
*/
|
||||
public void setIdentified(boolean identified) {
|
||||
this.identified = identified;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("version=");
|
||||
result.append(version);
|
||||
result.append(",");
|
||||
result.append("extraData=");
|
||||
result.append(extraData);
|
||||
result.append(",");
|
||||
result.append("identified=");
|
||||
result.append(identified);
|
||||
result.append(",");
|
||||
result.append("resultCode=");
|
||||
result.append(getResultCode());
|
||||
result.append(",");
|
||||
result.append("msg=");
|
||||
result.append(getMsg());
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.seata.common.Constants;
|
||||
import io.seata.common.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* The type Abstract message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public abstract class AbstractMessage implements MessageTypeAware, Serializable {
|
||||
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractMessage.class);
|
||||
|
||||
protected static final long serialVersionUID = -1441020418526899889L;
|
||||
|
||||
/**
|
||||
* The constant UTF8.
|
||||
*/
|
||||
protected static final Charset UTF8 = Constants.DEFAULT_CHARSET;
|
||||
/**
|
||||
* The Ctx.
|
||||
*/
|
||||
protected ChannelHandlerContext ctx;
|
||||
|
||||
/**
|
||||
* Bytes to int int.
|
||||
*
|
||||
* @param bytes the bytes
|
||||
* @param offset the offset
|
||||
* @return the int
|
||||
*/
|
||||
public static int bytesToInt(byte[] bytes, int offset) {
|
||||
int ret = 0;
|
||||
for (int i = 0; i < 4 && i + offset < bytes.length; i++) {
|
||||
ret <<= 8;
|
||||
ret |= (int)bytes[i + offset] & 0xFF;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Int to bytes.
|
||||
*
|
||||
* @param i the
|
||||
* @param bytes the bytes
|
||||
* @param offset the offset
|
||||
*/
|
||||
public static void intToBytes(int i, byte[] bytes, int offset) {
|
||||
bytes[offset] = (byte)((i >> 24) & 0xFF);
|
||||
bytes[offset + 1] = (byte)((i >> 16) & 0xFF);
|
||||
bytes[offset + 2] = (byte)((i >> 8) & 0xFF);
|
||||
bytes[offset + 3] = (byte)(i & 0xFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.toString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The type Abstract result message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public abstract class AbstractResultMessage extends AbstractMessage {
|
||||
|
||||
private ResultCode resultCode;
|
||||
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* Gets result code.
|
||||
*
|
||||
* @return the result code
|
||||
*/
|
||||
public ResultCode getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets result code.
|
||||
*
|
||||
* @param resultCode the result code
|
||||
*/
|
||||
public void setResultCode(ResultCode resultCode) {
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets msg.
|
||||
*
|
||||
* @return the msg
|
||||
*/
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets msg.
|
||||
*
|
||||
* @param msg the msg
|
||||
*/
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Heartbeat message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class HeartbeatMessage implements MessageTypeAware, Serializable {
|
||||
private static final long serialVersionUID = -985316399527884899L;
|
||||
private boolean ping = true;
|
||||
/**
|
||||
* The constant PING.
|
||||
*/
|
||||
public static final HeartbeatMessage PING = new HeartbeatMessage(true);
|
||||
/**
|
||||
* The constant PONG.
|
||||
*/
|
||||
public static final HeartbeatMessage PONG = new HeartbeatMessage(false);
|
||||
|
||||
private HeartbeatMessage(boolean ping) {
|
||||
this.ping = ping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_HEARTBEAT_MSG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.ping ? "services ping" : "services pong";
|
||||
}
|
||||
|
||||
public boolean isPing() {
|
||||
return ping;
|
||||
}
|
||||
|
||||
public void setPing(boolean ping) {
|
||||
this.ping = ping;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The type Incompatible version exception.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class IncompatibleVersionException extends Exception {
|
||||
|
||||
/**
|
||||
* Instantiates a new Incompatible version exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public IncompatibleVersionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
24
core/src/main/java/io/seata/core/protocol/MergeMessage.java
Normal file
24
core/src/main/java/io/seata/core/protocol/MergeMessage.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The interface Merge message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public interface MergeMessage {
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
|
||||
/**
|
||||
* The type Merge result message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class MergeResultMessage extends AbstractMessage implements MergeMessage {
|
||||
|
||||
/**
|
||||
* The Msgs.
|
||||
*/
|
||||
public AbstractResultMessage[] msgs;
|
||||
|
||||
/**
|
||||
* Get msgs abstract result message [ ].
|
||||
*
|
||||
* @return the abstract result message [ ]
|
||||
*/
|
||||
public AbstractResultMessage[] getMsgs() {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets msgs.
|
||||
*
|
||||
* @param msgs the msgs
|
||||
*/
|
||||
public void setMsgs(AbstractResultMessage[] msgs) {
|
||||
this.msgs = msgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_SEATA_MERGE_RESULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("MergeResultMessage ");
|
||||
if (msgs == null) {
|
||||
return sb.toString();
|
||||
}
|
||||
for (AbstractMessage msg : msgs) { sb.append(msg.toString()).append("\n"); }
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Merged warp message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class MergedWarpMessage extends AbstractMessage implements Serializable, MergeMessage {
|
||||
|
||||
/**
|
||||
* The Msgs.
|
||||
*/
|
||||
public List<AbstractMessage> msgs = new ArrayList<>();
|
||||
/**
|
||||
* The Msg ids.
|
||||
*/
|
||||
public List<Integer> msgIds = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_SEATA_MERGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("SeataMergeMessage ");
|
||||
for (AbstractMessage msg : msgs) {
|
||||
sb.append(msg.toString()).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
118
core/src/main/java/io/seata/core/protocol/MessageFuture.java
Normal file
118
core/src/main/java/io/seata/core/protocol/MessageFuture.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* The type Message future.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class MessageFuture {
|
||||
private RpcMessage requestMessage;
|
||||
private long timeout;
|
||||
private long start = System.currentTimeMillis();
|
||||
private transient CompletableFuture<Object> origin = new CompletableFuture<>();
|
||||
|
||||
/**
|
||||
* Is timeout boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isTimeout() {
|
||||
return System.currentTimeMillis() - start > timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object.
|
||||
*
|
||||
* @param timeout the timeout
|
||||
* @param unit the unit
|
||||
* @return the object
|
||||
* @throws TimeoutException the timeout exception
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
public Object get(long timeout, TimeUnit unit) throws TimeoutException,
|
||||
InterruptedException {
|
||||
Object result = null;
|
||||
try {
|
||||
result = origin.get(timeout, unit);
|
||||
} catch (ExecutionException e) {
|
||||
throw new ShouldNeverHappenException("Should not get results in a multi-threaded environment", e);
|
||||
} catch (TimeoutException e) {
|
||||
throw new TimeoutException("cost " + (System.currentTimeMillis() - start) + " ms");
|
||||
}
|
||||
|
||||
if (result instanceof RuntimeException) {
|
||||
throw (RuntimeException)result;
|
||||
} else if (result instanceof Throwable) {
|
||||
throw new RuntimeException((Throwable)result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets result message.
|
||||
*
|
||||
* @param obj the obj
|
||||
*/
|
||||
public void setResultMessage(Object obj) {
|
||||
origin.complete(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets request message.
|
||||
*
|
||||
* @return the request message
|
||||
*/
|
||||
public RpcMessage getRequestMessage() {
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request message.
|
||||
*
|
||||
* @param requestMessage the request message
|
||||
*/
|
||||
public void setRequestMessage(RpcMessage requestMessage) {
|
||||
this.requestMessage = requestMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets timeout.
|
||||
*
|
||||
* @return the timeout
|
||||
*/
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets timeout.
|
||||
*
|
||||
* @param timeout the timeout
|
||||
*/
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
141
core/src/main/java/io/seata/core/protocol/MessageType.java
Normal file
141
core/src/main/java/io/seata/core/protocol/MessageType.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The type Message codec type.
|
||||
*
|
||||
* @author zhangsen
|
||||
*/
|
||||
public interface MessageType {
|
||||
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_BEGIN.
|
||||
*/
|
||||
short TYPE_GLOBAL_BEGIN = 1;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_BEGIN_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_BEGIN_RESULT = 2;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_COMMIT.
|
||||
*/
|
||||
short TYPE_GLOBAL_COMMIT = 7;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_COMMIT_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_COMMIT_RESULT = 8;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_ROLLBACK.
|
||||
*/
|
||||
short TYPE_GLOBAL_ROLLBACK = 9;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_ROLLBACK_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_ROLLBACK_RESULT = 10;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_STATUS.
|
||||
*/
|
||||
short TYPE_GLOBAL_STATUS = 15;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_STATUS_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_STATUS_RESULT = 16;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_REPORT.
|
||||
*/
|
||||
short TYPE_GLOBAL_REPORT = 17;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_REPORT_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_REPORT_RESULT = 18;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_LOCK_QUERY.
|
||||
*/
|
||||
short TYPE_GLOBAL_LOCK_QUERY = 21;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_LOCK_QUERY_RESULT.
|
||||
*/
|
||||
short TYPE_GLOBAL_LOCK_QUERY_RESULT = 22;
|
||||
|
||||
/**
|
||||
* The constant TYPE_BRANCH_COMMIT.
|
||||
*/
|
||||
short TYPE_BRANCH_COMMIT = 3;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_COMMIT_RESULT.
|
||||
*/
|
||||
short TYPE_BRANCH_COMMIT_RESULT = 4;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_ROLLBACK.
|
||||
*/
|
||||
short TYPE_BRANCH_ROLLBACK = 5;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_ROLLBACK_RESULT.
|
||||
*/
|
||||
short TYPE_BRANCH_ROLLBACK_RESULT = 6;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_REGISTER.
|
||||
*/
|
||||
short TYPE_BRANCH_REGISTER = 11;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_REGISTER_RESULT.
|
||||
*/
|
||||
short TYPE_BRANCH_REGISTER_RESULT = 12;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_STATUS_REPORT.
|
||||
*/
|
||||
short TYPE_BRANCH_STATUS_REPORT = 13;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_STATUS_REPORT_RESULT.
|
||||
*/
|
||||
short TYPE_BRANCH_STATUS_REPORT_RESULT = 14;
|
||||
|
||||
/**
|
||||
* The constant TYPE_SEATA_MERGE.
|
||||
*/
|
||||
short TYPE_SEATA_MERGE = 59;
|
||||
/**
|
||||
* The constant TYPE_SEATA_MERGE_RESULT.
|
||||
*/
|
||||
short TYPE_SEATA_MERGE_RESULT = 60;
|
||||
|
||||
/**
|
||||
* The constant TYPE_REG_CLT.
|
||||
*/
|
||||
short TYPE_REG_CLT = 101;
|
||||
/**
|
||||
* The constant TYPE_REG_CLT_RESULT.
|
||||
*/
|
||||
short TYPE_REG_CLT_RESULT = 102;
|
||||
/**
|
||||
* The constant TYPE_REG_RM.
|
||||
*/
|
||||
short TYPE_REG_RM = 103;
|
||||
/**
|
||||
* The constant TYPE_REG_RM_RESULT.
|
||||
*/
|
||||
short TYPE_REG_RM_RESULT = 104;
|
||||
/**
|
||||
* The constant TYPE_RM_DELETE_UNDOLOG.
|
||||
*/
|
||||
short TYPE_RM_DELETE_UNDOLOG = 111;
|
||||
|
||||
/**
|
||||
* the constant TYPE_HEARTBEAT_MSG
|
||||
*/
|
||||
short TYPE_HEARTBEAT_MSG = 120;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The interface Message type aware.
|
||||
*/
|
||||
public interface MessageTypeAware {
|
||||
|
||||
/**
|
||||
* Gets type code.
|
||||
*
|
||||
* @return the type code
|
||||
*/
|
||||
short getTypeCode();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import io.seata.config.ConfigurationFactory;
|
||||
import io.seata.core.serializer.SerializerType;
|
||||
import io.seata.core.compressor.CompressorType;
|
||||
import io.seata.core.constants.ConfigurationKeys;
|
||||
|
||||
/**
|
||||
* @author Geng Zhang
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public interface ProtocolConstants {
|
||||
|
||||
/**
|
||||
* Magic code
|
||||
*/
|
||||
byte[] MAGIC_CODE_BYTES = {(byte) 0xda, (byte) 0xda};
|
||||
|
||||
/**
|
||||
* Protocol version
|
||||
*/
|
||||
byte VERSION = 1;
|
||||
|
||||
/**
|
||||
* Max frame length
|
||||
*/
|
||||
int MAX_FRAME_LENGTH = 8 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* HEAD_LENGTH of protocol v1
|
||||
*/
|
||||
int V1_HEAD_LENGTH = 16;
|
||||
|
||||
/**
|
||||
* Message type: Request
|
||||
*/
|
||||
byte MSGTYPE_RESQUEST_SYNC = 0;
|
||||
/**
|
||||
* Message type: Response
|
||||
*/
|
||||
byte MSGTYPE_RESPONSE = 1;
|
||||
/**
|
||||
* Message type: Request which no need response
|
||||
*/
|
||||
byte MSGTYPE_RESQUEST_ONEWAY = 2;
|
||||
/**
|
||||
* Message type: Heartbeat Request
|
||||
*/
|
||||
byte MSGTYPE_HEARTBEAT_REQUEST = 3;
|
||||
/**
|
||||
* Message type: Heartbeat Response
|
||||
*/
|
||||
byte MSGTYPE_HEARTBEAT_RESPONSE = 4;
|
||||
|
||||
//byte MSGTYPE_NEGOTIATOR_REQUEST = 5;
|
||||
//byte MSGTYPE_NEGOTIATOR_RESPONSE = 6;
|
||||
|
||||
/**
|
||||
* Configured codec by user, default is SEATA
|
||||
*
|
||||
* @see SerializerType#SEATA
|
||||
*/
|
||||
byte CONFIGURED_CODEC = SerializerType.getByName(ConfigurationFactory.getInstance()
|
||||
.getConfig(ConfigurationKeys.SERIALIZE_FOR_RPC, SerializerType.SEATA.name())).getCode();
|
||||
|
||||
/**
|
||||
* Configured compressor by user, default is NONE
|
||||
*
|
||||
* @see CompressorType#NONE
|
||||
*/
|
||||
byte CONFIGURED_COMPRESSOR = CompressorType.getByName(ConfigurationFactory.getInstance()
|
||||
.getConfig(ConfigurationKeys.COMPRESSOR_FOR_RPC, CompressorType.NONE.name())).getCode();
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Register rm request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RegisterRMRequest extends AbstractIdentifyRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* Instantiates a new Register rm request.
|
||||
*/
|
||||
public RegisterRMRequest() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Register rm request.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
*/
|
||||
public RegisterRMRequest(String applicationId, String transactionServiceGroup) {
|
||||
super(applicationId, transactionServiceGroup);
|
||||
}
|
||||
|
||||
private String resourceIds;
|
||||
|
||||
/**
|
||||
* Gets resource ids.
|
||||
*
|
||||
* @return the resource ids
|
||||
*/
|
||||
public String getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource ids.
|
||||
*
|
||||
* @param resourceIds the resource ids
|
||||
*/
|
||||
public void setResourceIds(String resourceIds) {
|
||||
this.resourceIds = resourceIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_REG_RM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RegisterRMRequest{" +
|
||||
"resourceIds='" + resourceIds + '\'' +
|
||||
", applicationId='" + applicationId + '\'' +
|
||||
", transactionServiceGroup='" + transactionServiceGroup + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Register rm response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RegisterRMResponse extends AbstractIdentifyResponse implements Serializable {
|
||||
|
||||
/**
|
||||
* Instantiates a new Register rm response.
|
||||
*/
|
||||
public RegisterRMResponse() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Register rm response.
|
||||
*
|
||||
* @param result the result
|
||||
*/
|
||||
public RegisterRMResponse(boolean result) {
|
||||
super();
|
||||
setIdentified(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_REG_RM_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.seata.common.util.NetUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import static io.seata.core.constants.ConfigurationKeys.EXTRA_DATA_SPLIT_CHAR;
|
||||
|
||||
/**
|
||||
* The type Register tm request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RegisterTMRequest extends AbstractIdentifyRequest implements Serializable {
|
||||
private static final long serialVersionUID = -5929081344190543690L;
|
||||
public static final String UDATA_VGROUP = "vgroup";
|
||||
public static final String UDATA_AK = "ak";
|
||||
public static final String UDATA_DIGEST = "digest";
|
||||
public static final String UDATA_IP = "ip";
|
||||
public static final String UDATA_TIMESTAMP = "timestamp";
|
||||
|
||||
/**
|
||||
* Instantiates a new Register tm request.
|
||||
*/
|
||||
public RegisterTMRequest() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Register tm request.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public RegisterTMRequest(String applicationId, String transactionServiceGroup, String extraData) {
|
||||
super(applicationId, transactionServiceGroup, extraData);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (null != extraData) {
|
||||
sb.append(extraData);
|
||||
if (!extraData.endsWith(EXTRA_DATA_SPLIT_CHAR)) {
|
||||
sb.append(EXTRA_DATA_SPLIT_CHAR);
|
||||
}
|
||||
}
|
||||
if (transactionServiceGroup != null && !transactionServiceGroup.isEmpty()) {
|
||||
sb.append(String.format("%s=%s", UDATA_VGROUP, transactionServiceGroup));
|
||||
sb.append(EXTRA_DATA_SPLIT_CHAR);
|
||||
String clientIP = NetUtil.getLocalIp();
|
||||
if (!StringUtils.isEmpty(clientIP)) {
|
||||
sb.append(String.format("%s=%s", UDATA_IP, clientIP));
|
||||
sb.append(EXTRA_DATA_SPLIT_CHAR);
|
||||
}
|
||||
}
|
||||
this.extraData = sb.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Register tm request.
|
||||
*
|
||||
* @param applicationId the application id
|
||||
* @param transactionServiceGroup the transaction service group
|
||||
*/
|
||||
public RegisterTMRequest(String applicationId, String transactionServiceGroup) {
|
||||
this(applicationId, transactionServiceGroup, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_REG_CLT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RegisterTMRequest{" +
|
||||
"applicationId='" + applicationId + '\'' +
|
||||
", transactionServiceGroup='" + transactionServiceGroup + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Register tm response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RegisterTMResponse extends AbstractIdentifyResponse implements Serializable {
|
||||
|
||||
/**
|
||||
* Instantiates a new Register tm response.
|
||||
*/
|
||||
public RegisterTMResponse() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Register tm response.
|
||||
*
|
||||
* @param result the result
|
||||
*/
|
||||
public RegisterTMResponse(boolean result) {
|
||||
super();
|
||||
setIdentified(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_REG_CLT_RESULT;
|
||||
}
|
||||
}
|
||||
61
core/src/main/java/io/seata/core/protocol/ResultCode.java
Normal file
61
core/src/main/java/io/seata/core/protocol/ResultCode.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
/**
|
||||
* The enum Result code.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public enum ResultCode {
|
||||
|
||||
/**
|
||||
* Failed result code.
|
||||
*/
|
||||
// Failed
|
||||
Failed,
|
||||
|
||||
/**
|
||||
* Success result code.
|
||||
*/
|
||||
// Success
|
||||
Success;
|
||||
|
||||
/**
|
||||
* Get result code.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the result code
|
||||
*/
|
||||
public static ResultCode get(byte ordinal) {
|
||||
return get((int)ordinal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get result code.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the result code
|
||||
*/
|
||||
public static ResultCode get(int ordinal) {
|
||||
for (ResultCode resultCode : ResultCode.values()) {
|
||||
if (resultCode.ordinal() == ordinal) {
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ResultCode[" + ordinal + "]");
|
||||
}
|
||||
}
|
||||
175
core/src/main/java/io/seata/core/protocol/RpcMessage.java
Normal file
175
core/src/main/java/io/seata/core/protocol/RpcMessage.java
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import io.seata.common.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Rpc message.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class RpcMessage {
|
||||
|
||||
private int id;
|
||||
private byte messageType;
|
||||
private byte codec;
|
||||
private byte compressor;
|
||||
private Map<String, String> headMap = new HashMap<>();
|
||||
private Object body;
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets id.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets body.
|
||||
*
|
||||
* @return the body
|
||||
*/
|
||||
public Object getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets body.
|
||||
*
|
||||
* @param body the body
|
||||
*/
|
||||
public void setBody(Object body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets codec.
|
||||
*
|
||||
* @return the codec
|
||||
*/
|
||||
public byte getCodec() {
|
||||
return codec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets codec.
|
||||
*
|
||||
* @param codec the codec
|
||||
* @return the codec
|
||||
*/
|
||||
public RpcMessage setCodec(byte codec) {
|
||||
this.codec = codec;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets compressor.
|
||||
*
|
||||
* @return the compressor
|
||||
*/
|
||||
public byte getCompressor() {
|
||||
return compressor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets compressor.
|
||||
*
|
||||
* @param compressor the compressor
|
||||
* @return the compressor
|
||||
*/
|
||||
public RpcMessage setCompressor(byte compressor) {
|
||||
this.compressor = compressor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets head map.
|
||||
*
|
||||
* @return the head map
|
||||
*/
|
||||
public Map<String, String> getHeadMap() {
|
||||
return headMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets head map.
|
||||
*
|
||||
* @param headMap the head map
|
||||
* @return the head map
|
||||
*/
|
||||
public RpcMessage setHeadMap(Map<String, String> headMap) {
|
||||
this.headMap = headMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets head.
|
||||
*
|
||||
* @param headKey the head key
|
||||
* @return the head
|
||||
*/
|
||||
public String getHead(String headKey) {
|
||||
return headMap.get(headKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put head.
|
||||
*
|
||||
* @param headKey the head key
|
||||
* @param headValue the head value
|
||||
*/
|
||||
public void putHead(String headKey, String headValue) {
|
||||
headMap.put(headKey, headValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message type.
|
||||
*
|
||||
* @return the message type
|
||||
*/
|
||||
public byte getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets message type.
|
||||
*
|
||||
* @param messageType the message type
|
||||
*/
|
||||
public void setMessageType(byte messageType) {
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StringUtils.toString(this);
|
||||
}
|
||||
}
|
||||
119
core/src/main/java/io/seata/core/protocol/Version.java
Normal file
119
core/src/main/java/io/seata/core/protocol/Version.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.seata.common.util.NetUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* The type Version.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class Version {
|
||||
|
||||
/**
|
||||
* The constant CURRENT.
|
||||
*/
|
||||
private static final String CURRENT = "1.4.2";
|
||||
private static final String VERSION_0_7_1 = "0.7.1";
|
||||
private static final int MAX_VERSION_DOT = 3;
|
||||
|
||||
/**
|
||||
* The constant VERSION_MAP.
|
||||
*/
|
||||
public static final Map<String, String> VERSION_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
private Version() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current.
|
||||
*
|
||||
* @return the current
|
||||
*/
|
||||
public static String getCurrent() {
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put channel version.
|
||||
*
|
||||
* @param c the c
|
||||
* @param v the v
|
||||
*/
|
||||
public static void putChannelVersion(Channel c, String v) {
|
||||
VERSION_MAP.put(NetUtil.toStringAddress(c.remoteAddress()), v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets channel version.
|
||||
*
|
||||
* @param c the c
|
||||
* @return the channel version
|
||||
*/
|
||||
public static String getChannelVersion(Channel c) {
|
||||
return VERSION_MAP.get(NetUtil.toStringAddress(c.remoteAddress()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check version string.
|
||||
*
|
||||
* @param version the version
|
||||
* @throws IncompatibleVersionException the incompatible version exception
|
||||
*/
|
||||
public static void checkVersion(String version) throws IncompatibleVersionException {
|
||||
long current = convertVersion(CURRENT);
|
||||
long clientVersion = convertVersion(version);
|
||||
long divideVersion = convertVersion(VERSION_0_7_1);
|
||||
if ((current > divideVersion && clientVersion < divideVersion) || (current < divideVersion && clientVersion > divideVersion)) {
|
||||
throw new IncompatibleVersionException("incompatible client version:" + version);
|
||||
}
|
||||
}
|
||||
|
||||
private static long convertVersion(String version) throws IncompatibleVersionException {
|
||||
String[] parts = StringUtils.split(version, '.');
|
||||
long result = 0L;
|
||||
int i = 1;
|
||||
int size = parts.length;
|
||||
if (size > MAX_VERSION_DOT + 1) {
|
||||
throw new IncompatibleVersionException("incompatible version format:" + version);
|
||||
}
|
||||
size = MAX_VERSION_DOT + 1;
|
||||
for (String part : parts) {
|
||||
if (StringUtils.isNumeric(part)) {
|
||||
result += calculatePartValue(part, size, i);
|
||||
} else {
|
||||
String[] subParts = StringUtils.split(part, '-');
|
||||
if (StringUtils.isNumeric(subParts[0])) {
|
||||
result += calculatePartValue(subParts[0], size, i);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long calculatePartValue(String partNumeric, int size, int index) {
|
||||
return Long.parseLong(partNumeric) * Double.valueOf(Math.pow(100, size - index)).longValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
|
||||
/**
|
||||
* The type Abstract branch end request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractBranchEndRequest extends AbstractTransactionRequestToRM {
|
||||
|
||||
/**
|
||||
* The Xid.
|
||||
*/
|
||||
protected String xid;
|
||||
|
||||
/**
|
||||
* The Branch id.
|
||||
*/
|
||||
protected long branchId;
|
||||
|
||||
/**
|
||||
* The Branch type.
|
||||
*/
|
||||
protected BranchType branchType = BranchType.AT;
|
||||
|
||||
/**
|
||||
* The Resource id.
|
||||
*/
|
||||
protected String resourceId;
|
||||
|
||||
/**
|
||||
* The Application data.
|
||||
*/
|
||||
protected String applicationData;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch id.
|
||||
*
|
||||
* @return the branch id
|
||||
*/
|
||||
public long getBranchId() {
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch id.
|
||||
*
|
||||
* @param branchId the branch id
|
||||
*/
|
||||
public void setBranchId(long branchId) {
|
||||
this.branchId = branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch type.
|
||||
*
|
||||
* @return the branch type
|
||||
*/
|
||||
public BranchType getBranchType() {
|
||||
return branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch type.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
*/
|
||||
public void setBranchType(BranchType branchType) {
|
||||
this.branchType = branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource id.
|
||||
*
|
||||
* @return the resource id
|
||||
*/
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource id.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
*/
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets application data.
|
||||
*
|
||||
* @return the application data
|
||||
*/
|
||||
public String getApplicationData() {
|
||||
return applicationData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets application data.
|
||||
*
|
||||
* @param applicationData the application data
|
||||
*/
|
||||
public void setApplicationData(String applicationData) {
|
||||
this.applicationData = applicationData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("xid=");
|
||||
result.append(xid);
|
||||
result.append(",");
|
||||
result.append("branchId=");
|
||||
result.append(branchId);
|
||||
result.append(",");
|
||||
result.append("branchType=");
|
||||
result.append(branchType);
|
||||
result.append(",");
|
||||
result.append("resourceId=");
|
||||
result.append(resourceId);
|
||||
result.append(",");
|
||||
result.append("applicationData=");
|
||||
result.append(applicationData);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.BranchStatus;
|
||||
|
||||
/**
|
||||
* The type Abstract branch end response.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractBranchEndResponse extends AbstractTransactionResponse {
|
||||
|
||||
/**
|
||||
* The Xid.
|
||||
*/
|
||||
protected String xid;
|
||||
|
||||
/**
|
||||
* The Branch id.
|
||||
*/
|
||||
protected long branchId;
|
||||
/**
|
||||
* The Branch status.
|
||||
*/
|
||||
protected BranchStatus branchStatus;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch id.
|
||||
*
|
||||
* @return the branch id
|
||||
*/
|
||||
public long getBranchId() {
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch id.
|
||||
*
|
||||
* @param branchId the branch id
|
||||
*/
|
||||
public void setBranchId(long branchId) {
|
||||
this.branchId = branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch status.
|
||||
*
|
||||
* @return the branch status
|
||||
*/
|
||||
public BranchStatus getBranchStatus() {
|
||||
return branchStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch status.
|
||||
*
|
||||
* @param branchStatus the branch status
|
||||
*/
|
||||
public void setBranchStatus(BranchStatus branchStatus) {
|
||||
this.branchStatus = branchStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("xid=");
|
||||
result.append(xid);
|
||||
result.append(",");
|
||||
result.append("branchId=");
|
||||
result.append(branchId);
|
||||
result.append(",");
|
||||
result.append("branchStatus=");
|
||||
result.append(branchStatus);
|
||||
result.append(",");
|
||||
result.append("result code =");
|
||||
result.append(getResultCode());
|
||||
result.append(",");
|
||||
result.append("getMsg =");
|
||||
result.append(getMsg());
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
/**
|
||||
* The type Abstract global end request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractGlobalEndRequest extends AbstractTransactionRequestToTC {
|
||||
|
||||
private String xid;
|
||||
|
||||
/**
|
||||
* The Extra data.
|
||||
*/
|
||||
protected String extraData;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra data.
|
||||
*
|
||||
* @return the extra data
|
||||
*/
|
||||
public String getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra data.
|
||||
*
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public void setExtraData(String extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("xid=");
|
||||
result.append(xid);
|
||||
result.append(",");
|
||||
result.append("extraData=");
|
||||
result.append(extraData);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
|
||||
/**
|
||||
* The type Abstract global end response.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractGlobalEndResponse extends AbstractTransactionResponse {
|
||||
|
||||
/**
|
||||
* The Global status.
|
||||
*/
|
||||
protected GlobalStatus globalStatus;
|
||||
|
||||
/**
|
||||
* Gets global status.
|
||||
*
|
||||
* @return the global status
|
||||
*/
|
||||
public GlobalStatus getGlobalStatus() {
|
||||
return globalStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets global status.
|
||||
*
|
||||
* @param globalStatus the global status
|
||||
*/
|
||||
public void setGlobalStatus(GlobalStatus globalStatus) {
|
||||
this.globalStatus = globalStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("globalStatus=");
|
||||
result.append(globalStatus);
|
||||
result.append(",");
|
||||
result.append("ResultCode=");
|
||||
result.append(getResultCode());
|
||||
result.append(",");
|
||||
result.append("Msg=");
|
||||
result.append(getMsg());
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
|
||||
import io.seata.core.protocol.AbstractMessage;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Abstract transaction request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractTransactionRequest extends AbstractMessage {
|
||||
|
||||
/**
|
||||
* Handle abstract transaction response.
|
||||
*
|
||||
* @param rpcContext the rpc context
|
||||
* @return the abstract transaction response
|
||||
*/
|
||||
public abstract AbstractTransactionResponse handle(RpcContext rpcContext);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
|
||||
/**
|
||||
* The type Abstract transaction request to rm.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractTransactionRequestToRM extends AbstractTransactionRequest {
|
||||
|
||||
/**
|
||||
* The Handler.
|
||||
*/
|
||||
protected RMInboundHandler handler;
|
||||
|
||||
/**
|
||||
* Sets rm inbound message handler.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void setRMInboundMessageHandler(RMInboundHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
|
||||
/**
|
||||
* The type Abstract transaction request to tc.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractTransactionRequestToTC extends AbstractTransactionRequest {
|
||||
|
||||
/**
|
||||
* The Handler.
|
||||
*/
|
||||
protected TCInboundHandler handler;
|
||||
|
||||
/**
|
||||
* Sets tc inbound handler.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void setTCInboundHandler(TCInboundHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.AbstractResultMessage;
|
||||
|
||||
/**
|
||||
* The type Abstract transaction response.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public abstract class AbstractTransactionResponse extends AbstractResultMessage {
|
||||
|
||||
private TransactionExceptionCode transactionExceptionCode = TransactionExceptionCode.Unknown;
|
||||
|
||||
/**
|
||||
* Gets transaction exception code.
|
||||
*
|
||||
* @return the transaction exception code
|
||||
*/
|
||||
public TransactionExceptionCode getTransactionExceptionCode() {
|
||||
return transactionExceptionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction exception code.
|
||||
*
|
||||
* @param transactionExceptionCode the transaction exception code
|
||||
*/
|
||||
public void setTransactionExceptionCode(TransactionExceptionCode transactionExceptionCode) {
|
||||
this.transactionExceptionCode = transactionExceptionCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Branch commit request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class BranchCommitRequest extends AbstractBranchEndRequest {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_COMMIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Branch commit response.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class BranchCommitResponse extends AbstractBranchEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_COMMIT_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Branch register request.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public class BranchRegisterRequest extends AbstractTransactionRequestToTC {
|
||||
|
||||
private String xid;
|
||||
|
||||
private BranchType branchType = BranchType.AT;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private String lockKey;
|
||||
|
||||
private String applicationData;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch type.
|
||||
*
|
||||
* @return the branch type
|
||||
*/
|
||||
public BranchType getBranchType() {
|
||||
return branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch type.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
*/
|
||||
public void setBranchType(BranchType branchType) {
|
||||
this.branchType = branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets lock key.
|
||||
*
|
||||
* @return the lock key
|
||||
*/
|
||||
public String getLockKey() {
|
||||
return lockKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets lock key.
|
||||
*
|
||||
* @param lockKey the lock key
|
||||
*/
|
||||
public void setLockKey(String lockKey) {
|
||||
this.lockKey = lockKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource id.
|
||||
*
|
||||
* @return the resource id
|
||||
*/
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource id.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
*/
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_REGISTER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets application data.
|
||||
*
|
||||
* @return the application data
|
||||
*/
|
||||
public String getApplicationData() {
|
||||
return applicationData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets application data.
|
||||
*
|
||||
* @param applicationData the application data
|
||||
*/
|
||||
public void setApplicationData(String applicationData) {
|
||||
this.applicationData = applicationData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("xid=");
|
||||
result.append(xid);
|
||||
result.append(",");
|
||||
result.append("branchType=");
|
||||
result.append(branchType);
|
||||
result.append(",");
|
||||
result.append("resourceId=");
|
||||
result.append(resourceId);
|
||||
result.append(",");
|
||||
result.append("lockKey=");
|
||||
result.append(lockKey);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Branch register response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class BranchRegisterResponse extends AbstractTransactionResponse implements Serializable {
|
||||
|
||||
private long branchId;
|
||||
|
||||
/**
|
||||
* Gets branch id.
|
||||
*
|
||||
* @return the branch id
|
||||
*/
|
||||
public long getBranchId() {
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch id.
|
||||
*
|
||||
* @param branchId the branch id
|
||||
*/
|
||||
public void setBranchId(long branchId) {
|
||||
this.branchId = branchId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_REGISTER_RESULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("BranchRegisterResponse: branchId=");
|
||||
result.append(branchId);
|
||||
result.append(",");
|
||||
result.append("result code =");
|
||||
result.append(getResultCode());
|
||||
result.append(",");
|
||||
result.append("getMsg =");
|
||||
result.append(getMsg());
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Branch report request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class BranchReportRequest extends AbstractTransactionRequestToTC {
|
||||
|
||||
private String xid;
|
||||
|
||||
private long branchId;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private BranchStatus status;
|
||||
|
||||
private String applicationData;
|
||||
|
||||
private BranchType branchType = BranchType.AT;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch id.
|
||||
*
|
||||
* @return the branch id
|
||||
*/
|
||||
public long getBranchId() {
|
||||
return branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch id.
|
||||
*
|
||||
* @param branchId the branch id
|
||||
*/
|
||||
public void setBranchId(long branchId) {
|
||||
this.branchId = branchId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource id.
|
||||
*
|
||||
* @return the resource id
|
||||
*/
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource id.
|
||||
*
|
||||
* @param resourceId the resource id
|
||||
*/
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets branch type.
|
||||
*
|
||||
* @return the branch type
|
||||
*/
|
||||
public BranchType getBranchType() {
|
||||
return branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets branch type.
|
||||
*
|
||||
* @param branchType the branch type
|
||||
*/
|
||||
public void setBranchType(BranchType branchType) {
|
||||
this.branchType = branchType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status.
|
||||
*
|
||||
* @return the status
|
||||
*/
|
||||
public BranchStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status.
|
||||
*
|
||||
* @param status the status
|
||||
*/
|
||||
public void setStatus(BranchStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets application data.
|
||||
*
|
||||
* @return the application data
|
||||
*/
|
||||
public String getApplicationData() {
|
||||
return applicationData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets application data.
|
||||
*
|
||||
* @param applicationData the application data
|
||||
*/
|
||||
public void setApplicationData(String applicationData) {
|
||||
this.applicationData = applicationData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_STATUS_REPORT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("xid=");
|
||||
result.append(xid);
|
||||
result.append(",");
|
||||
result.append("branchId=");
|
||||
result.append(branchId);
|
||||
result.append(",");
|
||||
result.append("resourceId=");
|
||||
result.append(resourceId);
|
||||
result.append(",");
|
||||
result.append("status=");
|
||||
result.append(status);
|
||||
result.append(",");
|
||||
result.append("applicationData=");
|
||||
result.append(applicationData);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Branch report response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class BranchReportResponse extends AbstractTransactionResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Branch rollback request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class BranchRollbackRequest extends AbstractBranchEndRequest {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_ROLLBACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Branch rollback response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class BranchRollbackResponse extends AbstractBranchEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_BRANCH_ROLLBACK_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global begin request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalBeginRequest extends AbstractTransactionRequestToTC {
|
||||
|
||||
private int timeout = 60000;
|
||||
|
||||
private String transactionName;
|
||||
|
||||
/**
|
||||
* Gets timeout.
|
||||
*
|
||||
* @return the timeout
|
||||
*/
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets timeout.
|
||||
*
|
||||
* @param timeout the timeout
|
||||
*/
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets transaction name.
|
||||
*
|
||||
* @return the transaction name
|
||||
*/
|
||||
public String getTransactionName() {
|
||||
return transactionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction name.
|
||||
*
|
||||
* @param transactionName the transaction name
|
||||
*/
|
||||
public void setTransactionName(String transactionName) {
|
||||
this.transactionName = transactionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_BEGIN;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("timeout=");
|
||||
result.append(timeout);
|
||||
result.append(",");
|
||||
result.append("transactionName=");
|
||||
result.append(transactionName);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Global begin response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalBeginResponse extends AbstractTransactionResponse {
|
||||
|
||||
private String xid;
|
||||
|
||||
private String extraData;
|
||||
|
||||
/**
|
||||
* Gets xid.
|
||||
*
|
||||
* @return the xid
|
||||
*/
|
||||
public String getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets xid.
|
||||
*
|
||||
* @param xid the xid
|
||||
*/
|
||||
public void setXid(String xid) {
|
||||
this.xid = xid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra data.
|
||||
*
|
||||
* @return the extra data
|
||||
*/
|
||||
public String getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra data.
|
||||
*
|
||||
* @param extraData the extra data
|
||||
*/
|
||||
public void setExtraData(String extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_BEGIN_RESULT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global commit request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalCommitRequest extends AbstractGlobalEndRequest {
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_COMMIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Global commit response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalCommitResponse extends AbstractGlobalEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_COMMIT_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global lock query request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalLockQueryRequest extends BranchRegisterRequest {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_LOCK_QUERY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
|
||||
/**
|
||||
* The type Global lock query response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalLockQueryResponse extends AbstractTransactionResponse {
|
||||
|
||||
private boolean lockable = false;
|
||||
|
||||
/**
|
||||
* Is lockable boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isLockable() {
|
||||
return lockable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets lockable.
|
||||
*
|
||||
* @param lockable the lockable
|
||||
*/
|
||||
public void setLockable(boolean lockable) {
|
||||
this.lockable = lockable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global report request.
|
||||
*
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class GlobalReportRequest extends AbstractGlobalEndRequest {
|
||||
|
||||
/**
|
||||
* The Global status.
|
||||
*/
|
||||
protected GlobalStatus globalStatus;
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_REPORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets global status.
|
||||
*
|
||||
* @return the global status
|
||||
*/
|
||||
public GlobalStatus getGlobalStatus() {
|
||||
return globalStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets global status.
|
||||
*
|
||||
* @param globalStatus the global status
|
||||
*/
|
||||
public void setGlobalStatus(GlobalStatus globalStatus) {
|
||||
this.globalStatus = globalStatus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Global report response.
|
||||
*
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class GlobalReportResponse extends AbstractGlobalEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_REPORT_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global rollback request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalRollbackRequest extends AbstractGlobalEndRequest {
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_ROLLBACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Global rollback response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalRollbackResponse extends AbstractGlobalEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_ROLLBACK_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The type Global status request.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalStatusRequest extends AbstractGlobalEndRequest {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
return handler.handle(this, rpcContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.protocol.MessageType;
|
||||
|
||||
/**
|
||||
* The type Global status response.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
public class GlobalStatusResponse extends AbstractGlobalEndResponse {
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_GLOBAL_STATUS_RESULT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
/**
|
||||
* The interface Rm inbound handler.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface RMInboundHandler {
|
||||
|
||||
/**
|
||||
* Handle branch commit response.
|
||||
*
|
||||
* @param request the request
|
||||
* @return the branch commit response
|
||||
*/
|
||||
BranchCommitResponse handle(BranchCommitRequest request);
|
||||
|
||||
/**
|
||||
* Handle branch rollback response.
|
||||
*
|
||||
* @param request the request
|
||||
* @return the branch rollback response
|
||||
*/
|
||||
BranchRollbackResponse handle(BranchRollbackRequest request);
|
||||
|
||||
/**
|
||||
* Handle delete undo log .
|
||||
*
|
||||
* @param request the request
|
||||
*/
|
||||
void handle(UndoLogDeleteRequest request);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
* The interface Tc inbound handler.
|
||||
*
|
||||
* @author sharajava
|
||||
*/
|
||||
public interface TCInboundHandler {
|
||||
|
||||
/**
|
||||
* Handle global begin response.
|
||||
*
|
||||
* @param globalBegin the global begin
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global begin response
|
||||
*/
|
||||
GlobalBeginResponse handle(GlobalBeginRequest globalBegin, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle global commit response.
|
||||
*
|
||||
* @param globalCommit the global commit
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global commit response
|
||||
*/
|
||||
GlobalCommitResponse handle(GlobalCommitRequest globalCommit, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle global rollback response.
|
||||
*
|
||||
* @param globalRollback the global rollback
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global rollback response
|
||||
*/
|
||||
GlobalRollbackResponse handle(GlobalRollbackRequest globalRollback, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle branch register response.
|
||||
*
|
||||
* @param branchRegister the branch register
|
||||
* @param rpcContext the rpc context
|
||||
* @return the branch register response
|
||||
*/
|
||||
BranchRegisterResponse handle(BranchRegisterRequest branchRegister, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle branch report response.
|
||||
*
|
||||
* @param branchReport the branch report
|
||||
* @param rpcContext the rpc context
|
||||
* @return the branch report response
|
||||
*/
|
||||
BranchReportResponse handle(BranchReportRequest branchReport, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle global lock query response.
|
||||
*
|
||||
* @param checkLock the check lock
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global lock query response
|
||||
*/
|
||||
GlobalLockQueryResponse handle(GlobalLockQueryRequest checkLock, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle global status response.
|
||||
*
|
||||
* @param globalStatus the global status
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global status response
|
||||
*/
|
||||
GlobalStatusResponse handle(GlobalStatusRequest globalStatus, RpcContext rpcContext);
|
||||
|
||||
/**
|
||||
* Handle global report request.
|
||||
*
|
||||
* @param globalReport the global report request
|
||||
* @param rpcContext the rpc context
|
||||
* @return the global report response
|
||||
*/
|
||||
GlobalReportResponse handle(GlobalReportRequest globalReport, RpcContext rpcContext);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.protocol.transaction;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.MessageType;
|
||||
import io.seata.core.rpc.RpcContext;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type to delete undolog request.
|
||||
*
|
||||
* @author github-ygy
|
||||
*/
|
||||
public class UndoLogDeleteRequest extends AbstractTransactionRequestToRM implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7539732523682335742L;
|
||||
|
||||
public static final short DEFAULT_SAVE_DAYS = 7;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private short saveDays = DEFAULT_SAVE_DAYS;
|
||||
|
||||
/**
|
||||
* The Branch type.
|
||||
*/
|
||||
protected BranchType branchType = BranchType.AT;
|
||||
|
||||
public String getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
public void setResourceId(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public short getSaveDays() {
|
||||
return saveDays;
|
||||
}
|
||||
|
||||
public void setSaveDays(short saveDays) {
|
||||
this.saveDays = saveDays;
|
||||
}
|
||||
|
||||
public BranchType getBranchType() {
|
||||
return branchType;
|
||||
}
|
||||
|
||||
public void setBranchType(BranchType branchType) {
|
||||
this.branchType = branchType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTransactionResponse handle(RpcContext rpcContext) {
|
||||
handler.handle(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getTypeCode() {
|
||||
return MessageType.TYPE_RM_DELETE_UNDOLOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UndoLogDeleteRequest{" +
|
||||
"resourceId='" + resourceId + '\'' +
|
||||
", saveDays=" + saveDays +
|
||||
", branchType=" + branchType +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.rpc;
|
||||
|
||||
import io.seata.core.protocol.RpcMessage;
|
||||
|
||||
/**
|
||||
* The interface Client message listener.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ClientMessageListener {
|
||||
/**
|
||||
* On message.
|
||||
*
|
||||
* @param request the msg id
|
||||
* @param serverAddress the server address
|
||||
*/
|
||||
void onMessage(RpcMessage request, String serverAddress);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.rpc;
|
||||
|
||||
import io.seata.core.protocol.RpcMessage;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* The interface Client message sender.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ClientMessageSender {
|
||||
/**
|
||||
* Send msg with response object.
|
||||
*
|
||||
* @param msg the msg
|
||||
* @param timeout the timeout
|
||||
* @return the object
|
||||
* @throws TimeoutException the timeout exception
|
||||
*/
|
||||
Object sendMsgWithResponse(Object msg, long timeout) throws TimeoutException;
|
||||
|
||||
/**
|
||||
* Send msg with response object.
|
||||
*
|
||||
* @param serverAddress the server address
|
||||
* @param msg the msg
|
||||
* @param timeout the timeout
|
||||
* @return the object
|
||||
* @throws TimeoutException the timeout exception
|
||||
*/
|
||||
Object sendMsgWithResponse(String serverAddress, Object msg, long timeout) throws TimeoutException;
|
||||
|
||||
/**
|
||||
* Send msg with response object.
|
||||
*
|
||||
* @param msg the msg
|
||||
* @return the object
|
||||
* @throws TimeoutException the timeout exception
|
||||
*/
|
||||
Object sendMsgWithResponse(Object msg) throws TimeoutException;
|
||||
|
||||
/**
|
||||
* Send response.
|
||||
*
|
||||
* @param request the msg id
|
||||
* @param serverAddress the server address
|
||||
* @param msg the msg
|
||||
*/
|
||||
void sendResponse(RpcMessage request, String serverAddress, Object msg);
|
||||
}
|
||||
62
core/src/main/java/io/seata/core/rpc/ClientType.java
Normal file
62
core/src/main/java/io/seata/core/rpc/ClientType.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed 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.core.rpc;
|
||||
|
||||
/**
|
||||
* The enum Client type.
|
||||
*
|
||||
* @author slievrly
|
||||
*/
|
||||
@Deprecated
|
||||
public enum ClientType {
|
||||
|
||||
/**
|
||||
* The Tm.
|
||||
*/
|
||||
// Transaction Manager client
|
||||
TM,
|
||||
|
||||
/**
|
||||
* The Rm.
|
||||
*/
|
||||
// Resource Manager client
|
||||
RM;
|
||||
|
||||
/**
|
||||
* Get client type.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the client type
|
||||
*/
|
||||
public static ClientType get(byte ordinal) {
|
||||
return get((int)ordinal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client type.
|
||||
*
|
||||
* @param ordinal the ordinal
|
||||
* @return the client type
|
||||
*/
|
||||
public static ClientType get(int ordinal) {
|
||||
for (ClientType clientType : ClientType.values()) {
|
||||
if (clientType.ordinal() == ordinal) {
|
||||
return clientType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown ClientType[" + ordinal + "]");
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user