gpt4 book ai didi

com.xjeffrose.xio.storage.ZooKeeperWriteProvider类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 10:35:21 29 4
gpt4 key购买 nike

本文整理了Java中com.xjeffrose.xio.storage.ZooKeeperWriteProvider类的一些代码示例,展示了ZooKeeperWriteProvider类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperWriteProvider类的具体详情如下:
包路径:com.xjeffrose.xio.storage.ZooKeeperWriteProvider
类名称:ZooKeeperWriteProvider

ZooKeeperWriteProvider介绍

暂无

代码示例

代码示例来源:origin: xjdr/xio

public static Configurator build(Config config) {
  Config configurationUpdateServer = config.getConfig("configurationUpdateServer");
  if (configurationUpdateServer.getBoolean("enabled") == false) {
   return new NullConfigurator();
  }
  CuratorFramework client = new ZooKeeperClientFactory(config.getConfig("zookeeper")).newClient();
  client.start();
  ZooKeeperWriteProvider zkWriter = new ZooKeeperWriteProvider(new ThriftMarshaller(), client);
  ZooKeeperReadProvider zkReader = new ZooKeeperReadProvider(new ThriftUnmarshaller(), client);

  Config configurationManager = config.getConfig("configurationManager");
  Ruleset rules = new Ruleset(configurationManager);
  rules.read(zkReader);
  ZooKeeperUpdateHandler zkUpdater = new ZooKeeperUpdateHandler(zkWriter, rules);
  ZooKeeperValidator zkValidator = new ZooKeeperValidator(zkReader, rules, configurationManager);

  Duration writeInterval = configurationUpdateServer.getDuration("writeInterval");
  InetSocketAddress serverAddress =
    new InetSocketAddress(
      configurationUpdateServer.getString("bindIp"),
      configurationUpdateServer.getInt("bindPort"));
  Configurator server =
    new Configurator(zkUpdater, writeInterval, serverAddress, rules, zkValidator);
  return server;
 }
}

代码示例来源:origin: xjdr/xio

String path = "/some/path/to/nodes/ipRules";
ZooKeeperWriteProvider provider = new ZooKeeperWriteProvider(marshaller, client);
provider.write(path, config);

代码示例来源:origin: xjdr/xio

@Test
public void testWriteHostnameDeterministicRuleEngineConfig() throws Exception {
 try (TestingServer server = new TestingServer()) {
  server.start();
  HostnameDeterministicRuleEngineConfig config = new HostnameDeterministicRuleEngineConfig();
  config.blacklistHost("localhost");
  config.blacklistHost("localhost.localdomain");
  config.whitelistHost("google.com");
  ThriftMarshaller marshaller = new ThriftMarshaller();
  RetryPolicy retryPolicy = new RetryOneTime(1);
  try (CuratorFramework client =
    CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy)) {
   client.start();
   String path = "/some/path/to/nodes/hostRules";
   ZooKeeperWriteProvider provider = new ZooKeeperWriteProvider(marshaller, client);
   provider.write(path, config);
   byte[] data = client.getData().forPath(path);
   ThriftUnmarshaller unmarshaller = new ThriftUnmarshaller();
   HostnameDeterministicRuleEngineConfig read = new HostnameDeterministicRuleEngineConfig();
   unmarshaller.unmarshall(read, data);
   assertEquals(config, read);
  }
 }
}

代码示例来源:origin: xjdr/xio

@Test
public void testWriteHttp1DeterministicRuleEngineConfig() throws Exception {
 try (TestingServer server = new TestingServer()) {
  server.start();
  Http1DeterministicRuleEngineConfig config = new Http1DeterministicRuleEngineConfig();
  HashMultimap<String, String> headers = HashMultimap.create();
  headers.put("User-Agent", "Bad-actor: 1.0");
  Http1DeterministicRuleEngineConfig.Rule bad =
    new Http1DeterministicRuleEngineConfig.Rule(
      HttpMethod.GET, "/path/to/failure", HttpVersion.HTTP_1_0, headers);
  Http1DeterministicRuleEngineConfig.Rule good =
    new Http1DeterministicRuleEngineConfig.Rule(null, null, null, null);
  config.blacklistRule(bad);
  config.whitelistRule(good);
  ThriftMarshaller marshaller = new ThriftMarshaller();
  RetryPolicy retryPolicy = new RetryOneTime(1);
  try (CuratorFramework client =
    CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy)) {
   client.start();
   String path = "/some/path/to/nodes/http1Rules";
   ZooKeeperWriteProvider provider = new ZooKeeperWriteProvider(marshaller, client);
   provider.write(path, config);
   byte[] data = client.getData().forPath(path);
   ThriftUnmarshaller unmarshaller = new ThriftUnmarshaller();
   Http1DeterministicRuleEngineConfig read = new Http1DeterministicRuleEngineConfig();
   unmarshaller.unmarshall(read, data);
   assertEquals(config, read);
  }
 }
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com