use of io.shardingjdbc.orchestration.reg.listener.DataChangedEvent in project sharding-jdbc by shardingjdbc.
the class ConfigMapListenerManager method start.
@Override
public void start(final MasterSlaveDataSource masterSlaveDataSource) {
String cachePath = configNode.getFullPath(ConfigurationNode.MASTER_SLAVE_CONFIG_MAP_NODE_PATH);
regCenter.watch(cachePath, new EventListener() {
@Override
public void onChange(final DataChangedEvent event) {
if (DataChangedEvent.Type.UPDATED == event.getEventType()) {
ConfigMapContext.getInstance().getMasterSlaveConfig().clear();
ConfigMapContext.getInstance().getMasterSlaveConfig().putAll(configService.loadMasterSlaveConfigMap());
}
}
});
}
use of io.shardingjdbc.orchestration.reg.listener.DataChangedEvent in project sharding-jdbc by shardingjdbc.
the class ConfigMapListenerManager method start.
@Override
public void start(final ShardingDataSource shardingDataSource) {
String cachePath = configNode.getFullPath(ConfigurationNode.SHARDING_CONFIG_MAP_NODE_PATH);
regCenter.watch(cachePath, new EventListener() {
@Override
public void onChange(final DataChangedEvent event) {
if (DataChangedEvent.Type.UPDATED == event.getEventType()) {
ConfigMapContext.getInstance().getShardingConfig().clear();
ConfigMapContext.getInstance().getShardingConfig().putAll(configService.loadShardingConfigMap());
}
}
});
}
use of io.shardingjdbc.orchestration.reg.listener.DataChangedEvent in project sharding-jdbc by shardingjdbc.
the class ConfigurationListenerManager method start.
private void start(final String node, final MasterSlaveDataSource masterSlaveDataSource) {
String cachePath = configNode.getFullPath(node);
regCenter.watch(cachePath, new EventListener() {
@Override
public void onChange(final DataChangedEvent event) {
if (DataChangedEvent.Type.UPDATED == event.getEventType()) {
masterSlaveDataSource.renew(dataSourceService.getAvailableDataSources(), dataSourceService.getAvailableMasterSlaveRuleConfiguration());
}
}
});
}
use of io.shardingjdbc.orchestration.reg.listener.DataChangedEvent in project sharding-jdbc by shardingjdbc.
the class ConfigurationListenerManager method start.
private void start(final String node, final ShardingDataSource shardingDataSource) {
String cachePath = configNode.getFullPath(node);
regCenter.watch(cachePath, new EventListener() {
@Override
public void onChange(final DataChangedEvent event) {
if (DataChangedEvent.Type.UPDATED == event.getEventType()) {
Map<String, DataSource> dataSourceMap = dataSourceService.getAvailableDataSources();
shardingDataSource.renew(dataSourceMap, new ShardingRule(dataSourceService.getAvailableShardingRuleConfiguration(), dataSourceMap.keySet()), configService.loadShardingProperties());
}
}
});
}
use of io.shardingjdbc.orchestration.reg.listener.DataChangedEvent in project sharding-jdbc by shardingjdbc.
the class ZookeeperRegistryCenter method watch.
@Override
public void watch(final String key, final EventListener eventListener) {
final String path = key + "/";
if (!caches.containsKey(path)) {
addCacheData(key);
}
TreeCache cache = caches.get(path);
cache.getListenable().addListener(new TreeCacheListener() {
@Override
public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception {
ChildData data = event.getData();
if (null == data || null == data.getPath()) {
return;
}
eventListener.onChange(new DataChangedEvent(getEventType(event), data.getPath(), null == data.getData() ? null : new String(data.getData(), "UTF-8")));
}
private DataChangedEvent.Type getEventType(final TreeCacheEvent event) {
switch(event.getType()) {
case NODE_UPDATED:
return DataChangedEvent.Type.UPDATED;
case NODE_REMOVED:
return DataChangedEvent.Type.DELETED;
default:
return DataChangedEvent.Type.IGNORED;
}
}
});
}
Aggregations