use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class StringUtils method inputStream2String.
/**
* Input stream 2 string string.
*
* @param is the is
* @return the string
*/
public static String inputStream2String(InputStream is) {
if (is == null) {
return null;
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = is.read()) != -1) {
baos.write(i);
}
return baos.toString(Constants.DEFAULT_CHARSET_NAME);
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class StringUtils method inputStream2Bytes.
/**
* Input stream to byte array
*
* @param is the is
* @return the byte array
*/
public static byte[] inputStream2Bytes(InputStream is) {
if (is == null) {
return null;
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = is.read()) != -1) {
baos.write(i);
}
return baos.toByteArray();
} catch (Exception e) {
throw new ShouldNeverHappenException(e);
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class ConfigFuture method get.
/**
* Get object.
*
* @param timeout the timeout
* @param unit the unit
* @return the object
*/
public Object get(long timeout, TimeUnit unit) {
this.timeoutMills = unit.toMillis(timeout);
Object result;
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) {
LOGGER.error("config operation timeout,cost:{} ms,op:{},dataId:{}", System.currentTimeMillis() - start, operation.name(), dataId);
return getFailResult();
} catch (InterruptedException exx) {
LOGGER.error("config operate interrupted,error:{}", exx.getMessage(), exx);
return getFailResult();
}
if (operation == ConfigOperation.GET) {
return result == null ? content : result;
} else {
return result == null ? Boolean.FALSE : result;
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class PostgresqlUndoInsertExecutor method buildUndoSQL.
@Override
protected String buildUndoSQL() {
TableRecords afterImage = sqlUndoLog.getAfterImage();
List<Row> afterImageRows = afterImage.getRows();
if (CollectionUtils.isEmpty(afterImageRows)) {
throw new ShouldNeverHappenException("Invalid UNDO LOG");
}
return generateDeleteSql(afterImageRows, afterImage);
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class TCCResourceManager method branchCommit.
/**
* TCC branch commit
*
* @param branchType
* @param xid Transaction id.
* @param branchId Branch id.
* @param resourceId Resource id.
* @param applicationData Application data bind with this branch.
* @return BranchStatus
* @throws TransactionException TransactionException
*/
@Override
public BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException {
TCCResource tccResource = (TCCResource) tccResourceCache.get(resourceId);
if (tccResource == null) {
throw new ShouldNeverHappenException(String.format("TCC resource is not exist, resourceId: %s", resourceId));
}
Object targetTCCBean = tccResource.getTargetBean();
Method commitMethod = tccResource.getCommitMethod();
if (targetTCCBean == null || commitMethod == null) {
throw new ShouldNeverHappenException(String.format("TCC resource is not available, resourceId: %s", resourceId));
}
try {
// BusinessActionContext
BusinessActionContext businessActionContext = getBusinessActionContext(xid, branchId, resourceId, applicationData);
Object ret = commitMethod.invoke(targetTCCBean, businessActionContext);
LOGGER.info("TCC resource commit result : {}, xid: {}, branchId: {}, resourceId: {}", ret, xid, branchId, resourceId);
boolean result;
if (ret != null) {
if (ret instanceof TwoPhaseResult) {
result = ((TwoPhaseResult) ret).isSuccess();
} else {
result = (boolean) ret;
}
} else {
result = true;
}
return result ? BranchStatus.PhaseTwo_Committed : BranchStatus.PhaseTwo_CommitFailed_Retryable;
} catch (Throwable t) {
String msg = String.format("commit TCC resource error, resourceId: %s, xid: %s.", resourceId, xid);
LOGGER.error(msg, t);
return BranchStatus.PhaseTwo_CommitFailed_Retryable;
}
}
Aggregations