Loading pom.xml +6 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ <elastic-job.version>1.0.6</elastic-job.version> <grpc.version>1.7.0</grpc.version> <protobuf.version>3.4.0</protobuf.version> <guava-retrying.version>2.0.0</guava-retrying.version> <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version> <maven-assembly-plugin.version>2.5.5</maven-assembly-plugin.version> Loading Loading @@ -136,6 +137,11 @@ <artifactId>grpc-stub</artifactId> <version>${grpc.version}</version> </dependency> <dependency> <groupId>com.github.rholder</groupId> <artifactId>guava-retrying</artifactId> <version>${guava-retrying.version}</version> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-test</artifactId> Loading sharding-jdbc-orchestration/pom.xml +4 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,10 @@ <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> </dependency> <dependency> <groupId>com.github.rholder</groupId> <artifactId>guava-retrying</artifactId> </dependency> <dependency> <groupId>junit</groupId> Loading sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/config/ConfigMapListenerManager.java +14 −20 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource; import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource; import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; Loading Loading @@ -51,38 +53,30 @@ public final class ConfigMapListenerManager implements ListenerManager { @Override public void start(final ShardingDataSource shardingDataSource) { String cachePath = configNode.getFullPath(ConfigurationNode.SHARDING_CONFIG_MAP_NODE_PATH); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent changeEvent) throws Exception { // only handles the reg center updated event if (ChangeEvent.ChangeType.UPDATED == changeEvent.getChangeType() && changeEvent.getChangeData().isPresent()) { ConfigMapContext.getInstance().getShardingConfig().clear(); ConfigMapContext.getInstance().getShardingConfig().putAll(configurationService.loadShardingConfigMap()); } } }); } @Override public void start(final MasterSlaveDataSource masterSlaveDataSource) { String cachePath = configNode.getFullPath(ConfigurationNode.MASTER_SLAVE_CONFIG_MAP_NODE_PATH); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handles the reg center update event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { ConfigMapContext.getInstance().getMasterSlaveConfig().clear(); ConfigMapContext.getInstance().getMasterSlaveConfig().putAll(configurationService.loadMasterSlaveConfigMap()); } } }); } } sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/config/ConfigurationListenerManager.java +13 −18 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource; import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.internal.state.datasource.DataSourceService; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import javafx.scene.control.TextFormatter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; import org.apache.curator.framework.recipes.cache.TreeCache; Loading Loading @@ -60,18 +63,14 @@ public final class ConfigurationListenerManager implements ListenerManager { private void start(final String node, final ShardingDataSource shardingDataSource) { String cachePath = configNode.getFullPath(node); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handle updated event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { shardingDataSource.renew(dataSourceService.getAvailableShardingRule(), configurationService.loadShardingProperties()); } } }); } Loading @@ -83,18 +82,14 @@ public final class ConfigurationListenerManager implements ListenerManager { private void start(final String node, final MasterSlaveDataSource masterSlaveDataSource) { String cachePath = configNode.getFullPath(node); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handle updated event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { masterSlaveDataSource.renew(dataSourceService.getAvailableMasterSlaveRule()); } } }); } } sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/state/datasource/DataSourceListenerManager.java +14 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.config.ConfigurationService; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.internal.state.StateNode; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; Loading Loading @@ -54,16 +56,13 @@ public final class DataSourceListenerManager implements ListenerManager { @Override public void start(final ShardingDataSource shardingDataSource) { TreeCache cache = (TreeCache) registryCenter.getRawCache(stateNode.getDataSourcesNodeFullPath()); cache.getListenable().addListener(new TreeCacheListener() { registryCenter.watch(stateNode.getDataSourcesNodeFullPath(), new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || null == childData.getData() || childData.getPath().isEmpty()) { return; } if (TreeCacheEvent.Type.NODE_UPDATED == event.getType() || TreeCacheEvent.Type.NODE_REMOVED == event.getType()) { public void onChange(ChangeEvent event) throws Exception { // only handle updated and deleted event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() || ChangeEvent.ChangeType.DELETED == event.getChangeType() && event.getChangeData().isPresent()) { shardingDataSource.renew(dataSourceService.getAvailableShardingRule(), configurationService.loadShardingProperties()); } } Loading @@ -72,16 +71,13 @@ public final class DataSourceListenerManager implements ListenerManager { @Override public void start(final MasterSlaveDataSource masterSlaveDataSource) { TreeCache cache = (TreeCache) registryCenter.getRawCache(stateNode.getDataSourcesNodeFullPath()); cache.getListenable().addListener(new TreeCacheListener() { registryCenter.watch(stateNode.getDataSourcesNodeFullPath(), new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || null == childData.getData() || childData.getPath().isEmpty()) { return; } if (TreeCacheEvent.Type.NODE_UPDATED == event.getType() || TreeCacheEvent.Type.NODE_REMOVED == event.getType()) { public void onChange(ChangeEvent event) throws Exception { // only handle updated and deleted event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() || ChangeEvent.ChangeType.DELETED == event.getChangeType() && event.getChangeData().isPresent()) { masterSlaveDataSource.renew(dataSourceService.getAvailableMasterSlaveRule()); } } Loading Loading
pom.xml +6 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ <elastic-job.version>1.0.6</elastic-job.version> <grpc.version>1.7.0</grpc.version> <protobuf.version>3.4.0</protobuf.version> <guava-retrying.version>2.0.0</guava-retrying.version> <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version> <maven-assembly-plugin.version>2.5.5</maven-assembly-plugin.version> Loading Loading @@ -136,6 +137,11 @@ <artifactId>grpc-stub</artifactId> <version>${grpc.version}</version> </dependency> <dependency> <groupId>com.github.rholder</groupId> <artifactId>guava-retrying</artifactId> <version>${guava-retrying.version}</version> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-test</artifactId> Loading
sharding-jdbc-orchestration/pom.xml +4 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,10 @@ <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> </dependency> <dependency> <groupId>com.github.rholder</groupId> <artifactId>guava-retrying</artifactId> </dependency> <dependency> <groupId>junit</groupId> Loading
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/config/ConfigMapListenerManager.java +14 −20 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource; import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource; import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; Loading Loading @@ -51,38 +53,30 @@ public final class ConfigMapListenerManager implements ListenerManager { @Override public void start(final ShardingDataSource shardingDataSource) { String cachePath = configNode.getFullPath(ConfigurationNode.SHARDING_CONFIG_MAP_NODE_PATH); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent changeEvent) throws Exception { // only handles the reg center updated event if (ChangeEvent.ChangeType.UPDATED == changeEvent.getChangeType() && changeEvent.getChangeData().isPresent()) { ConfigMapContext.getInstance().getShardingConfig().clear(); ConfigMapContext.getInstance().getShardingConfig().putAll(configurationService.loadShardingConfigMap()); } } }); } @Override public void start(final MasterSlaveDataSource masterSlaveDataSource) { String cachePath = configNode.getFullPath(ConfigurationNode.MASTER_SLAVE_CONFIG_MAP_NODE_PATH); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handles the reg center update event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { ConfigMapContext.getInstance().getMasterSlaveConfig().clear(); ConfigMapContext.getInstance().getMasterSlaveConfig().putAll(configurationService.loadMasterSlaveConfigMap()); } } }); } }
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/config/ConfigurationListenerManager.java +13 −18 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource; import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.internal.state.datasource.DataSourceService; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import javafx.scene.control.TextFormatter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; import org.apache.curator.framework.recipes.cache.TreeCache; Loading Loading @@ -60,18 +63,14 @@ public final class ConfigurationListenerManager implements ListenerManager { private void start(final String node, final ShardingDataSource shardingDataSource) { String cachePath = configNode.getFullPath(node); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handle updated event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { shardingDataSource.renew(dataSourceService.getAvailableShardingRule(), configurationService.loadShardingProperties()); } } }); } Loading @@ -83,18 +82,14 @@ public final class ConfigurationListenerManager implements ListenerManager { private void start(final String node, final MasterSlaveDataSource masterSlaveDataSource) { String cachePath = configNode.getFullPath(node); regCenter.addCacheData(cachePath); TreeCache cache = (TreeCache) regCenter.getRawCache(cachePath); cache.getListenable().addListener(new TreeCacheListener() { regCenter.watch(cachePath, new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || childData.getPath().isEmpty() || null == childData.getData() || TreeCacheEvent.Type.NODE_UPDATED != event.getType()) { return; } public void onChange(ChangeEvent event) throws Exception { // only handle updated event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() && event.getChangeData().isPresent()) { masterSlaveDataSource.renew(dataSourceService.getAvailableMasterSlaveRule()); } } }); } }
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/internal/state/datasource/DataSourceListenerManager.java +14 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration; import io.shardingjdbc.orchestration.internal.config.ConfigurationService; import io.shardingjdbc.orchestration.internal.listener.ListenerManager; import io.shardingjdbc.orchestration.internal.state.StateNode; import io.shardingjdbc.orchestration.reg.base.ChangeEvent; import io.shardingjdbc.orchestration.reg.base.ChangeListener; import io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.recipes.cache.ChildData; Loading Loading @@ -54,16 +56,13 @@ public final class DataSourceListenerManager implements ListenerManager { @Override public void start(final ShardingDataSource shardingDataSource) { TreeCache cache = (TreeCache) registryCenter.getRawCache(stateNode.getDataSourcesNodeFullPath()); cache.getListenable().addListener(new TreeCacheListener() { registryCenter.watch(stateNode.getDataSourcesNodeFullPath(), new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || null == childData.getData() || childData.getPath().isEmpty()) { return; } if (TreeCacheEvent.Type.NODE_UPDATED == event.getType() || TreeCacheEvent.Type.NODE_REMOVED == event.getType()) { public void onChange(ChangeEvent event) throws Exception { // only handle updated and deleted event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() || ChangeEvent.ChangeType.DELETED == event.getChangeType() && event.getChangeData().isPresent()) { shardingDataSource.renew(dataSourceService.getAvailableShardingRule(), configurationService.loadShardingProperties()); } } Loading @@ -72,16 +71,13 @@ public final class DataSourceListenerManager implements ListenerManager { @Override public void start(final MasterSlaveDataSource masterSlaveDataSource) { TreeCache cache = (TreeCache) registryCenter.getRawCache(stateNode.getDataSourcesNodeFullPath()); cache.getListenable().addListener(new TreeCacheListener() { registryCenter.watch(stateNode.getDataSourcesNodeFullPath(), new ChangeListener() { @Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData || null == childData.getData() || childData.getPath().isEmpty()) { return; } if (TreeCacheEvent.Type.NODE_UPDATED == event.getType() || TreeCacheEvent.Type.NODE_REMOVED == event.getType()) { public void onChange(ChangeEvent event) throws Exception { // only handle updated and deleted event if (ChangeEvent.ChangeType.UPDATED == event.getChangeType() || ChangeEvent.ChangeType.DELETED == event.getChangeType() && event.getChangeData().isPresent()) { masterSlaveDataSource.renew(dataSourceService.getAvailableMasterSlaveRule()); } } Loading