Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
huabao.fang committed Jul 13, 2022
1 parent 6cb0b53 commit bbe447c
Show file tree
Hide file tree
Showing 85 changed files with 7,307 additions and 6,094 deletions.
1 change: 0 additions & 1 deletion tcc-transaction-admin-web/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import {Provider} from 'react-redux';
import {HashRouter as Router, Redirect, Route, Switch} from 'react-router-dom';
import 'antd/dist/antd.css';
Expand Down
1 change: 0 additions & 1 deletion tcc-transaction-admin-web/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import {render} from '@testing-library/react';
import App from './App';

Expand Down
8 changes: 4 additions & 4 deletions tcc-transaction-admin-web/src/common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ export function getAllDomains() {
}

export function domainCreate(params) {
return http.post("/tcc-transaction-dashboard/api/domain/create",{
return http.post("/tcc-transaction-dashboard/api/domain/create", {
...params
});
}

export function domainModify(params) {
return http.post("/tcc-transaction-dashboard/api/domain/modify",{
return http.post("/tcc-transaction-dashboard/api/domain/modify", {
...params
});
}

export function domainDelete(params) {
return http.post("/tcc-transaction-dashboard/api/domain/delete",{
return http.post("/tcc-transaction-dashboard/api/domain/delete", {
...params
});
}

export function domainAlertTest(params) {
return http.post("/tcc-transaction-dashboard/api/domain/alertTest",{
return http.post("/tcc-transaction-dashboard/api/domain/alertTest", {
...params
});
}
Expand Down
39 changes: 19 additions & 20 deletions tcc-transaction-admin-web/src/common/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import {Button, message} from 'antd';

// createTime: "2022-05-18T01:09:22.000+0000"
Expand All @@ -15,25 +14,25 @@ const xidRender = (text, record) => {
newText = String(text).substr(0, 40).concat("...");
}
return (
<div>
{newText}
<Button
className="button"
size="small"
type="primary"
style={{backgroundColor: '#03cee0', borderColor: '#03cee0'}}
onClick={() => {
let oInput = document.createElement('input')
oInput.value = text;
document.body.appendChild(oInput)
oInput.select() // 选择对象
document.execCommand("Copy") // 执行浏览器复制命令
message.success('复制成功');
oInput.remove()
}}>
复制
</Button>
</div>
<div>
{newText}
<Button
className="button"
size="small"
type="primary"
style={{backgroundColor: '#03cee0', borderColor: '#03cee0'}}
onClick={() => {
let oInput = document.createElement('input')
oInput.value = text;
document.body.appendChild(oInput)
oInput.select() // 选择对象
document.execCommand("Copy") // 执行浏览器复制命令
message.success('复制成功');
oInput.remove()
}}>
复制
</Button>
</div>
);
};
export const columns = [
Expand Down
4 changes: 2 additions & 2 deletions tcc-transaction-admin-web/src/common/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {message} from "antd";

// create an axios instance
const http = axios.create({
baseURL: process.env.REACT_APP_ENV==='test'?"http://localhost:22332":"",
baseURL: process.env.REACT_APP_ENV === 'test' ? "http://localhost:22332" : "",
timeout: 20000 // request timeout
})

Expand Down Expand Up @@ -46,7 +46,7 @@ http.interceptors.response.use(
let businessResponse = response.data;
if (!response.status || response.status !== 200) {
errorMessage = RESPONSE_DEFAULT_ERROR_MESSAGE;
} else if(response.status === 401){
} else if (response.status === 401) {
errorMessage = '请先登录';
} else if (businessResponse.code && businessResponse.code !== 200 && businessResponse.code !== '200') {
errorMessage = businessResponse.code + '-' + businessResponse.message || 'Error'
Expand Down
1 change: 0 additions & 1 deletion tcc-transaction-admin-web/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import * as serviceWorker from './serviceWorker';
Expand Down
12 changes: 9 additions & 3 deletions tcc-transaction-admin-web/src/pages/tcc/domain/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ const Page = (props) => {
<Form.Item
label="phoneNumbers"
name="phoneNumbers"
rules={[{pattern: "[1-9][0-9]{10}(,[1-9][0-9]{10}){0,20}$", message: '手机号列表格式有误,形如:12345678901,12345678902'}]}>
rules={[{
pattern: "[1-9][0-9]{10}(,[1-9][0-9]{10}){0,20}$",
message: '手机号列表格式有误,形如:12345678901,12345678902'
}]}>
<Input/>
</Form.Item>
<Form.Item
Expand All @@ -290,7 +293,7 @@ const Page = (props) => {
label="告警阈值"
name="threshold"
rules={[{pattern: "[0-9]+", message: '必须为整数'}]}>
<Input/>
<Input/>
</Form.Item>
<Form.Item
label="告警间隔(分钟)"
Expand Down Expand Up @@ -332,7 +335,10 @@ const Page = (props) => {
label="phoneNumbers"
initialValue={waitModifyDomain.phoneNumbers}
name="phoneNumbers"
rules={[{pattern: "[1-9][0-9]{10}(,[1-9][0-9]{10}){0,20}$", message: '手机号列表格式有误,形如:12345678901,12345678902'}]}>
rules={[{
pattern: "[1-9][0-9]{10}(,[1-9][0-9]{10}){0,20}$",
message: '手机号列表格式有误,形如:12345678901,12345678902'
}]}>
<Input/>
</Form.Item>
<Form.Item
Expand Down
2 changes: 1 addition & 1 deletion tcc-transaction-admin-web/src/pages/tcc/task/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from 'react';
import {getAllTask, taskDelete, taskModifyCron, taskPause, taskResume} from '../../../common/api';
import {getAllTask, taskModifyCron, taskPause, taskResume} from '../../../common/api';
import {Button, Col, Form, Input, message, Modal, Popconfirm, Row, Space, Table} from 'antd';


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import React from 'react';
import {Button, Form, Input, Select} from 'antd';
import {useDispatch, useSelector} from 'react-redux';
import {Domain} from '../../../store/actions/domain';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ const TableCard = (props) => {
reloadHandler(Promise.all(resultPromiseList));
};

const contentFormat = (content)=>{
try{
const contentFormat = (content) => {
try {
return JSON.parse(content)
}catch (e){
return {'content':content};
} catch (e) {
return {'content': content};
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ const TableCard = (props) => {
}

<Space size="small" style={{float: "right"}}>
<Tag color="#f50">总数:{total>fetchNum?total+', 仅显示'+fetchNum+'条':total}</Tag>
<Tag color="#f50">总数:{total > fetchNum ? total + ', 仅显示' + fetchNum + '条' : total}</Tag>
</Space>
<Table
rowKey={record => record.xidString}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void channelUnregistered(ChannelHandlerContext ctx) {

Set<Channel> channels = FactoryBuilder.factoryOf(ChannelGroupMap.class).getInstance().getAllChannels(domain);

if(channels == null) {
if (channels == null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
**/
public class AlertManager {

private static final String ALERT_CONTENT_TEMPLATE = "【TCC告警】\n" +
"Domain: $domain$\n" +
"当前TCC事件堆积数:$errorCount$,超过阈值: $threshold$\n" +
"告警间隔时间为$intervalMinutes$分钟,请及时处理!";
private static Logger logger = LoggerFactory.getLogger(AlertManager.class);

/**
Expand All @@ -30,7 +34,7 @@ public class AlertManager {
public static void tryAlert(String domain, int currentErrorTransactionCount, TransactionStorage transactionStorage) {
DomainStore domainStore = ((StorageRecoverable) transactionStorage).findDomain(domain);
if (domainStore == null) {
logger.warn("domainStore:{} not exist",domain);
logger.warn("domainStore:{} not exist", domain);
return;
}

Expand All @@ -48,11 +52,6 @@ public static void tryAlert(String domain, int currentErrorTransactionCount, Tra

}

private static final String ALERT_CONTENT_TEMPLATE = "【TCC告警】\n" +
"Domain: $domain$\n" +
"当前TCC事件堆积数:$errorCount$,超过阈值: $threshold$\n" +
"告警间隔时间为$intervalMinutes$分钟,请及时处理!";

private static String buildAlertContent(int currentErrorTransactionCount, DomainStore currentDomainStore) {
return ALERT_CONTENT_TEMPLATE.replace("$domain$", currentDomainStore.getDomain())
.replace("$errorCount$", String.valueOf(currentErrorTransactionCount))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class MixAll {

public final static String DOMAIN ="DOMAIN";
public final static String DOMAIN = "DOMAIN";
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public static ResponseDto returnResponse(ResponseCodeEnum responseCode, Object d
return new ResponseDto(responseCode.getCode(), responseCode.getMessage(), data);
}

public boolean isSuccess(){
public boolean isSuccess() {
return ResponseCodeEnum.SUCCESS.getCode().equals(this.code);
}

public String getCode() {
return code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @Author huabao.fang
* @Date 2022/5/30 10:09
**/
public interface DomainService extends TransactionStorageable{
public interface DomainService extends TransactionStorageable {

public ResponseDto<List<String>> getAllDomainKeys();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @Author huabao.fang
* @Date 2022/5/30 10:08
**/
public interface TransactionService extends TransactionStorageable{
public interface TransactionService extends TransactionStorageable {

/**
* 事件分页查询
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ private DomainStore transferToNewDomainStore(DomainStoreRequestDto requestDto, D
private List<DomainStoreDto> transferToDomainStoreDtoList(List<DomainStore> domainStoreList) {
List<DomainStoreDto> domainStoreDtoList = new ArrayList<>(domainStoreList.size());
domainStoreList.sort(((d1, d2) -> {//按更新时间降序
return -1*(d1.getLastUpdateTime().compareTo(d2.getLastUpdateTime()));
return -1 * (d1.getLastUpdateTime().compareTo(d2.getLastUpdateTime()));
}));
for (DomainStore domainStore : domainStoreList) {
domainStoreDtoList.add(transferToDomainStoreDto(domainStore));
}
domainStoreDtoList.sort((d1,d2)->{
return -1*d1.getCreateTime().compareTo(d2.getCreateTime());
domainStoreDtoList.sort((d1, d2) -> {
return -1 * d1.getCreateTime().compareTo(d2.getCreateTime());
});
return domainStoreDtoList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ private List<TransactionStoreDto> toTransactionStoreDtoList(List<TransactionStor
transactionStoreList.forEach(transactionStore -> {
transactionStoreDtoList.add(toTransactionStoreDto(transactionStore));
});
transactionStoreDtoList.sort((t1,t2)->{
return -1*t1.getCreateTime().compareTo(t2.getCreateTime());
transactionStoreDtoList.sort((t1, t2) -> {
return -1 * t1.getCreateTime().compareTo(t2.getCreateTime());
});
return transactionStoreDtoList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Nervose.Wu
* @date 2022/7/7 17:34
*/
public interface ClientRegistryConfig extends RegistryConfig{
public interface ClientRegistryConfig extends RegistryConfig {

String getLoadBalanceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import org.mengyun.tcctransaction.remoting.protocol.RemotingCommand;
import org.mengyun.tcctransaction.remoting.protocol.RemotingCommandCode;
import org.mengyun.tcctransaction.serializer.TransactionStoreSerializer;
import org.mengyun.tcctransaction.storage.StorageRecoverable;
import org.mengyun.tcctransaction.storage.TransactionStorage;
import org.mengyun.tcctransaction.storage.TransactionStore;
import org.mengyun.tcctransaction.storage.domain.DomainStore;
import org.mengyun.tcctransaction.support.FactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class StoreProperties implements StoreConfig {
//only used by client
private String transactionSerializerClassName;
private int kryoPoolSize = 512;
private int maxTransactionSize = 16*1024; // 16KB
private int maxTransactionSize = 16 * 1024; // 16KB
private int maxAttempts = 2;
private String domain = "TCC";
private String transactionStorageClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class QuartzRecoveryTask implements Job {

static final Logger logger = LoggerFactory.getLogger(QuartzRecoveryTask.class.getSimpleName());

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
String domain = context.getJobDetail().getJobDataMap().getString(MixAll.DOMAIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
*/
public class RecoveryScheduler {

static final Logger logger = LoggerFactory.getLogger(RecoveryScheduler.class.getSimpleName());

public final static String JOB_NAME = "TCC_JOB_%s";

public final static String TRIGGER_NAME = "TCC_TRIGGER_%s";

static final Logger logger = LoggerFactory.getLogger(RecoveryScheduler.class.getSimpleName());
private RecoveryConfig recoveryConfig;

private Map<String, Scheduler> schedulers = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
public class ReusableConnectionProvider implements ConnectionProvider {

private static final Logger logger = LoggerFactory.getLogger(ReusableConnectionProvider.class.getSimpleName());

private static ComboPooledDataSource instance;
private static AtomicInteger inuseCounter = new AtomicInteger(0);
private String driver;
private String URL;
private String user = "";
Expand All @@ -31,9 +32,6 @@ public class ReusableConnectionProvider implements ConnectionProvider {
private boolean validateOnCheckout = false;
private String validationQuery;

private static ComboPooledDataSource instance;
private static AtomicInteger inuseCounter = new AtomicInteger(0);

public ReusableConnectionProvider() {
logger.debug("one user joined, current inuse counter:{}", inuseCounter.incrementAndGet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
public class ReusableThreadPool implements ThreadPool {

private static final Logger logger = LoggerFactory.getLogger(ReusableThreadPool.class.getSimpleName());

private static SimpleThreadPool instance;
private static AtomicInteger inuseCounter = new AtomicInteger(0);
private int threadCount = -1;
private int threadPriority = Thread.NORM_PRIORITY;
private boolean threadsInheritGroupOfInitializingThread = true;
private boolean threadsInheritContextClassLoaderOfInitializingThread =false;
private boolean threadsInheritContextClassLoaderOfInitializingThread = false;
private boolean makeThreadsDaemons = false;
private String threadNamePrefix;

private static SimpleThreadPool instance;
private static AtomicInteger inuseCounter = new AtomicInteger(0);

public ReusableThreadPool() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void startRecover(String domain) {
} while (true);

// 告警
AlertManager.tryAlert(domain,totalCount,transactionStorage);
AlertManager.tryAlert(domain, totalCount, transactionStorage);

logger.debug(String.format("total recovery count %d from repository:%s", totalCount, transactionStorage.getClass().getName()));
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class NettyRemotingServer extends AbstractNettyRemoting implements Remoti

public NettyRemotingServer(RemotingCommandSerializer serializer, NettyServerConfig nettyServerConfig) {
this.nettyServerConfig = nettyServerConfig;
this.serializer=serializer;
this.serializer = serializer;
this.serverBootstrap = new ServerBootstrap();

if (useEpoll()) {
Expand Down
Loading

0 comments on commit bbe447c

Please sign in to comment.