Package com.taobao.metamorphosis.cluster

Examples of com.taobao.metamorphosis.cluster.Broker


    /**
     * ��zk��ѯһ��id�µ�brokers,����master��һ������slave
     * */
    public Set<Broker> getBrokersById(final int brokerId) {
        final Set<Broker> set = new HashSet<Broker>();
        final Broker masterBroker = this.getMasterBrokerById(brokerId);
        final Set<Broker> slaveBrokers = this.getSlaveBrokersById(brokerId);
        if (masterBroker != null) {
            set.add(masterBroker);
        }
        if (slaveBrokers != null && !slaveBrokers.isEmpty()) {
View Full Code Here


     * ��zk��ѯmaster broker,�������򷵻�null
     * */
    public Broker getMasterBrokerById(final int brokerId) {
        final String brokersString = ZkUtils.readDataMaybeNull(this.zkClient, this.brokerIdsPathOf(brokerId, -1));
        if (StringUtils.isNotBlank(brokersString)) {
            return new Broker(brokerId, brokersString);
        }
        return null;
    }
View Full Code Here

                    continue;
                }
                final String brokerData =
                        ZkUtils.readDataMaybeNull(this.zkClient, this.brokerIdsPath + "/" + brokerId + "/" + broker);
                if (StringUtils.isNotBlank(brokerData)) {
                    ret.add(new Broker(brokerId, brokerData + "?slaveId=" + slaveId));
                }
            }
        }
        return ret;
    }
View Full Code Here

        for (final String brokerIdStr : brokerIds) {
            if (!brokerIdStr.endsWith("-m")) {
                continue;
            }
            final int brokerId = Integer.parseInt(StringUtils.split(brokerIdStr, "-")[0]);
            final Broker broker = this.getMasterBrokerById(brokerId);
            if (broker != null) {
                ret.put(brokerId, broker.getZKString());
            }
        }
        return ret;

    }
View Full Code Here

        this.mockLoadNullInitOffset("topic1", GROUP, new Partition("0-2"));
        this.mockLoadNullInitOffset("topic2", GROUP, new Partition("0-0"));
        // this.mockLoadNullInitOffset("topic2", GROUP, new
        // Partition("1-0"));��load����һ��master�ķ���
        this.mockFetchManagerRestart();
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-0"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-1"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-2"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic2", new Partition("0-0"), 0), 1024 * 1024));
        // this.mockAddFetchRequest(new FetchRequest(new Broker(1,
        // "meta://localhost:1"), 0, new TopicPartitionRegInfo(
        // "topic2", new Partition("1-0"), 0), 1024 * 1024));��������һ��masterץȡ��Ϣ

        this.mocksControl.replay();

        this.slaveConsumerZooKeeper.registerConsumer(consumerConfig, this.fetchManager, topicSubcriberRegistry,
            this.offsetStorage, this.loadBalanceStrategy);
        this.mocksControl.verify();

        // ��֤�����߷���,ֻ�����Լ�master�µ����з�����
        final SlaveZKLoadRebalanceListener listener = this.checkTopic();

        final Set<Broker> brokerSet = ConsumerZooKeeperAccessor.getOldBrokerSet(listener);
        assertEquals(1, brokerSet.size());
        assertTrue(brokerSet.contains(new Broker(0, "meta://localhost:0")));
        assertFalse(brokerSet.contains(new Broker(1, "meta://localhost:1")));
    }
View Full Code Here

                ConsumerZooKeeperAccessor.getTopicRegistry(listener);
        assertNotNull(topicRegistry);
        assertTrue(topicRegistry.isEmpty());
        final Set<Broker> brokerSet = ConsumerZooKeeperAccessor.getOldBrokerSet(listener);
        assertEquals(0, brokerSet.size());
        assertFalse(brokerSet.contains(new Broker(0, "meta://localhost:0")));
        assertFalse(brokerSet.contains(new Broker(1, "meta://localhost:1")));
    }
View Full Code Here

        this.mockLoadNullInitOffset("topic1", GROUP, new Partition("0-0"));
        this.mockLoadNullInitOffset("topic1", GROUP, new Partition("0-1"));
        this.mockLoadNullInitOffset("topic1", GROUP, new Partition("0-2"));
        this.mockLoadNullInitOffset("topic2", GROUP, new Partition("0-0"));
        this.mockFetchManagerRestart();
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-0"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-1"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic1", new Partition("0-2"), 0), 1024 * 1024));
        this.mockAddFetchRequest(new FetchRequest(new Broker(0, "meta://localhost:0"), 0, new TopicPartitionRegInfo(
            "topic2", new Partition("0-0"), 0), 1024 * 1024));
        this.mocksControl.replay();

        ZkUtils.createEphemeralPath(this.client, this.metaZookeeper.brokerIdsPath + "/0/master", "meta://localhost:0");
        this.client.createEphemeral(this.metaZookeeper.brokerTopicsSubPath + "/topic1/0-m",
            new TopicBroker(3, "0-m").toJson());
        this.client.createEphemeral(this.metaZookeeper.brokerTopicsSubPath + "/topic2/0-m",
            new TopicBroker(1, "0-m").toJson());
        Thread.sleep(5000);
        this.mocksControl.verify();

        // �ָ���testReigsterSlaveConsumerʱ��״̬
        final SlaveZKLoadRebalanceListener listener = this.checkTopic();
        final Set<Broker> brokerSet = ConsumerZooKeeperAccessor.getOldBrokerSet(listener);
        assertEquals(1, brokerSet.size());
        assertTrue(brokerSet.contains(new Broker(0, "meta://localhost:0")));
        assertFalse(brokerSet.contains(new Broker(1, "meta://localhost:1")));

    }
View Full Code Here

        this.mocksControl.verify();
        final SlaveZKLoadRebalanceListener listener = this.checkTopic();

        final Set<Broker> brokerSet = ConsumerZooKeeperAccessor.getOldBrokerSet(listener);
        assertEquals(1, brokerSet.size());
        assertTrue(brokerSet.contains(new Broker(0, "meta://localhost:0")));
        assertFalse(brokerSet.contains(new Broker(1, "meta://localhost:1")));
    }
View Full Code Here

        final String topic = "topic1";
        final int maxSize = 1024;
        final Partition partition = new Partition("0-0");
        final long offset = 12;
        final Broker broker = new Broker(0, "meta://localhost:0");
        final int msgId = 1111;
        final byte[] data =
                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
View Full Code Here

        final String topic = "topic1";
        final int maxSize = 1024;
        final Partition partition = new Partition("0-0");
        final long offset = 12;
        final Broker broker = new Broker(0, "meta://localhost:0");
        final int msgId = 1111;
        final byte[] data =
                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.cluster.Broker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.