Package com.taobao.metamorphosis.utils

Examples of com.taobao.metamorphosis.utils.IdWorker


        this.metaConfig.setDataPath(tmpPath);
        final PutCommand cmd1 = new PutCommand(this.topic, this.partition, "hello".getBytes(), null, 0, 0);
        this.metaConfig.setUnflushThreshold(1);
        // ���ƴ�10����Ϣ��roll�ļ�
        this.metaConfig.setMaxSegmentSize(MessageUtils.makeMessageBuffer(1, cmd1).capacity() * MSG_COUNT);
        this.idWorker = new IdWorker(0);
        this.clearTopicPartDir();
        this.deletePolicy = new DiscardDeletePolicy();
        ((DiscardDeletePolicy) this.deletePolicy).setMaxReservedTime(Integer.MAX_VALUE);
        this.messageStore = new MessageStore(this.topic, this.partition, this.metaConfig, this.deletePolicy);
    }
View Full Code Here


        assertTrue(dir.exists());
        final MessageStore store2 = this.messageStoreManager.getMessageStore(topic, partition);
        assertSame(store1, store2);
        assertEquals(2048, store2.getMinOffset());

        final IdWorker idWorker = new IdWorker(0);
        final PutCommand cmd1 = new PutCommand(topic, partition, "hello".getBytes(), null, 0, 0);
        final PutCommand cmd2 = new PutCommand(topic, partition, "world".getBytes(), null, 0, 0);
        store1.append(idWorker.nextId(), cmd1, new AppendCallback() {

            @Override
            public void appendComplete(final Location location) {
                assertEquals(2048, location.getOffset());

            }
        });
        store1.flush();// flushһ��
        final long size = store1.getSegments().last().size();
        store1.append(idWorker.nextId(), cmd2, new AppendCallback() {
            @Override
            public void appendComplete(final Location location) {
                assertEquals(2048 + size, location.getOffset());

            }
View Full Code Here

    }


    private void testInit0(boolean inParallel) throws IOException, InterruptedException {
        final String topic = "MessageStoreManagerUnitTest";
        IdWorker idWorker = new IdWorker(0);
        final TopicConfig topicConfig = new TopicConfig(topic, this.metaConfig);
        topicConfig.setNumPartitions(10);
        this.metaConfig.getTopicConfigMap().put("MessageStoreManagerUnitTest", topicConfig);
        this.metaConfig.setLoadMessageStoresInParallel(inParallel);
        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getMessageStore(topic, i);
            Assert.assertNull(store);
        }
        final CountDownLatch latch = new CountDownLatch(1000);
        for (int i = 0; i < 10; i++) {
            final MessageStore store = this.messageStoreManager.getOrCreateMessageStore(topic, i);
            for (int j = 0; j < 100; j++) {
                final PutCommand cmd = new PutCommand(topic, i, new byte[1024], null, 0, 0);
                final long id = idWorker.nextId();
                store.append(id, cmd, new AppendCallback() {

                    @Override
                    public void appendComplete(Location location) {
                        if (location == Location.InvalidLocaltion) {
View Full Code Here

        final File dir = new File(this.metaConfig.getDataPath() + File.separator + topic + "-" + partition);
        assertFalse(dir.exists());
        assertNull(this.messageStoreManager.getMessageStore(topic, partition));
        final MessageStore store = this.messageStoreManager.getOrCreateMessageStore(topic, partition);

        final IdWorker idWorker = new IdWorker(0);
        final byte[] data = new byte[1024];
        final PutCommand cmd1 = new PutCommand(topic, partition, data, null, 0, 0);
        final PutCommand cmd2 = new PutCommand(topic, partition, data, null, 0, 0);
        store.append(idWorker.nextId(), cmd1, new AppendCallback() {

            @Override
            public void appendComplete(final Location location) {
                assertEquals(0, location.getOffset());

            }
        });
        store.flush();// flushһ��
        store.append(idWorker.nextId(), cmd2, new AppendCallback() {
            @Override
            public void appendComplete(final Location location) {
                assertEquals(1044, location.getOffset());

            }
View Full Code Here

        metaConfig.getTopics().add(topic);
        metaConfig.setNumPartitions(5);
        metaConfig.setMaxSegmentSize(1024 * 1024);
        final MetaMorphosisBroker metaBroker = new MetaMorphosisBroker(metaConfig);

        final IdWorker idWorker = metaBroker.getIdWorker();
        final byte[] data = new byte[1024];
        // ��Ҫ��recover��offset��Ϣ
        final List<MessageInfo> allMsgs = new ArrayList<MessageInfo>();
        final Random random = new Random();
        // ��������
        for (int i = 0; i < 20000; i++) {
            // ��5����������Ϊ��
            final int partition = i % 4;
            final int step = i;
            final MessageStore store = metaBroker.getStoreManager().getOrCreateMessageStore(topic, partition);
            final long msgId = idWorker.nextId();
            store.append(msgId, new PutCommand(topic, partition, data, null, 0, 0), new AppendCallback() {

                @Override
                public void appendComplete(final Location location) {
                    // �������1044����Ϊlocation��offset��������Ϣ�����
View Full Code Here


    private void newProcessor() throws Exception {
        final MetaConfig metaConfig = new MetaConfig();
        this.processor =
                new TransactionalCommandProcessor(metaConfig, this.messageStoreManager, new IdWorker(0), this.next,
                    this.transactionStore, new StatsManager(new MetaConfig(), this.messageStoreManager, null));
    }
View Full Code Here

        this.shutdownHook = new ShutdownHook();
        Runtime.getRuntime().addShutdownHook(this.shutdownHook);
        this.metaConfig = metaConfig;
        this.remotingServer = newRemotingServer(metaConfig);
        this.executorsManager = new ExecutorsManager(metaConfig);
        this.idWorker = new IdWorker(metaConfig.getBrokerId());
        this.storeManager = new MessageStoreManager(metaConfig, this.newDeletePolicy(metaConfig));
        this.statsManager = new StatsManager(this.metaConfig, this.storeManager, this.remotingServer);
        this.brokerZooKeeper = new BrokerZooKeeper(metaConfig);
        JournalTransactionStore transactionStore = null;
        try {
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.utils.IdWorker

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.