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


Java ZkUtils.createFullPathOptimistic方法代码示例

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


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

示例1: addBrokerToZk

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
private void addBrokerToZk(int number) throws Exception {

        for (int i = 0; i < number; i++) {
            LoadReport report = new LoadReport(null, null, "pulsar://broker-:15000" + i, null);
            String reportData = ObjectMapperFactory.getThreadLocal().writeValueAsString(report);
            ZkUtils.createFullPathOptimistic(mockZookKeeper, LOADBALANCE_BROKERS_ROOT + "/" + "broker-" + i,
                    reportData.getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }

        // sometimes test-environment takes longer time to trigger async mockZK-watch: so reload cache explicitly
        Field field = ZookeeperCacheLoader.class.getDeclaredField("availableBrokersCache");
        field.setAccessible(true);
        ZooKeeperChildrenCache availableBrokersCache = (ZooKeeperChildrenCache) field
                .get(service.getDiscoveryProvider().localZkCache);
        availableBrokersCache.reloadCache(LOADBALANCE_BROKERS_ROOT);
    }
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:18,代码来源:DiscoveryServiceTest.java

示例2: create

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
@Override
public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType, int zkSessionTimeoutMillis) {
    MockZooKeeper mockZooKeeper = MockZooKeeper.newInstance();
    // not used for mock mode
    List<ACL> dummyAclList = new ArrayList<ACL>(0);

    try {
        ZkUtils.createFullPathOptimistic(mockZooKeeper, "/ledgers/available/192.168.1.1:" + 5000,
                "".getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), dummyAclList, CreateMode.PERSISTENT);

        mockZooKeeper.create("/ledgers/LAYOUT", "1\nflat:1".getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME),
                dummyAclList, CreateMode.PERSISTENT);
        return CompletableFuture.completedFuture(mockZooKeeper);

    } catch (KeeperException | InterruptedException e) {
        CompletableFuture<ZooKeeper> future = new CompletableFuture<>();
        future.completeExceptionally(e);
        return future;
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:21,代码来源:MockedZooKeeperClientFactoryImpl.java

示例3: testNoIsolationGroup

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的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

示例4: testMaxTopicDistributionToBroker

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
/**
 * It verifies that once broker owns max-number of topics: load-manager doesn't allocates new bundles to that broker
 * unless all the brokers are in same state.
 * 
 * <pre>
 * 1. Create a bundle whose bundle-resource-quota will contain max-topics
 * 2. Load-manager assigns broker to this bundle so, assigned broker is overloaded with max-topics
 * 3. For any new further bundles: broker assigns different brokers.
 * </pre>
 * 
 * @throws Exception
 */
@Test
public void testMaxTopicDistributionToBroker() throws Exception {

    final int totalBundles = 50;
    final NamespaceBundle[] bundles = LoadBalancerTestingUtils.makeBundles(nsFactory, "test", "test", "test",
            totalBundles);
    final BundleData bundleData = new BundleData(10, 1000);
    // it sets max topics under this bundle so, owner of this broker reaches max-topic threshold
    bundleData.setTopics(pulsar1.getConfiguration().getLoadBalancerBrokerMaxTopics() + 10);
    final TimeAverageMessageData longTermMessageData = new TimeAverageMessageData(1000);
    longTermMessageData.setMsgRateIn(1000);
    bundleData.setLongTermData(longTermMessageData);
    final String firstBundleDataPath = String.format("%s/%s", ModularLoadManagerImpl.BUNDLE_DATA_ZPATH, bundles[0]);
    ZkUtils.createFullPathOptimistic(pulsar1.getZkClient(), firstBundleDataPath, bundleData.getJsonBytes(),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    String maxTopicOwnedBroker = primaryLoadManager.selectBrokerForAssignment(bundles[0]);

    for (int i = 1; i < totalBundles; i++) {
        assertNotEquals(primaryLoadManager.selectBrokerForAssignment(bundles[i]), maxTopicOwnedBroker);
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:34,代码来源:ModularLoadManagerImplTest.java

示例5: testOwnBrokerZnodeByMultipleBroker

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
/**
 * It verifies that pulsar-service fails if load-manager tries to create ephemeral znode for broker which is already
 * created by other zk-session-id.
 * 
 * @throws Exception
 */
@Test
public void testOwnBrokerZnodeByMultipleBroker() throws Exception {

    ServiceConfiguration config = new ServiceConfiguration();
    config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config.setClusterName("use");
    int brokerWebServicePort = PortManager.nextFreePort();
    int brokerServicePort = PortManager.nextFreePort();
    config.setWebServicePort(brokerWebServicePort);
    config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config.setBrokerServicePort(brokerServicePort);
    PulsarService pulsar = new PulsarService(config);
    // create znode using different zk-session
    final String brokerZnode = LoadManager.LOADBALANCE_BROKERS_ROOT + "/" + pulsar.getAdvertisedAddress() + ":"
            + brokerWebServicePort;
    ZkUtils.createFullPathOptimistic(pulsar1.getZkClient(), brokerZnode, "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
    try {
        pulsar.start();
    } catch (PulsarServerException e) {
        //Ok.
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:30,代码来源:ModularLoadManagerImplTest.java

示例6: testLoadReportDeserialize

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
/**
 * <pre>
 *  It verifies that namespace service deserialize the load-report based on load-manager which active.
 *  1. write candidate1- load report using {@link LoadReport} which is used by SimpleLoadManagerImpl
 *  2. Write candidate2- load report using {@link LocalBrokerData} which is used by ModularLoadManagerImpl
 *  3. try to get Lookup Result based on active load-manager
 * </pre>
 * @throws Exception
 */
@Test
public void testLoadReportDeserialize() throws Exception {

    final String candidateBroker1 = "http://localhost:8000";
    final String candidateBroker2 = "http://localhost:3000";
    LoadReport lr = new LoadReport(null, null, candidateBroker1, null);
    LocalBrokerData ld = new LocalBrokerData(null, null, candidateBroker2, null);
    URI uri1 = new URI(candidateBroker1);
    URI uri2 = new URI(candidateBroker2);
    String path1 = String.format("%s/%s:%s", LoadManager.LOADBALANCE_BROKERS_ROOT, uri1.getHost(), uri1.getPort());
    String path2 = String.format("%s/%s:%s", LoadManager.LOADBALANCE_BROKERS_ROOT, uri2.getHost(), uri2.getPort());
    ZkUtils.createFullPathOptimistic(pulsar.getZkClient(), path1,
            ObjectMapperFactory.getThreadLocal().writeValueAsBytes(lr), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
    ZkUtils.createFullPathOptimistic(pulsar.getZkClient(), path2,
            ObjectMapperFactory.getThreadLocal().writeValueAsBytes(ld), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
    LookupResult result1 = pulsar.getNamespaceService().createLookupResult(candidateBroker1).get();

    // update to new load mananger
    pulsar.getLoadManager().set(new ModularLoadManagerWrapper(new ModularLoadManagerImpl()));
    LookupResult result2 = pulsar.getNamespaceService().createLookupResult(candidateBroker2).get();
    Assert.assertEquals(result1.getLookupData().getBrokerUrl(), candidateBroker1);
    Assert.assertEquals(result2.getLookupData().getBrokerUrl(), candidateBroker2);
    System.out.println(result2);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:36,代码来源:NamespaceServiceTest.java

示例7: createZPathIfNotExists

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
private static void createZPathIfNotExists(final ZooKeeper zkClient, final String path) throws Exception {
    if (zkClient.exists(path, false) == null) {
        try {
            ZkUtils.createFullPathOptimistic(zkClient, path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        } catch (KeeperException.NodeExistsException e) {
            // Ignore if already exists.
        }
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:11,代码来源:ModularLoadManagerImpl.java

示例8: DistributedIdGenerator

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
/**
 *
 * @param zk
 * @param path
 *            path of the z-node used to track the generators ids
 * @param prefix
 *            prefix to prepend to the generated id. Having a unique prefix can make the id globally unique
 * @throws Exception
 */
public DistributedIdGenerator(ZooKeeper zk, String path, String prefix) throws Exception {
    this.prefix = prefix;
    this.counter = new AtomicLong(0);

    // Create base path if it doesn't exist
    if (zk.exists(path, false) == null) {
        try {
            ZkUtils.createFullPathOptimistic(zk, path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        } catch (NodeExistsException e) {
            // Ok
        }
    }

    // Create an ephemeral sequential z-node that will have a name containing a unique number. We'll use this number
    // as a prefix for all the generated ids, in addition to the specified prefix.
    String createdPath = zk.create(path + "/-", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL_SEQUENTIAL);

    // Parse the sequential z-node name and extract the unique number
    String[] parts = createdPath.split("/");
    String name = parts[parts.length - 1].replace('-', ' ').trim();

    this.generatorInstanceId = Integer.parseInt(name);
    log.info("Created sequential node at {} -- Generator Id is {}-{}", createdPath, prefix, generatorInstanceId);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:36,代码来源:DistributedIdGenerator.java

示例9: startBookKeeper

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
/**
 * Start cluster
 *
 * @throws Exception
 */
protected void startBookKeeper() throws Exception {
    zkc = MockZooKeeper.newInstance();
    for (int i = 0; i < numBookies; i++) {
        ZkUtils.createFullPathOptimistic(zkc, "/ledgers/available/192.168.1.1:" + (5000 + i), "".getBytes(), null,
                null);
    }

    zkc.create("/ledgers/LAYOUT", "1\nflat:1".getBytes(), null, null);

    bkc = new MockBookKeeper(baseClientConf, zkc);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:17,代码来源:MockedBookKeeperTestCase.java

示例10: testNoBookieInfo

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的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

示例11: upsertLookupPermits

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
private void upsertLookupPermits(int permits) throws Exception {
    Map<String, String> throttlingMap = Maps.newHashMap();
    throttlingMap.put("maxConcurrentLookupRequest", Integer.toString(permits));
    byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(throttlingMap);
    if (mockZookKeeper.exists(BROKER_SERVICE_CONFIGURATION_PATH, false) != null) {
        mockZookKeeper.setData(BROKER_SERVICE_CONFIGURATION_PATH, content, -1);
    } else {
        ZkUtils.createFullPathOptimistic(mockZookKeeper, BROKER_SERVICE_CONFIGURATION_PATH, content,
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:12,代码来源:BrokerServiceThrottlingTest.java

示例12: setup

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    ZkUtils.createFullPathOptimistic(bkEnsemble.getZkClient(),
            SimpleLoadManagerImpl.LOADBALANCER_DYNAMIC_SETTING_STRATEGY_ZPATH,
            "{\"loadBalancerStrategy\":\"leastLoadedServer\"}".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    final String localhost = InetAddress.getLocalHost().getHostName();
    // start brokers
    for (int i = 0; i < BROKER_COUNT; i++) {
        brokerWebServicePorts[i] = PortManager.nextFreePort();
        brokerNativeBrokerPorts[i] = PortManager.nextFreePort();

        ServiceConfiguration config = new ServiceConfiguration();
        config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
        config.setClusterName("use");
        config.setWebServicePort(brokerWebServicePorts[i]);
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
        config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
        config.setAdvertisedAddress(localhost+i);;

        pulsarServices[i] = new PulsarService(config);
        pulsarServices[i].start();

        brokerUrls[i] = new URL("http://127.0.0.1" + ":" + brokerWebServicePorts[i]);
        lookupAddresses[i] = pulsarServices[i].getAdvertisedAddress() + ":" + config.getWebServicePort();
        pulsarAdmins[i] = new PulsarAdmin(brokerUrls[i], (Authentication) null);
    }

    createNamespacePolicies(pulsarServices[0]);

    Thread.sleep(100);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:38,代码来源:LoadBalancerTest.java

示例13: createNamespace

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
private void createNamespace(PulsarService pulsar, String namespace, int numBundles) throws Exception {
    Policies policies = new Policies();
    policies.bundles = getBundles(numBundles);

    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    ZooKeeper globalZk = pulsar.getGlobalZkCache().getZooKeeper();
    String zpath = AdminResource.path(POLICIES, namespace);
    ZkUtils.createFullPathOptimistic(globalZk, zpath, jsonMapper.writeValueAsBytes(policies),
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:12,代码来源:LoadBalancerTest.java

示例14: testBasic

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的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

示例15: testEvenBundleDistribution

import org.apache.bookkeeper.util.ZkUtils; //导入方法依赖的package包/类
@Test
public void testEvenBundleDistribution() throws Exception {
    final NamespaceBundle[] bundles = LoadBalancerTestingUtils
            .makeBundles(pulsar1.getNamespaceService().getNamespaceBundleFactory(), "pulsar", "use", "test", 16);
    final ResourceQuota quota = new ResourceQuota();
    final String quotaZPath = String.format("%s/%s/%s", ResourceQuotaCache.RESOURCE_QUOTA_ROOT, "namespace",
            bundles[0]);
    // Create high message rate quota for the first bundle to make it unlikely to be a coincidence of even
    // distribution.
    ZkUtils.createFullPathOptimistic(pulsar1.getZkClient(), quotaZPath,
            ObjectMapperFactory.getThreadLocal().writeValueAsBytes(quota), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    int numAssignedToPrimary = 0;
    int numAssignedToSecondary = 0;
    pulsar1.getConfiguration().setLoadBalancerPlacementStrategy(SimpleLoadManagerImpl.LOADBALANCER_STRATEGY_LLS);
    final SimpleLoadManagerImpl loadManager = (SimpleLoadManagerImpl) pulsar1.getLoadManager().get();

    for (final NamespaceBundle bundle : bundles) {
        if (loadManager.getLeastLoaded(bundle).getResourceId().equals(primaryHost)) {
            ++numAssignedToPrimary;
        } else {
            ++numAssignedToSecondary;
        }
        // Check that number of assigned bundles are equivalent when an even number have been assigned.
        if ((numAssignedToPrimary + numAssignedToSecondary) % 2 == 0) {
            assert (numAssignedToPrimary == numAssignedToSecondary);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:30,代码来源:SimpleLoadManagerImplTest.java


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