use of io.seata.server.session.GlobalSession in project seata by seata.
the class WriteStoreMultithreadTest method main.
public static void main(String[] args) throws Exception {
TransactionStoreManager transactionStoreManager = new FileTransactionStoreManager("data", new SessionManager() {
@Override
public void destroy() {
}
@Override
public void addGlobalSession(GlobalSession session) throws TransactionException {
}
@Override
public GlobalSession findGlobalSession(String xid) {
return null;
}
@Override
public GlobalSession findGlobalSession(String xid, boolean withBranchSessions) {
return null;
}
@Override
public void updateGlobalSessionStatus(GlobalSession session, GlobalStatus status) throws TransactionException {
}
@Override
public void removeGlobalSession(GlobalSession session) throws TransactionException {
}
@Override
public void addBranchSession(GlobalSession globalSession, BranchSession session) throws TransactionException {
}
@Override
public void updateBranchSessionStatus(BranchSession session, BranchStatus status) throws TransactionException {
}
@Override
public void removeBranchSession(GlobalSession globalSession, BranchSession session) throws TransactionException {
}
@Override
public Collection<GlobalSession> allSessions() {
return null;
}
@Override
public List<GlobalSession> findGlobalSessions(SessionCondition condition) {
List<GlobalSession> globalSessions = new ArrayList<>();
int begin = 10000;
int num = 1000;
for (int i = begin; i < begin + num; i++) {
BranchSession branchSession1 = new BranchSession();
branchSession1.setTransactionId(i);
branchSession1.setBranchId(begin + num + (i - begin) * 2);
branchSession1.setResourceId("mockDbkeY1");
BranchSession branchSession2 = new BranchSession();
branchSession2.setTransactionId(i);
branchSession2.setBranchId(begin + num + (i - begin) * 2 + 1);
branchSession2.setResourceId("mockDbkeY2");
GlobalSession globalSession = new GlobalSession(appname, vgroup, instname, 60000);
try {
globalSession.add(branchSession1);
globalSession.add(branchSession2);
globalSessions.add(globalSession);
} catch (Exception exx) {
}
}
return globalSessions;
}
@Override
public <T> T lockAndExecute(GlobalSession globalSession, GlobalSession.LockCallable<T> lockCallable) throws TransactionException {
return null;
}
@Override
public void onBegin(GlobalSession globalSession) throws TransactionException {
}
@Override
public void onStatusChange(GlobalSession globalSession, GlobalStatus status) throws TransactionException {
}
@Override
public void onBranchStatusChange(GlobalSession globalSession, BranchSession branchSession, BranchStatus status) throws TransactionException {
}
@Override
public void onAddBranch(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
}
@Override
public void onRemoveBranch(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
}
@Override
public void onClose(GlobalSession globalSession) throws TransactionException {
}
@Override
public void onEnd(GlobalSession globalSession) throws TransactionException {
}
});
long beginWriteMills = System.currentTimeMillis();
for (int i = 0; i < threadNum; i++) {
final int threadNo = i;
Thread thread = new Thread(() -> {
write(transactionStoreManager, threadNo);
});
thread.start();
}
countDownLatch.await();
long endWriteMills = System.currentTimeMillis();
System.out.println("thread nums:" + threadNum + ", per_thread_trx_num:" + per_thread_trx_num + " ,cost" + (endWriteMills - beginWriteMills));
}
use of io.seata.server.session.GlobalSession in project seata by seata.
the class DefaultCoreTest method releaseSessionManager.
/**
* Release session manager.
*
* @throws Exception the exception
*/
@AfterEach
public void releaseSessionManager() throws Exception {
Collection<GlobalSession> globalSessions = SessionHolder.getRootSessionManager().allSessions();
Collection<GlobalSession> asyncGlobalSessions = SessionHolder.getAsyncCommittingSessionManager().allSessions();
for (GlobalSession asyncGlobalSession : asyncGlobalSessions) {
asyncGlobalSession.closeAndClean();
}
for (GlobalSession globalSession : globalSessions) {
globalSession.closeAndClean();
}
}
use of io.seata.server.session.GlobalSession in project seata by seata.
the class SessionConverter method convertGlobalSession.
public static GlobalSession convertGlobalSession(GlobalTransactionDO globalTransactionDO) {
if (globalTransactionDO == null) {
return null;
}
GlobalSession session = new GlobalSession(globalTransactionDO.getApplicationId(), globalTransactionDO.getTransactionServiceGroup(), globalTransactionDO.getTransactionName(), globalTransactionDO.getTimeout());
session.setXid(globalTransactionDO.getXid());
session.setTransactionId(globalTransactionDO.getTransactionId());
session.setStatus(GlobalStatus.get(globalTransactionDO.getStatus()));
session.setApplicationData(globalTransactionDO.getApplicationData());
session.setBeginTime(globalTransactionDO.getBeginTime());
return session;
}
use of io.seata.server.session.GlobalSession in project seata by seata.
the class SessionConverter method convertGlobalTransactionDO.
public static GlobalTransactionDO convertGlobalTransactionDO(SessionStorable session) {
if (session == null || !(session instanceof GlobalSession)) {
throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
}
GlobalSession globalSession = (GlobalSession) session;
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid(globalSession.getXid());
globalTransactionDO.setStatus(globalSession.getStatus().getCode());
globalTransactionDO.setApplicationId(globalSession.getApplicationId());
globalTransactionDO.setBeginTime(globalSession.getBeginTime());
globalTransactionDO.setTimeout(globalSession.getTimeout());
globalTransactionDO.setTransactionId(globalSession.getTransactionId());
globalTransactionDO.setTransactionName(globalSession.getTransactionName());
globalTransactionDO.setTransactionServiceGroup(globalSession.getTransactionServiceGroup());
globalTransactionDO.setApplicationData(globalSession.getApplicationData());
return globalTransactionDO;
}
use of io.seata.server.session.GlobalSession in project XHuiCloud by sindaZeng.
the class DataBaseTransactionStoreManager method readSession.
@Override
public List<GlobalSession> readSession(SessionCondition sessionCondition) {
if (StringUtils.isNotBlank(sessionCondition.getXid())) {
GlobalSession globalSession = readSession(sessionCondition.getXid());
if (globalSession != null) {
List<GlobalSession> globalSessions = new ArrayList<>();
globalSessions.add(globalSession);
return globalSessions;
}
} else if (sessionCondition.getTransactionId() != null) {
GlobalSession globalSession = readSession(sessionCondition.getTransactionId());
if (globalSession != null) {
List<GlobalSession> globalSessions = new ArrayList<>();
globalSessions.add(globalSession);
return globalSessions;
}
} else if (CollectionUtils.isNotEmpty(sessionCondition.getStatuses())) {
return readSession(sessionCondition.getStatuses());
}
return null;
}
Aggregations