Search in sources :

Example 1 with RmTransactionException

use of io.seata.core.exception.RmTransactionException in project seata by seata.

the class AbstractResourceManager method branchReport.

/**
 * report branch status
 *
 * @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  TransactionException
 */
@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
    try {
        BranchReportRequest request = new BranchReportRequest();
        request.setXid(xid);
        request.setBranchId(branchId);
        request.setStatus(status);
        request.setApplicationData(applicationData);
        BranchReportResponse response = (BranchReportResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
        if (response.getResultCode() == ResultCode.Failed) {
            throw new RmTransactionException(response.getTransactionExceptionCode(), String.format("Response[ %s ]", response.getMsg()));
        }
    } catch (TimeoutException toe) {
        throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
    } catch (RuntimeException rex) {
        throw new RmTransactionException(TransactionExceptionCode.BranchReportFailed, "Runtime", rex);
    }
}
Also used : RmTransactionException(io.seata.core.exception.RmTransactionException) BranchReportRequest(io.seata.core.protocol.transaction.BranchReportRequest) BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with RmTransactionException

use of io.seata.core.exception.RmTransactionException in project seata by seata.

the class DataSourceManager method lockQuery.

@Override
public boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys) throws TransactionException {
    GlobalLockQueryRequest request = new GlobalLockQueryRequest();
    request.setXid(xid);
    request.setLockKey(lockKeys);
    request.setResourceId(resourceId);
    try {
        GlobalLockQueryResponse response;
        if (RootContext.inGlobalTransaction() || RootContext.requireGlobalLock()) {
            response = (GlobalLockQueryResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
        } else {
            throw new RuntimeException("unknow situation!");
        }
        if (response.getResultCode() == ResultCode.Failed) {
            throw new TransactionException(response.getTransactionExceptionCode(), "Response[" + response.getMsg() + "]");
        }
        return response.isLockable();
    } catch (TimeoutException toe) {
        throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
    } catch (RuntimeException rex) {
        throw new RmTransactionException(TransactionExceptionCode.LockableCheckFailed, "Runtime", rex);
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryResponse(io.seata.core.protocol.transaction.GlobalLockQueryResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with RmTransactionException

use of io.seata.core.exception.RmTransactionException in project seata by seata.

the class AbstractResourceManager method branchRegister.

/**
 * registry branch record
 *
 * @param branchType the branch type
 * @param resourceId the resource id
 * @param clientId   the client id
 * @param xid        the xid
 * @param lockKeys   the lock keys
 * @return branchId
 * @throws TransactionException TransactionException
 */
@Override
public Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData, String lockKeys) throws TransactionException {
    try {
        BranchRegisterRequest request = new BranchRegisterRequest();
        request.setXid(xid);
        request.setLockKey(lockKeys);
        request.setResourceId(resourceId);
        request.setBranchType(branchType);
        request.setApplicationData(applicationData);
        BranchRegisterResponse response = (BranchRegisterResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
        if (response.getResultCode() == ResultCode.Failed) {
            throw new RmTransactionException(response.getTransactionExceptionCode(), String.format("Response[ %s ]", response.getMsg()));
        }
        return response.getBranchId();
    } catch (TimeoutException toe) {
        throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
    } catch (RuntimeException rex) {
        throw new RmTransactionException(TransactionExceptionCode.BranchRegisterFailed, "Runtime", rex);
    }
}
Also used : BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse) RmTransactionException(io.seata.core.exception.RmTransactionException) BranchRegisterRequest(io.seata.core.protocol.transaction.BranchRegisterRequest) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RmTransactionException (io.seata.core.exception.RmTransactionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 TransactionException (io.seata.core.exception.TransactionException)1 BranchRegisterRequest (io.seata.core.protocol.transaction.BranchRegisterRequest)1 BranchRegisterResponse (io.seata.core.protocol.transaction.BranchRegisterResponse)1 BranchReportRequest (io.seata.core.protocol.transaction.BranchReportRequest)1 BranchReportResponse (io.seata.core.protocol.transaction.BranchReportResponse)1 GlobalLockQueryRequest (io.seata.core.protocol.transaction.GlobalLockQueryRequest)1 GlobalLockQueryResponse (io.seata.core.protocol.transaction.GlobalLockQueryResponse)1