当前位置: 首页>>代码示例>>Java>>正文


Java ClientConfiguration.setProperty方法代码示例

本文整理汇总了Java中org.apache.bookkeeper.conf.ClientConfiguration.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ClientConfiguration.setProperty方法的具体用法?Java ClientConfiguration.setProperty怎么用?Java ClientConfiguration.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bookkeeper.conf.ClientConfiguration的用法示例。


在下文中一共展示了ClientConfiguration.setProperty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNoIsolationGroup

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testNoIsolationGroup() throws Exception {
    String data = "{\"group1\": {\"" + BOOKIE1
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2
            + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4
            + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}";

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc) {
    });
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

    isolationPolicy.newEnsemble(4, 4, new HashSet<>());
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:23,代码来源:ZkIsolatedBookieEnsemblePlacementPolicyTest.java

示例2: testBasic

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testBasic() throws Exception {
    String data = "{\"group1\": {\"" + BOOKIE1
            + "\": {\"rack\": \"/rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2
            + "\": {\"rack\": \"/rack1\", \"hostname\": \"bookie2.example.com\"}}}";
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    // Case1: ZKCache is given
    ZkBookieRackAffinityMapping mapping1 = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf1 = new ClientConfiguration();
    bkClientConf1.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc) {
    });
    mapping1.setConf(bkClientConf1);
    List<String> racks1 = mapping1.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks1.get(0), "/rack0");
    assertEquals(racks1.get(1), "/rack1");
    assertEquals(racks1.get(2), NetworkTopology.DEFAULT_RACK);

    // Case 2: ZkServers and ZkTimeout are given (ZKCache will be constructed in
    // ZkBookieRackAffinityMapping#setConf)
    ZkBookieRackAffinityMapping mapping2 = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf2 = new ClientConfiguration();
    bkClientConf2.setZkServers("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT);
    bkClientConf2.setZkTimeout(1000);
    mapping2.setConf(bkClientConf2);
    List<String> racks2 = mapping2.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks2.get(0), "/rack0");
    assertEquals(racks2.get(1), "/rack1");
    assertEquals(racks2.get(2), NetworkTopology.DEFAULT_RACK);

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:34,代码来源:ZkBookieRackAffinityMappingTest.java

示例3: testNoBookieInfo

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testNoBookieInfo() throws Exception {
    ZkBookieRackAffinityMapping mapping = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc) {
    });
    mapping.setConf(bkClientConf);
    List<String> racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(1), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);

    Map<String, Map<BookieSocketAddress, BookieInfo>> bookieMapping = new HashMap<>();
    Map<BookieSocketAddress, BookieInfo> mainBookieGroup = new HashMap<>();

    BookieInfo bookieInfo0 = new BookieInfo();
    bookieInfo0.setRack("/rack0");
    mainBookieGroup.put(BOOKIE1, bookieInfo0);

    BookieInfo bookieInfo1 = new BookieInfo();
    bookieInfo1.setRack("/rack1");
    mainBookieGroup.put(BOOKIE2, bookieInfo1);

    bookieMapping.put("group1", mainBookieGroup);

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH,
            jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), "/rack0");
    assertEquals(racks.get(1), "/rack1");
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:38,代码来源:ZkBookieRackAffinityMappingTest.java

示例4: testNoBookieInfo

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testNoBookieInfo() throws Exception {
    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc) {
    });
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

    isolationPolicy.newEnsemble(4, 4, new HashSet<>());

    String data = "{\"group1\": {\"" + BOOKIE1
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2
            + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3
            + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4
            + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}";

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    ArrayList<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));

    try {
        isolationPolicy.newEnsemble(3, 3, new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
        // ok
    }

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:37,代码来源:ZkIsolatedBookieEnsemblePlacementPolicyTest.java

示例5: create

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Override
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient) throws IOException {
    ClientConfiguration bkConf = new ClientConfiguration();

    if (conf.getBookkeeperClientAuthenticationPlugin() != null
            && conf.getBookkeeperClientAuthenticationPlugin().trim().length() > 0) {
        bkConf.setClientAuthProviderFactoryClass(conf.getBookkeeperClientAuthenticationPlugin());
        bkConf.setProperty(conf.getBookkeeperClientAuthenticationParametersName(),
                conf.getBookkeeperClientAuthenticationParameters());
    }

    bkConf.setThrottleValue(0);
    bkConf.setAddEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setReadEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setSpeculativeReadTimeout(conf.getBookkeeperClientSpeculativeReadTimeoutInMillis());
    bkConf.setNumChannelsPerBookie(16);
    bkConf.setUseV2WireProtocol(true);
    bkConf.setLedgerManagerFactoryClassName(HierarchicalLedgerManagerFactory.class.getName());
    if (conf.isBookkeeperClientHealthCheckEnabled()) {
        bkConf.enableBookieHealthCheck();
        bkConf.setBookieHealthCheckInterval(conf.getBookkeeperHealthCheckIntervalSec(), TimeUnit.SECONDS);
        bkConf.setBookieErrorThresholdPerInterval(conf.getBookkeeperClientHealthCheckErrorThresholdPerInterval());
        bkConf.setBookieQuarantineTime((int) conf.getBookkeeperClientHealthCheckQuarantineTimeInSeconds(),
                TimeUnit.SECONDS);
    }

    if (conf.isBookkeeperClientRackawarePolicyEnabled()) {
        bkConf.setEnsemblePlacementPolicy(RackawareEnsemblePlacementPolicy.class);
        bkConf.setProperty(RackawareEnsemblePlacementPolicy.REPP_DNS_RESOLVER_CLASS,
                ZkBookieRackAffinityMapping.class.getName());
        this.rackawarePolicyZkCache = new ZooKeeperCache(zkClient) {
        };
        bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, this.rackawarePolicyZkCache);
    }

    if (conf.getBookkeeperClientIsolationGroups() != null && !conf.getBookkeeperClientIsolationGroups().isEmpty()) {
        bkConf.setEnsemblePlacementPolicy(ZkIsolatedBookieEnsemblePlacementPolicy.class);
        bkConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS,
                conf.getBookkeeperClientIsolationGroups());
        if (bkConf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) == null) {
            this.clientIsolationZkCache = new ZooKeeperCache(zkClient) {
            };
            bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, this.clientIsolationZkCache);
        }
    }

    try {
        return new BookKeeper(bkConf, zkClient);
    } catch (InterruptedException | KeeperException e) {
        throw new IOException(e);
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:53,代码来源:BookKeeperClientFactoryImpl.java

示例6: testBookieInfoChange

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testBookieInfoChange() throws Exception {
    Map<String, Map<BookieSocketAddress, BookieInfo>> bookieMapping = new HashMap<>();
    Map<BookieSocketAddress, BookieInfo> mainBookieGroup = new HashMap<>();

    BookieInfo bookieInfo0 = new BookieInfo();
    bookieInfo0.setRack("rack0");
    mainBookieGroup.put(BOOKIE1, bookieInfo0);

    BookieInfo bookieInfo1 = new BookieInfo();
    bookieInfo1.setRack("rack1");
    mainBookieGroup.put(BOOKIE2, bookieInfo1);

    bookieMapping.put("group1", mainBookieGroup);

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH,
            jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    ZkBookieRackAffinityMapping mapping = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc) {
    });
    mapping.setConf(bkClientConf);
    List<String> racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), "/rack0");
    assertEquals(racks.get(1), "/rack1");
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);

    // add info for BOOKIE3 and check if the mapping picks up the change
    Map<BookieSocketAddress, BookieInfo> secondaryBookieGroup = new HashMap<>();
    BookieInfo bookieInfo2 = new BookieInfo();
    bookieInfo2.setRack("rack0");
    secondaryBookieGroup.put(BOOKIE3, bookieInfo2);

    bookieMapping.put("group2", secondaryBookieGroup);
    localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping),
            -1);

    // wait for the zk to notify and update the mappings
    Thread.sleep(100);

    racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), "/rack0");
    assertEquals(racks.get(1), "/rack1");
    assertEquals(racks.get(2), "/rack0");

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);

    Thread.sleep(100);

    racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(1), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:56,代码来源:ZkBookieRackAffinityMappingTest.java

示例7: testBookieInfoChange

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@Test
public void testBookieInfoChange() throws Exception {
    Map<String, Map<String, BookieInfo>> bookieMapping = new HashMap<>();
    Map<String, BookieInfo> mainBookieGroup = new HashMap<>();
    Map<String, BookieInfo> secondaryBookieGroup = new HashMap<>();

    BookieInfo bookieInfo0 = new BookieInfo();
    bookieInfo0.setRack("rack0");
    mainBookieGroup.put(BOOKIE1, bookieInfo0);

    BookieInfo bookieInfo1 = new BookieInfo();
    bookieInfo1.setRack("rack1");
    mainBookieGroup.put(BOOKIE2, bookieInfo1);

    BookieInfo bookieInfo2 = new BookieInfo();
    bookieInfo2.setRack("rack0");
    secondaryBookieGroup.put(BOOKIE3, bookieInfo2);

    BookieInfo bookieInfo3 = new BookieInfo();
    bookieInfo3.setRack("rack2");
    secondaryBookieGroup.put(BOOKIE4, bookieInfo3);

    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);

    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH,
            jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    Thread.sleep(100);

    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setZkServers("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT);
    bkClientConf.setZkTimeout(1000);
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);

    ArrayList<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));

    try {
        isolationPolicy.newEnsemble(3, 3, new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
        // ok
    }

    mainBookieGroup.put(BOOKIE3, bookieInfo2);
    secondaryBookieGroup.remove(BOOKIE3);
    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);

    localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping),
            -1);

    // wait for the zk to notify and update the mappings
    Thread.sleep(100);

    ensemble = isolationPolicy.newEnsemble(3, 3, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE3)));

    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);

    Thread.sleep(100);

    isolationPolicy.newEnsemble(1, 1, new HashSet<>());
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:72,代码来源:ZkIsolatedBookieEnsemblePlacementPolicyTest.java

示例8: commonInitialization

import org.apache.bookkeeper.conf.ClientConfiguration; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private synchronized void commonInitialization(
        DistributedLogConfiguration conf, String ledgersPath,
        ClientSocketChannelFactory channelFactory, StatsLogger statsLogger, HashedWheelTimer requestTimer,
        boolean registerExpirationHandler)
    throws IOException, InterruptedException, KeeperException {
    ClientConfiguration bkConfig = new ClientConfiguration();
    bkConfig.setAddEntryTimeout(conf.getBKClientWriteTimeout());
    bkConfig.setReadTimeout(conf.getBKClientReadTimeout());
    bkConfig.setZkLedgersRootPath(ledgersPath);
    bkConfig.setZkTimeout(conf.getBKClientZKSessionTimeoutMilliSeconds());
    bkConfig.setNumWorkerThreads(conf.getBKClientNumberWorkerThreads());
    bkConfig.setEnsemblePlacementPolicy(RegionAwareEnsemblePlacementPolicy.class);
    bkConfig.setZkRequestRateLimit(conf.getBKClientZKRequestRateLimit());
    bkConfig.setProperty(RegionAwareEnsemblePlacementPolicy.REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME,
            DistributedLogConstants.DISALLOW_PLACEMENT_IN_REGION_FEATURE_NAME);
    // reload configuration from dl configuration with settings prefixed with 'bkc.'
    ConfUtils.loadConfiguration(bkConfig, conf, "bkc.");

    Class<? extends DNSToSwitchMapping> dnsResolverCls;
    try {
        dnsResolverCls = conf.getEnsemblePlacementDnsResolverClass();
    } catch (ConfigurationException e) {
        LOG.error("Failed to load bk dns resolver : ", e);
        throw new IOException("Failed to load bk dns resolver : ", e);
    }
    final DNSToSwitchMapping dnsResolver =
            NetUtils.getDNSResolver(dnsResolverCls, conf.getBkDNSResolverOverrides());

    this.bkc = BookKeeper.newBuilder()
        .config(bkConfig)
        .zk(zkc.get())
        .channelFactory(channelFactory)
        .statsLogger(statsLogger)
        .dnsResolver(dnsResolver)
        .requestTimer(requestTimer)
        .featureProvider(featureProvider.orNull())
        .build();

    if (registerExpirationHandler) {
        sessionExpireWatcher = this.zkc.registerExpirationHandler(this);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:44,代码来源:BookKeeperClient.java


注:本文中的org.apache.bookkeeper.conf.ClientConfiguration.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。