@Test public void testZooKeeperDataSource() throws Exception { TestingServer server = new TestingServer(21812); server.start(); final String remoteAddress = server.getConnectString(); final String path = "/sentinel-zk-ds-demo/flow-HK"; ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<List<FlowRule>>(remoteAddress, path, new Converter<String, List<FlowRule>>() { @Override public List<FlowRule> convert(String source) { return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}); } }); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); CuratorFramework zkClient = CuratorFrameworkFactory.newClient(remoteAddress, new ExponentialBackoffRetry(3, 1000)); zkClient.start(); Stat stat = zkClient.checkExists().forPath(path); if (stat == null) { zkClient.create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path, null); } final String resourceName = "HK"; publishThenTestFor(zkClient, path, resourceName, 10); publishThenTestFor(zkClient, path, resourceName, 15); zkClient.close(); server.stop(); }
public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) { super(parser); if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) { throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path)); } this.path = path; init(serverAddr, null); }
ZookeeperDataSource extends AbstractDataSource<String, T> { public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) { super(parser); if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) { throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path)); } this.path = path; init(serverAddr, null); } }
ZookeeperDataSource extends AbstractDataSource<String, T> { public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) { super(parser); if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) { throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path)); } this.path = path; init(serverAddr, null); } ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId,
                               Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final List<AuthInfo> authInfos, final String groupId, final String dataId,
                               Converter<String, T> parser); }
ZookeeperDataSource extends AbstractDataSource<String, T> { public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) { super(parser); if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) { throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path)); } this.path = path; init(serverAddr, null); } ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId,
                               Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final List<AuthInfo> authInfos, final String groupId, final String dataId,
                               Converter<String, T> parser); @Override String readSource(); @Override void close(); }
ZookeeperDataSource extends AbstractDataSource<String, T> { public ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser) { super(parser); if (StringUtil.isBlank(serverAddr) || StringUtil.isBlank(path)) { throw new IllegalArgumentException(String.format("Bad argument: serverAddr=[%s], path=[%s]", serverAddr, path)); } this.path = path; init(serverAddr, null); } ZookeeperDataSource(final String serverAddr, final String path, Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId,
                               Converter<String, T> parser);  ZookeeperDataSource(final String serverAddr, final List<AuthInfo> authInfos, final String groupId, final String dataId,
                               Converter<String, T> parser); @Override String readSource(); @Override void close();  }