use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class ProtobufInnerSerializer method serializeContent.
public static byte[] serializeContent(Object request) {
Class clazz = request.getClass();
Method method = CollectionUtils.computeIfAbsent(PROTOBUF_HELPER.toByteArrayMethodMap, clazz, key -> {
try {
Method m = clazz.getMethod(METHOD_TOBYTEARRAY);
m.setAccessible(true);
return m;
} catch (Exception e) {
throw new ShouldNeverHappenException("Cannot found method " + clazz.getName() + ".toByteArray(), please check the generated code.", e);
}
});
try {
return (byte[]) method.invoke(request);
} catch (Exception e) {
throw new ShouldNeverHappenException("serialize occurs exception", e);
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class SpringBootConfigurationProvider method get.
private Object get(String dataId) throws IllegalAccessException, InstantiationException {
String propertyPrefix = getPropertyPrefix(dataId);
String propertySuffix = getPropertySuffix(dataId);
ApplicationContext applicationContext = (ApplicationContext) ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_APPLICATION_CONTEXT);
Class<?> propertyClass = PROPERTY_BEAN_MAP.get(propertyPrefix);
Object valueObject = null;
if (propertyClass != null) {
try {
Object propertyBean = applicationContext.getBean(propertyClass);
valueObject = getFieldValue(propertyBean, propertySuffix, dataId);
} catch (NoSuchBeanDefinitionException ignore) {
}
} else {
throw new ShouldNeverHappenException("PropertyClass for prefix: [" + propertyPrefix + "] should not be null.");
}
if (valueObject == null) {
valueObject = getFieldValue(propertyClass.newInstance(), propertySuffix, dataId);
}
return valueObject;
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class ProtobufInnerSerializer method deserializeContent.
public static <T> T deserializeContent(String responseClazz, byte[] content) {
if (content == null || content.length == 0) {
return null;
}
Class clazz = PROTOBUF_HELPER.getPbClass(responseClazz);
Method method = CollectionUtils.computeIfAbsent(PROTOBUF_HELPER.parseFromMethodMap, clazz, key -> {
try {
Method m = clazz.getMethod(METHOD_PARSEFROM, byte[].class);
if (!Modifier.isStatic(m.getModifiers())) {
throw new ShouldNeverHappenException("Cannot found static method " + clazz.getName() + ".parseFrom(byte[]), please check the generated code");
}
m.setAccessible(true);
return m;
} catch (NoSuchMethodException e) {
throw new ShouldNeverHappenException("Cannot found method " + clazz.getName() + ".parseFrom(byte[]), please check the generated code", e);
}
});
try {
return (T) method.invoke(null, content);
} catch (Exception e) {
throw new ShouldNeverHappenException("Error when invoke " + clazz.getName() + ".parseFrom(byte[]).", e);
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class FileSessionManager method restore.
private void restore(List<TransactionWriteStore> stores, Set<String> removedGlobalBuffer, Map<String, Map<Long, BranchSession>> unhandledBranchBuffer) {
for (TransactionWriteStore store : stores) {
TransactionStoreManager.LogOperation logOperation = store.getOperate();
SessionStorable sessionStorable = store.getSessionRequest();
switch(logOperation) {
case GLOBAL_ADD:
case GLOBAL_UPDATE:
{
GlobalSession globalSession = (GlobalSession) sessionStorable;
if (globalSession.getTransactionId() == 0) {
LOGGER.error("Restore globalSession from file failed, the transactionId is zero , xid:" + globalSession.getXid());
break;
}
if (removedGlobalBuffer.contains(globalSession.getXid())) {
break;
}
GlobalSession foundGlobalSession = sessionMap.get(globalSession.getXid());
if (foundGlobalSession == null) {
if (this.checkSessionStatus(globalSession)) {
sessionMap.put(globalSession.getXid(), globalSession);
} else {
removedGlobalBuffer.add(globalSession.getXid());
unhandledBranchBuffer.remove(globalSession.getXid());
}
} else {
if (this.checkSessionStatus(globalSession)) {
foundGlobalSession.setStatus(globalSession.getStatus());
} else {
sessionMap.remove(globalSession.getXid());
removedGlobalBuffer.add(globalSession.getXid());
unhandledBranchBuffer.remove(globalSession.getXid());
}
}
break;
}
case GLOBAL_REMOVE:
{
GlobalSession globalSession = (GlobalSession) sessionStorable;
if (globalSession.getTransactionId() == 0) {
LOGGER.error("Restore globalSession from file failed, the transactionId is zero , xid:" + globalSession.getXid());
break;
}
if (removedGlobalBuffer.contains(globalSession.getXid())) {
break;
}
if (sessionMap.remove(globalSession.getXid()) == null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("GlobalSession To Be Removed Does Not Exists [" + globalSession.getXid() + "]");
}
}
removedGlobalBuffer.add(globalSession.getXid());
unhandledBranchBuffer.remove(globalSession.getXid());
break;
}
case BRANCH_ADD:
case BRANCH_UPDATE:
{
BranchSession branchSession = (BranchSession) sessionStorable;
if (branchSession.getTransactionId() == 0) {
LOGGER.error("Restore branchSession from file failed, the transactionId is zero , xid:" + branchSession.getXid());
break;
}
if (removedGlobalBuffer.contains(branchSession.getXid())) {
break;
}
GlobalSession foundGlobalSession = sessionMap.get(branchSession.getXid());
if (foundGlobalSession == null) {
unhandledBranchBuffer.computeIfAbsent(branchSession.getXid(), key -> new HashMap<>()).put(branchSession.getBranchId(), branchSession);
} else {
BranchSession existingBranch = foundGlobalSession.getBranch(branchSession.getBranchId());
if (existingBranch == null) {
foundGlobalSession.add(branchSession);
} else {
existingBranch.setStatus(branchSession.getStatus());
}
}
break;
}
case BRANCH_REMOVE:
{
BranchSession branchSession = (BranchSession) sessionStorable;
String xid = branchSession.getXid();
if (removedGlobalBuffer.contains(xid)) {
break;
}
long bid = branchSession.getBranchId();
if (branchSession.getTransactionId() == 0) {
LOGGER.error("Restore branchSession from file failed, the transactionId is zero , xid:" + branchSession.getXid());
break;
}
GlobalSession found = sessionMap.get(xid);
if (found == null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("GlobalSession To Be Updated (Remove Branch) Does Not Exists [" + bid + "/" + xid + "]");
}
} else {
BranchSession theBranch = found.getBranch(bid);
if (theBranch == null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("BranchSession To Be Updated Does Not Exists [" + bid + "/" + xid + "]");
}
} else {
found.remove(theBranch);
}
}
break;
}
default:
throw new ShouldNeverHappenException("Unknown Operation: " + logOperation);
}
}
}
use of io.seata.common.exception.ShouldNeverHappenException in project seata by seata.
the class SessionHolder method queueToAsyncCommitting.
private static void queueToAsyncCommitting(GlobalSession globalSession) {
try {
globalSession.addSessionLifecycleListener(getAsyncCommittingSessionManager());
getAsyncCommittingSessionManager().addGlobalSession(globalSession);
} catch (TransactionException e) {
throw new ShouldNeverHappenException(e);
}
}
Aggregations