Package com.taobao.metamorphosis.network

Examples of com.taobao.metamorphosis.network.BooleanCommand


        int partition = 0;
        // skip two messages.
        OpaqueGenerator.getNextOpaque();
        OpaqueGenerator.getNextOpaque();
        // check if slave is ok.
        final BooleanCommand expectResp = new BooleanCommand(HttpStatus.Success, msgId + " " + partition + " " + 0, -1);
        SyncCommand command =
                new SyncCommand(testTopic, partition, encodePayload, flag, msgId, CheckSum.crc32(encodePayload),
                    OpaqueGenerator.getNextOpaque());
        EasyMock.expect(
            this.remotingClient.invokeToGroup(this.slaveUrl, command,
View Full Code Here


        final int flag = MessageFlagUtils.getFlag(null);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data), null,
                    Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                        new BooleanCommand(500, "server error", Integer.MIN_VALUE));
        // EasyMock.expect(
        // this.remotingClient.invokeToGroup(url, new PutCommand(topic,
        // partition.getPartition(), data, null, flag,
        // Integer.MIN_VALUE + 1), 3000, TimeUnit.MILLISECONDS)).andReturn(
        // new BooleanCommand(Integer.MIN_VALUE, 500, "server error"));
View Full Code Here

    private void mockInvokeSuccess(final String serverUrl, final TransactionInfo info, final String result)
            throws InterruptedException, TimeoutException, NotifyRemotingException {
        EasyMock.expect(
            this.remotingClient.invokeToGroup(serverUrl, new TransactionCommand(info, OpaqueGenerator.getNextOpaque()),
                5000L, TimeUnit.MILLISECONDS)).andReturn(new BooleanCommand(HttpStatus.Success, result, 0));
    }
View Full Code Here

        final TopicPartitionRegInfo topicPartitionRegInfo = new TopicPartitionRegInfo(topic, partition, offset);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new OffsetCommand(topic, this.consumerConfig.getGroup(), partition.getPartition(), offset,
                    Integer.MIN_VALUE), this.consumerConfig.getFetchTimeoutInMills(), TimeUnit.MILLISECONDS))
                    .andReturn(new BooleanCommand(HttpStatus.Success, String.valueOf(offset), Integer.MIN_VALUE));
        this.mocksControl.replay();
        OpaqueGenerator.resetOpaque();
        assertEquals(offset, this.consumer.offset(new FetchRequest(broker, delay, topicPartitionRegInfo, maxSize)));
        this.mocksControl.verify();
    }
View Full Code Here

        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new GetCommand(topic, this.consumerConfig.getGroup(), partition.getPartition(), offset, maxSize,
                    Integer.MIN_VALUE), 10000, TimeUnit.MILLISECONDS)).andReturn(
                        new BooleanCommand(500, "test error", Integer.MIN_VALUE));
        this.mocksControl.replay();
        try {
            OpaqueGenerator.resetOpaque();
            assertEquals(messageIterator, this.consumer.get(topic, partition, offset, maxSize));
            fail();
View Full Code Here

        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new GetCommand(topic, this.consumerConfig.getGroup(), partition.getPartition(), offset, maxSize,
                    Integer.MIN_VALUE), 10000, TimeUnit.MILLISECONDS)).andReturn(
                        new BooleanCommand(404, "not found", Integer.MIN_VALUE));
        this.mocksControl.replay();
        OpaqueGenerator.resetOpaque();
        assertNull(this.consumer.get(topic, partition, offset, maxSize));
        this.mocksControl.verify();
    }
View Full Code Here

        if (!this.remotingClient.isConnected(masterServerUrl)) {
            log.info("try connect to " + masterServerUrl);
            this.connectServer(masterServerUrl);
        }
        try {
            final BooleanCommand resp =
                    (BooleanCommand) this.remotingClient.invokeToGroup(masterServerUrl, new OffsetCommand(topic,
                        this.broker.getMetaConfig().getSlaveConfig().getSlaveGroup(), partition.getPartition(), 0,
                        OpaqueGenerator.getNextOpaque()));

            final String resultStr = resp.getErrorMsg();

            switch (resp.getCode()) {
            case HttpStatus.Success: {
                return Long.parseLong(resultStr);
            }
            case HttpStatus.NotFound: {
                // ��master��û���յ�һ�����topic����Ϣʱ,Ŀ¼��û����.����Ĭ��offsetΪ0����
                return 0;
            }
            default:
                throw new RuntimeException("failed to query offset form " + masterServerUrl + ",topic=" + topic
                    + ",partition=" + partition.getPartition() + ",httpCode=" + resp.getCode() + ",errorMessage="
                    + resultStr);
            }

        }
        catch (final InterruptedException e) {
View Full Code Here

        if (transaction != null) {
            transaction.setTransactionInUse();
            if (context.isInRecoverMode()) {
                // �ָ�ģʽ������Ҫ����
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.Forbidden, "The broker is in recover mode.", cmd
                        .getOpaque()));
                }
                return;
            }
            final String topic = cmd.getTopic();
            final int partition = cmd.getPartition();

            final String partitionString = this.metaConfig.getBrokerId() + "-" + partition;
            if (partition == Partition.RandomPartiton.getPartition()) {
                this.statsManager.statsPutFailed(topic, partitionString, 1);
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError,
                        "Invalid partition for transaction command:" + partition, cmd.getOpaque()));
                }
                return;
            }
            final MessageStore store = this.storeManager.getOrCreateMessageStore(topic, partition);
            if (store == null) {
                this.statsManager.statsPutFailed(topic, partitionString, 1);
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError,
                        "Could not get or create message store for topic=" + topic + ",partition=" + partition, cmd
                        .getOpaque()));
                }
                return;
            }
            final long msgId = this.idWorker.nextId();
            this.transactionStore.addMessage(store, msgId, cmd, null);
            this.statsManager.statsPut(topic, partitionString, 1);
            if (cb != null) {
                cb.putComplete(new BooleanCommand(HttpStatus.Success, this.genPutResultString(partition, msgId, -1),
                    cmd.getOpaque()));
            }
        }
        else {
            super.processPutCommand(cmd, context, cb);
View Full Code Here

        try {
            if (this.metaConfig.isClosedPartition(request.getTopic(), request.getPartition())) {
                log.warn("Can not put message to partition " + request.getPartition() + " for topic="
                        + request.getTopic() + ",it was closed");
                if (cb != null) {
                    cb.putComplete(new BooleanCommand(HttpStatus.Forbidden, "Partition[" + partitionString
                        + "] has been closed", request.getOpaque()));
                }
                return;
            }
            // ����Ƕ�̬��ӵ�topic����Ҫע�ᵽzk
            this.brokerZooKeeper.registerTopicInZk(request.getTopic(), false);

            // ���slaveû�����ӣ����Ϸ���ʧ�ܣ���ֹmaster�ظ���Ϣ����
            if (!this.remotingClient.isConnected(this.slaveUrl)) {
                this.statsManager.statsPutFailed(request.getTopic(), partitionString, 1);
                cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError, "Slave is disconnected ", request
                    .getOpaque()));
                return;
            }

            final int partition = this.getPartition(request);
            final MessageStore store = this.storeManager.getOrCreateMessageStore(request.getTopic(), partition);

            // �����store��ͬ������֤ͬһ�������ڵ���Ϣ����
            synchronized (store) {
                // idҲ��������
                final long messageId = this.idWorker.nextId();
                // ����callback
                final SyncAppendCallback syncCB =
                        new SyncAppendCallback(partition, partitionString, request, messageId, cb);
                // ����slave
                this.remotingClient.sendToGroup(this.slaveUrl,
                    new SyncCommand(request.getTopic(), partition, request.getData(), request.getFlag(), messageId,
                        request.getCheckSum(), OpaqueGenerator.getNextOpaque()), syncCB,
                        this.sendToSlaveTimeoutInMills, TimeUnit.MILLISECONDS);
                // д��master
                store.append(messageId, request, syncCB);
            }
        }
        catch (final Exception e) {
            this.statsManager.statsPutFailed(request.getTopic(), partitionString, 1);
            log.error("Put message failed", e);
            if (cb != null) {
                cb.putComplete(new BooleanCommand(HttpStatus.InternalServerError, e.getMessage(), request.getOpaque()));
            }
        }
    }
View Full Code Here

        // Master Config file changed
        if (metaConfig.getConfigFileChecksum() != masterChecksum) {
            String masterUrl = this.slaveZooKeeper.getMasterServerUrl();
            for (int i = 0; i < 3; i++) {
                try {
                    BooleanCommand resp =
                            (BooleanCommand) this.sessionFactory.getRemotingClient().invokeToGroup(masterUrl,
                                new StatsCommand(OpaqueGenerator.getNextOpaque(), "config"));
                    if (resp.getResponseStatus() == ResponseStatus.NO_ERROR) {
                        this.tryReloadConfig(resp);
                        break;
                    }
                    else {
                        log.error("Get config file failed,retry " + (i + 1) + " times,error code:" + resp.getCode());
                    }
                }
                catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.network.BooleanCommand

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.