本文整理汇总了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;
}