use of io.seata.core.protocol.transaction.BranchReportRequest in project seata by seata.
the class AbstractTCInboundHandler method handle.
@Override
public BranchReportResponse handle(BranchReportRequest request, final RpcContext rpcContext) {
BranchReportResponse response = new BranchReportResponse();
exceptionHandleTemplate(new AbstractCallback<BranchReportRequest, BranchReportResponse>() {
@Override
public void execute(BranchReportRequest request, BranchReportResponse response) throws TransactionException {
try {
doBranchReport(request, response, rpcContext);
} catch (StoreException e) {
throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("branch report request failed. xid=%s, branchId=%s, msg=%s", request.getXid(), request.getBranchId(), e.getMessage()), e);
}
}
}, request, response);
return response;
}
use of io.seata.core.protocol.transaction.BranchReportRequest in project seata by seata.
the class BranchReportRequestSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
BranchReportRequest branchReportRequest = new BranchReportRequest();
branchReportRequest.setBranchId(1346);
branchReportRequest.setBranchType(BranchType.TCC);
branchReportRequest.setApplicationData("acds");
branchReportRequest.setResourceId("aaa");
branchReportRequest.setStatus(BranchStatus.PhaseOne_Done);
branchReportRequest.setXid("abc123");
byte[] bytes = seataSerializer.serialize(branchReportRequest);
BranchReportRequest branchReportRequest2 = seataSerializer.deserialize(bytes);
assertThat(branchReportRequest2.getBranchId()).isEqualTo(branchReportRequest.getBranchId());
assertThat(branchReportRequest2.getBranchType()).isEqualTo(branchReportRequest.getBranchType());
assertThat(branchReportRequest2.getApplicationData()).isEqualTo(branchReportRequest.getApplicationData());
assertThat(branchReportRequest2.getResourceId()).isEqualTo(branchReportRequest.getResourceId());
assertThat(branchReportRequest2.getStatus()).isEqualTo(branchReportRequest.getStatus());
assertThat(branchReportRequest2.getXid()).isEqualTo(branchReportRequest.getXid());
}
use of io.seata.core.protocol.transaction.BranchReportRequest 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);
}
}
use of io.seata.core.protocol.transaction.BranchReportRequest in project seata by seata.
the class BranchReportRequestCodec method encode.
@Override
public <T> void encode(T t, ByteBuf out) {
BranchReportRequest branchReportRequest = (BranchReportRequest) t;
String xid = branchReportRequest.getXid();
long branchId = branchReportRequest.getBranchId();
BranchStatus status = branchReportRequest.getStatus();
String resourceId = branchReportRequest.getResourceId();
String applicationData = branchReportRequest.getApplicationData();
BranchType branchType = branchReportRequest.getBranchType();
byte[] applicationDataBytes = null;
if (applicationData != null) {
applicationDataBytes = applicationData.getBytes(UTF8);
}
// 1. xid
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short) bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short) 0);
}
// 2. Branch Id
out.writeLong(branchId);
// 3. Branch Status
out.writeByte(status.getCode());
// 4. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short) bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short) 0);
}
// 5. Application Data
if (applicationData != null) {
out.writeInt(applicationDataBytes.length);
if (applicationDataBytes.length > 0) {
out.writeBytes(applicationDataBytes);
}
} else {
out.writeInt(0);
}
// 6. branchType
out.writeByte(branchType.ordinal());
}
use of io.seata.core.protocol.transaction.BranchReportRequest in project seata by seata.
the class BranchReportRequestCodec method decode.
@Override
public <T> void decode(T t, ByteBuffer in) {
BranchReportRequest branchReportRequest = (BranchReportRequest) t;
short xidLen = in.getShort();
if (xidLen > 0) {
byte[] bs = new byte[xidLen];
in.get(bs);
branchReportRequest.setXid(new String(bs, UTF8));
}
branchReportRequest.setBranchId(in.getLong());
branchReportRequest.setStatus(BranchStatus.get(in.get()));
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
branchReportRequest.setResourceId(new String(bs, UTF8));
}
int iLen = in.getInt();
if (iLen > 0) {
byte[] bs = new byte[iLen];
in.get(bs);
branchReportRequest.setApplicationData(new String(bs, UTF8));
}
branchReportRequest.setBranchType(BranchType.get(in.get()));
}
Aggregations