本文整理匯總了Java中com.taobao.tddl.config.ConfigDataHandler類的典型用法代碼示例。如果您正苦於以下問題:Java ConfigDataHandler類的具體用法?Java ConfigDataHandler怎麽用?Java ConfigDataHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ConfigDataHandler類屬於com.taobao.tddl.config包,在下文中一共展示了ConfigDataHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doDestroy
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
protected void doDestroy() throws TddlException {
Map<String, IRepository> repos = repositoryHolder.getRepository();
for (IRepository repo : repos.values()) {
repo.destroy();
}
if (topologyFileHandler != null) {
topologyFileHandler.destroy();
}
for (ConfigDataHandler cdh : cdhs.asMap().values()) {
cdh.destroy();
}
cdhs.cleanUp();
}
示例2: loadUser
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
private synchronized void loadUser(final String app) throws ExecutionException, TddlException {
String dataId = DATAID_PREFIX + this.cluster + "." + app + DATAID_SUFFIX;
ConfigDataHandler cdh = getConfigDataHandler(app, dataId);
String config = cdh.getData();
if (StringUtil.isEmpty(config)) {
cdhs.invalidate(dataId);
cdh.destroy();
// 重新拿一下新的dataId
String newDataId = DATAID_PREFIX + app + DATAID_SUFFIX;
cdh = getConfigDataHandler(app, newDataId);
config = cdh.getData();
}
this.parseConfig(dataId, app, config);
}
示例3: unLoadUser
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
private synchronized void unLoadUser(final String app) throws TddlException {
String dataId = DATAID_PREFIX + this.cluster + "." + app + DATAID_SUFFIX;
ConfigDataHandler cdh = cdhs.getIfPresent(dataId);
if (cdh != null) {
cdh.destroy();
cdhs.invalidate(dataId);
}
String newDataId = DATAID_PREFIX + app + DATAID_SUFFIX;
cdh = cdhs.getIfPresent(newDataId);
if (cdh != null) {
cdh.destroy();
cdhs.invalidate(dataId);
}
users.remove(app);
}
示例4: getConfigDataHandler
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
public ConfigDataHandler getConfigDataHandler(String dataId, List<ConfigDataListener> configDataListenerList,
Executor executor, Map<String, Object> config) {
// 獲取config data handler的擴展實現
PreheatDataHandler instance = new PreheatDataHandler();
instance.setUnitName(unitName);
instance.setAppName(appName);
instance.setDataId(dataId);
instance.setListeners(clearNullListener(configDataListenerList));
instance.setConfig(config);
try {
instance.init();// 啟動
} catch (TddlException e) {
throw new TddlNestableRuntimeException(e);
}
return instance;
}
示例5: getConfigDataHandler
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
public ConfigDataHandler getConfigDataHandler(String dataId, ConfigDataListener configDataListener) {
String key = combineDataKey(appName, dataId);
ConfigDataHandler configDataHandler = filePath.get(key);
if (configDataHandler == null) {
synchronized (this) {
configDataHandler = filePath.get(key);
// dcl
if (configDataHandler == null) {
configDataHandler = new FileConfigDataHandler(appName,
executor,
configure_prefix,
directory,
dataId,
configDataListener);
ConfigDataHandler tempCdh = filePath.putIfAbsent(key, configDataHandler);
if (tempCdh != null) {
configDataHandler = tempCdh;
}
}
}
}
configDataHandler.addListener(configDataListener, null);
return configDataHandler;
}
示例6: getConfigDataHandler
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
public ConfigDataHandler getConfigDataHandler(String dataId, List<ConfigDataListener> configDataListenerList,
Executor executor, Map<String, Object> config) {
// 獲取config data handler的擴展實現
PreheatDataHandler instance = new PreheatDataHandler();
instance.setUnitName(unitName);
instance.setAppName(appName);
instance.setDataId(dataId);
instance.setListeners(clearNullListener(configDataListenerList));
instance.setConfig(config);
try {
instance.init();// 啟動
} catch (TddlException e) {
throw new TddlRuntimeException(e);
}
return instance;
}
示例7: dataSub
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
/**
* 嘗試訂閱一下
*
* @throws TddlException
*/
private boolean dataSub(String dataId, String version, ConfigDataListener listener) {
ConfigDataHandler ruleHandler = cdhf.getConfigDataHandler(dataId, listener);
try {
String data = ruleHandler.getData(TIMEOUT, ConfigDataHandler.FIRST_CACHE_THEN_SERVER_STRATEGY);
if (data == null) {
logger.error("use diamond rule config,but recieve no config at all!");
return false;
}
if (initVersionRule(data, version)) {
this.ruleHandlers.put(version, ruleHandler);
return true;
}
} catch (Exception e) {
try {
ruleHandler.destory();
} catch (TddlException e1) {
logger.error("destory failed!", e);
}
logger.error("get diamond data error!", e);
}
return false;
}
示例8: loadDualTable
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
void loadDualTable() throws TddlException {
ConfigDataHandler cdh = ConfigDataHandlerCity.getFileFactory(appName).getConfigDataHandler("DUAL_TABLE.xml",
null);
String data = cdh.getData();
cdh.destroy();
TableMetaParser parser = new TableMetaParser();
TableMeta dualTable = parser.parse(data).get(0);
this.putTable(dualTable.getTableName(), dualTable);
}
示例9: doDestroy
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
protected void doDestroy() throws TddlException {
for (ConfigDataHandler cdh : cdhs.asMap().values()) {
try {
cdh.destroy();
} catch (Exception e) {
// ignore
}
}
for (String app : loadedApps) {
appLoader.unLoadApp(app); // 卸載所有的app
}
}
示例10: getConfigDataHandler
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
public ConfigDataHandler getConfigDataHandler(String dataId) {
if (localValues != null && localValues.containsKey(dataId)) {
return new StaticConfigDataHandler(localValues.get(dataId));
}
return delegateFactory.getConfigDataHandler(dataId);
}
示例11: doDestroy
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
/**
* remove listeners
*
* @throws TddlException
*/
@Override
public void doDestroy() throws TddlException {
if (versionHandler != null) {
versionHandler.destroy();
}
for (ConfigDataHandler ruleListener : this.ruleHandlers.values()) {
ruleListener.destroy();
}
}
示例12: doInit
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
/**
* 從Diamond配置中心提取信息,構造TAtomDataSource、構造有優先級信息的讀寫DBSelector ---add by
* mazhidan.pt
*/
public void doInit() throws TddlException {
// 警告: 不要在構造DefaultDiamondManager時就注冊ManagerListener(比如:configReceiver)
// 也就是說,不要這樣用: new DefaultDiamondManager(dbGroupKey, configReceiver),
// 而是要設成null,等第一次取得信息並解析完成後再注冊,這樣可以不用同步,避免任何與並發相關的問題,
// 因為有可能在第一次剛取回信息後,Diamond配置中心那邊馬上修改了記錄,導致ManagerListener這個線程立刻收到信息,
// 造成初始化線程和ManagerListener線程同時解析信息。
// 目前針對parse方法會做同步處理,避免並發操作. 同時針對diamond相同配置的進行cache,避免重複相同內容的通知
configFactory = ConfigDataHandlerCity.getFactory(tGroupDataSource.getAppName(), tGroupDataSource.getUnitName());
globalHandler = configFactory.getConfigDataHandler(tGroupDataSource.getFullDbGroupKey(), configReceiver);
String dsWeightCommaStr = globalHandler.getData();
// extra config
extraFactory = ConfigDataHandlerCity.getFactory(tGroupDataSource.getAppName(), tGroupDataSource.getUnitName());
extraHandler = extraFactory.getConfigDataHandler(tGroupDataSource.getDbGroupExtraConfigKey(),
extraGroupConfigReceiver);
String extraConfig = extraHandler.getNullableData(tGroupDataSource.getConfigReceiveTimeout(),
ConfigDataHandler.FIRST_CACHE_THEN_SERVER_STRATEGY);
if (extraConfig != null) {
parseExtraConfig(extraConfig);
}
parse(dsWeightCommaStr);
// 已經使用過的配置移除
// destoryConfigHoderFactory();
}
示例13: buildRepository
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
public IRepository buildRepository(Group group, Map repoProperties, Map connectionProperties) {
// 依賴一個mapping文件
String mappingFile = GeneralUtil.getExtraCmdString(connectionProperties,
ConnectionProperties.HBASE_MAPPING_FILE);
String mappingData = null;
ConfigDataHandler cdh = null;
if (mappingFile != null) {
cdh = ConfigDataHandlerCity.getFileFactory(group.getAppName()).getConfigDataHandler(mappingFile, null);
} else {
cdh = ConfigDataHandlerCity.getFactory(group.getAppName(), group.getUnitName())
.getConfigDataHandler(HBASE_MAPPING_FILE.format(new Object[] { group.getAppName() }), null);
}
mappingData = cdh.getData();
if (mappingData == null) {
logger.error("init hbase mapping file failed! content is null");
return null;
}
HbRepository hbRepo = new HbRepository(mappingData);
try {
hbRepo.init();
} catch (TddlException e) {
throw new TddlNestableRuntimeException(e);
}
return hbRepo;
}
示例14: doInit
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
@Override
protected void doInit() {
if (topologyFilePath != null) {
cdh = ConfigDataHandlerCity.getFileFactory(appName).getConfigDataHandler(topologyFilePath,
new TopologyListener(this));
} else {
cdh = ConfigDataHandlerCity.getFactory(appName, unitName)
.getConfigDataHandler(TOPOLOGY.format(new Object[] { appName }), new TopologyListener(this));
}
String data = cdh.getData(ConfigDataHandler.GET_DATA_TIMEOUT, ConfigDataHandler.FIRST_SERVER_STRATEGY);
if (data == null) {
// 嘗試讀一次tddl的appName規則
data = generateTopologyXML(appName, unitName);
}
if (data == null) {
String dataId = TOPOLOGY.format(new Object[] { appName });
throw new TddlRuntimeException(topologyNullError.format(new String[] { appName, unitName, topologyFilePath,
dataId }));
}
try {
Matrix matrix = MatrixParser.parse(data);
this.matrix = matrix;
} catch (Exception ex) {
logger.error("matrix topology init error,file is: " + this.getTopologyFilePath() + ", appname is: "
+ this.getAppName(),
ex);
throw new TddlRuntimeException(ex);
}
}
示例15: getAppDbDbConf
import com.taobao.tddl.config.ConfigDataHandler; //導入依賴的package包/類
public String getAppDbDbConf() {
if (null != appDBHandler) {
return appDBHandler.getData(ConfigDataHandler.GET_DATA_TIMEOUT,
ConfigDataHandler.FIRST_CACHE_THEN_SERVER_STRATEGY);
}
logger.error("[getDataError] appDBConfig not init !");
return null;
}