Core
继承图
主要实现类
DefaultCore
public class DefaultCore implements Core {
// 存放core集合
private static Map<BranchType, AbstractCore> coreMap = new ConcurrentHashMap<>();
/**
* get the Default core.
*
* @param remotingServer the remoting server
*/
public DefaultCore(RemotingServer remotingServer) { // META-INF/services目录下 io.seata.server.coordinator.AbstractCore
List<AbstractCore> allCore = EnhancedServiceLoader.loadAll(AbstractCore.class,
new Class[]{RemotingServer.class}, new Object[]{remotingServer});
if (CollectionUtils.isNotEmpty(allCore)) {
for (AbstractCore core : allCore) { // ATCore TccCore SagaCore XACore
coreMap.put(core.getHandleBranchType(), core); // 这里放入core
}
}
}
/**
* get core
*
* @param branchType the branchType
* @return the core
*/
public AbstractCore getCore(BranchType branchType) {
AbstractCore core = coreMap.get(branchType);
if (core == null) {
throw new NotSupportYetException("unsupported type:" + branchType.name());
}
return core;
}
io.seata.server.coordinator.AbstractCore文件
文件内容
io.seata.server.transaction.at.ATCore
io.seata.server.transaction.tcc.TccCore
io.seata.server.transaction.saga.SagaCore
io.seata.server.transaction.xa.XACore
ATCore
public class ATCore extends AbstractCore {
public ATCore(RemotingServer remotingServer) {
super(remotingServer);
}
@Override
public BranchType getHandleBranchType() {
return BranchType.AT; // 类型
}
@Override
protected void branchSessionLock(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
if (!branchSession.lock()) {
throw new BranchTransactionException(LockKeyConflict, String
.format("Global lock acquire failed xid = %s branchId = %s", globalSession.getXid(),
branchSession.getBranchId()));
}
}
@Override
protected void branchSessionUnlock(BranchSession branchSession) throws TransactionException {
branchSession.unlock();
}
@Override
public boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys)
throws TransactionException {
return lockManager.isLockable(xid, resourceId, lockKeys);
}
}
TccCore
public class TccCore extends AbstractCore {
public TccCore(RemotingServer remotingServer) {
super(remotingServer);
}
@Override
public BranchType getHandleBranchType() {
return BranchType.TCC;
}
}
XACore
public class XACore extends AbstractCore {
public XACore(RemotingServer remotingServer) {
super(remotingServer);
}
@Override
public BranchType getHandleBranchType() {
return BranchType.XA;
}
@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status,
String applicationData) throws TransactionException {
super.branchReport(branchType, xid, branchId, status, applicationData);
if (BranchStatus.PhaseOne_Failed == status) {
}
}
}
SagaCore
public class SagaCore extends AbstractCore {
public SagaCore(RemotingServer remotingServer) {
super(remotingServer);
}
@Override
public BranchType getHandleBranchType() {
return BranchType.SAGA;
}
.....................
}