Search in sources :

Example 1 with EventListener

use of io.shardingjdbc.orchestration.reg.listener.EventListener 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());
            }
        }
    });
}
Also used : DataChangedEvent(io.shardingjdbc.orchestration.reg.listener.DataChangedEvent) EventListener(io.shardingjdbc.orchestration.reg.listener.EventListener)

Example 2 with EventListener

use of io.shardingjdbc.orchestration.reg.listener.EventListener 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());
            }
        }
    });
}
Also used : DataChangedEvent(io.shardingjdbc.orchestration.reg.listener.DataChangedEvent) EventListener(io.shardingjdbc.orchestration.reg.listener.EventListener)

Example 3 with EventListener

use of io.shardingjdbc.orchestration.reg.listener.EventListener 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());
            }
        }
    });
}
Also used : DataChangedEvent(io.shardingjdbc.orchestration.reg.listener.DataChangedEvent) EventListener(io.shardingjdbc.orchestration.reg.listener.EventListener)

Example 4 with EventListener

use of io.shardingjdbc.orchestration.reg.listener.EventListener 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());
            }
        }
    });
}
Also used : DataChangedEvent(io.shardingjdbc.orchestration.reg.listener.DataChangedEvent) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) EventListener(io.shardingjdbc.orchestration.reg.listener.EventListener) Map(java.util.Map)

Aggregations

DataChangedEvent (io.shardingjdbc.orchestration.reg.listener.DataChangedEvent)4 EventListener (io.shardingjdbc.orchestration.reg.listener.EventListener)4 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)1 Map (java.util.Map)1