return;
}
lock.lock();
try {
String appConfStr = data;
TAtomDsConfDO tmpConf = TAtomConfParser
.parserTAtomDsConfDO(null, appConfStr);
TAtomDsConfDO newConf = TAtomDsConfHandle.this.runTimeConf
.clone();
// ��Щ�������ò��ܱ�������Կ�¡�ϵ����ã�Ȼ���µ�set��ȥ
newConf.setUserName(tmpConf.getUserName());
newConf.setMinPoolSize(tmpConf.getMinPoolSize());
newConf.setMaxPoolSize(tmpConf.getMaxPoolSize());
newConf.setIdleTimeout(tmpConf.getIdleTimeout());
newConf.setBlockingTimeout(tmpConf.getBlockingTimeout());
newConf.setPreparedStatementCacheSize(tmpConf
.getPreparedStatementCacheSize());
newConf.setConnectionProperties(tmpConf
.getConnectionProperties());
newConf.setOracleConType(tmpConf.getOracleConType());
// ����3�������ʵ��
newConf.setWriteRestrictTimes(tmpConf
.getWriteRestrictTimes());
newConf.setReadRestrictTimes(tmpConf.getReadRestrictTimes());
newConf.setThreadCountRestrict(tmpConf
.getThreadCountRestrict());
newConf.setTimeSliceInMillis(tmpConf.getTimeSliceInMillis());
// ��������������
overConfByLocal(TAtomDsConfHandle.this.localConf, newConf);
// ת��tAtomDsConfDO
LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
newConf, TAtomConstants.getDbNameStr(
TAtomDsConfHandle.this.appName,
TAtomDsConfHandle.this.dbKey));
// ���ת�������Ƿ���ȷ
if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
logger.error("[GlobaConfError] dataSource Prams Error! dataId : "
+ dataId + " config : " + data);
return;
}
boolean isNeedReCreate = isNeedReCreate(
TAtomDsConfHandle.this.runTimeConf, newConf);
if (isNeedReCreate) {
try {
TAtomDsConfHandle.this.jbossDataSource.destroy();
logger.warn("[destroy OldDataSource] dataId : "
+ dataId);
LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
.createLocalTxDataSource(localTxDataSourceDO);
logger.warn("[create newDataSource] dataId : "
+ dataId);
TAtomDsConfHandle.this.jbossDataSource = localTxDataSource;
clearDataSourceWrapper();
TAtomDsConfHandle.this.runTimeConf = newConf;
} catch (Exception e) {
logger.error(
"[Flsh AppConf Error] reCreate dataSource Error ! dataId: "
+ dataId, e);
}
} else {
boolean isNeedFlush = isNeedFlush(
TAtomDsConfHandle.this.runTimeConf, newConf);
/**
* ��ֵ�仯����ˢ�³��е�����Դ��ֻҪ����runTimeConf���������wrapDataSource
*/
boolean isRestrictChange = isRestrictChange(
TAtomDsConfHandle.this.runTimeConf, newConf);
if (isNeedFlush) {
TAtomDsConfHandle.this.jbossDataSource
.setConnectionURL(localTxDataSourceDO
.getConnectionURL());
TAtomDsConfHandle.this.jbossDataSource
.setUserName(localTxDataSourceDO
.getUserName());
try {
// ��������Դ
TAtomDsConfHandle.this.flushDataSource();
// �����µ����ø�������ʱ������
TAtomDsConfHandle.this.runTimeConf = newConf;
clearDataSourceWrapper();
} catch (Exception e) {
logger.error(
"[Flash GlobaConf Error] flush dataSource Error !",
e);
}
} else if (isRestrictChange) {
TAtomDsConfHandle.this.runTimeConf = newConf;
clearDataSourceWrapper();
}
}
} finally {
lock.unlock();
}
}
private boolean isNeedReCreate(TAtomDsConfDO runConf,
TAtomDsConfDO newConf) {
boolean needReCreate = false;
if (AtomDbTypeEnum.ORACLE == newConf.getDbTypeEnum()) {
Map<String, String> newProp = newConf
.getConnectionProperties();
Map<String, String> runProp = runConf
.getConnectionProperties();
if (!runProp.equals(newProp)) {
return true;
}
}
if (runConf.getMinPoolSize() != newConf.getMinPoolSize()) {
return true;
}
if (runConf.getMaxPoolSize() != newConf.getMaxPoolSize()) {
return true;
}
if (runConf.getBlockingTimeout() != newConf
.getBlockingTimeout()) {
return true;
}
if (runConf.getIdleTimeout() != newConf.getIdleTimeout()) {
return true;
}
if (runConf.getPreparedStatementCacheSize() != newConf
.getPreparedStatementCacheSize()) {
return true;
}
return needReCreate;
}
private boolean isNeedFlush(TAtomDsConfDO runConf,
TAtomDsConfDO newConf) {
boolean needFlush = false;
if (AtomDbTypeEnum.MYSQL == newConf.getDbTypeEnum()) {
Map<String, String> newProp = newConf
.getConnectionProperties();
Map<String, String> runProp = runConf
.getConnectionProperties();
if (!runProp.equals(newProp)) {
return true;
}
}
if (!TStringUtil.equals(runConf.getUserName(),
newConf.getUserName())) {
return true;
}
if (!TStringUtil.equals(runConf.getPasswd(), newConf.getPasswd())) {
return true;
}
return needFlush;
}
private boolean isRestrictChange(TAtomDsConfDO runConf,
TAtomDsConfDO newConf) {
if (runConf.getReadRestrictTimes() != newConf
.getReadRestrictTimes()) {
return true;
}
if (runConf.getWriteRestrictTimes() != newConf
.getWriteRestrictTimes()) {
return true;
}
if (runConf.getThreadCountRestrict() != newConf
.getThreadCountRestrict()) {
return true;
}
if (runConf.getTimeSliceInMillis() != newConf
.getTimeSliceInMillis()) {
return true;
}
return false;