Java Code Examples for org.apache.rocketmq.common.UtilAll

The following examples show how to use org.apache.rocketmq.common.UtilAll. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DDMQ   Source File: Validators.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate topic
 */
public static void checkTopic(String topic) throws MQClientException {
    if (UtilAll.isBlank(topic)) {
        throw new MQClientException("The specified topic is blank", null);
    }

    if (!regularExpressionMatcher(topic, PATTERN)) {
        throw new MQClientException(String.format(
            "The specified topic[%s] contains illegal characters, allowing only %s", topic,
            VALID_PATTERN_STR), null);
    }

    if (topic.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("The specified topic is longer than topic max length 255.", null);
    }

    //whether the same with system reserved keyword
    if (topic.equals(MixAll.DEFAULT_TOPIC)) {
        throw new MQClientException(
            String.format("The topic[%s] is conflict with default topic.", topic), null);
    }
}
 
Example 2
Source Project: rocketmq-4.3.0   Source File: ConsumeQueueExtTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet_invalidAddress() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount);

    try {
        ConsumeQueueExt.CqExtUnit unit = consumeQueueExt.get(0);

        assertThat(unit).isNull();

        long addr = (cqExtFileSize / unitSizeWithBitMap) * unitSizeWithBitMap;
        addr += unitSizeWithBitMap;

        unit = consumeQueueExt.get(addr);
        assertThat(unit).isNull();
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example 3
Source Project: DDMQ   Source File: ClientRemotingProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumerRunningInfoRequestHeader requestHeader =
        (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);

    ConsumerRunningInfo consumerRunningInfo = this.mqClientFactory.consumerRunningInfo(requestHeader.getConsumerGroup());
    if (null != consumerRunningInfo) {
        if (requestHeader.isJstackEnable()) {
            Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
            String jstack = UtilAll.jstack(map);
            consumerRunningInfo.setJstack(jstack);
        }

        response.setCode(ResponseCode.SUCCESS);
        response.setBody(consumerRunningInfo.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example 4
Source Project: DDMQ   Source File: ClientConfig.java    License: Apache License 2.0 6 votes vote down vote up
public String buildMQClientId() {
    if (clientId != null) {
        return clientId;
    }

    StringBuilder sb = new StringBuilder();
    sb.append(this.getClientIP());

    sb.append("@");
    sb.append(this.getInstanceName());
    if (!UtilAll.isBlank(this.unitName)) {
        sb.append("@");
        sb.append(this.unitName);
    }

    return sb.toString();
}
 
Example 5
Source Project: rocketmq-4.3.0   Source File: StoreCheckpoint.java    License: Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example 6
Source Project: DDMQ   Source File: MessageClientIDSetter.java    License: Apache License 2.0 6 votes vote down vote up
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example 7
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example 8
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example 9
Source Project: DDMQ   Source File: MessageClientIDSetter.java    License: Apache License 2.0 6 votes vote down vote up
public static Date getNearlyTimeFromID(String msgID) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    byte[] bytes = UtilAll.string2bytes(msgID);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put((byte) 0);
    buf.put(bytes, 10, 4);
    buf.position(0);
    long spanMS = buf.getLong();
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    long monStartTime = cal.getTimeInMillis();
    if (monStartTime + spanMS >= now) {
        cal.add(Calendar.MONTH, -1);
        monStartTime = cal.getTimeInMillis();
    }
    cal.setTimeInMillis(monStartTime + spanMS);
    return cal.getTime();
}
 
Example 10
Source Project: rocketmq   Source File: ConsumeQueueExtTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example 11
Source Project: DDMQ   Source File: MappedFile.java    License: Apache License 2.0 6 votes vote down vote up
public boolean destroy(final long intervalForcibly) {
    this.shutdown(intervalForcibly);

    if (this.isCleanupOver()) {
        try {
            this.fileChannel.close();
            log.info("close file channel " + this.fileName + " OK");

            long beginTime = System.currentTimeMillis();
            boolean result = this.file.delete();
            log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName
                + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:"
                + this.getFlushedPosition() + ", "
                + UtilAll.computeEclipseTimeMilliseconds(beginTime));
        } catch (Exception e) {
            log.warn("close file channel " + this.fileName + " Failed. ", e);
        }

        return true;
    } else {
        log.warn("destroy mapped file[REF:" + this.getRefCount() + "] " + this.fileName
            + " Failed. cleanupOver: " + this.cleanupOver);
    }

    return false;
}
 
Example 12
Source Project: DDMQ   Source File: StoreCheckpoint.java    License: Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example 13
Source Project: DDMQ   Source File: StoreCheckpoint.java    License: Apache License 2.0 6 votes vote down vote up
public StoreCheckpoint(final String scpPath) throws IOException {
    File file = new File(scpPath);
    MappedFile.ensureDirOK(file.getParent());
    boolean fileExists = file.exists();

    this.randomAccessFile = new RandomAccessFile(file, "rw");
    this.fileChannel = this.randomAccessFile.getChannel();
    this.mappedByteBuffer = fileChannel.map(MapMode.READ_WRITE, 0, MappedFile.OS_PAGE_SIZE);

    if (fileExists) {
        log.info("store checkpoint file exists, " + scpPath);
        this.physicMsgTimestamp = this.mappedByteBuffer.getLong(0);
        this.logicsMsgTimestamp = this.mappedByteBuffer.getLong(8);
        this.indexMsgTimestamp = this.mappedByteBuffer.getLong(16);

        log.info("store checkpoint file physicMsgTimestamp " + this.physicMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.physicMsgTimestamp));
        log.info("store checkpoint file logicsMsgTimestamp " + this.logicsMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.logicsMsgTimestamp));
        log.info("store checkpoint file indexMsgTimestamp " + this.indexMsgTimestamp + ", "
            + UtilAll.timeMillisToHumanString(this.indexMsgTimestamp));
    } else {
        log.info("store checkpoint file not exists, " + scpPath);
    }
}
 
Example 14
Source Project: rocketmq-4.3.0   Source File: ConsumeQueueExtTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example 15
Source Project: DDMQ   Source File: ConsumeQueueExtTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example 16
Source Project: rocketmq-read   Source File: ConsumeQueueExtTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateByMaxOffset() {
    ConsumeQueueExt consumeQueueExt = genExt();

    putSth(consumeQueueExt, false, true, unitCount * 2);

    try {
        // truncate, only first 3 files exist.
        long address = consumeQueueExt.decorate(cqExtFileSize * 2 + unitSizeWithBitMap);

        long expectMaxAddress = address + unitSizeWithBitMap;

        consumeQueueExt.truncateByMaxAddress(address);

        long maxAddress = consumeQueueExt.getMaxAddress();

        assertThat(expectMaxAddress).isEqualTo(maxAddress);
    } finally {
        consumeQueueExt.destroy();
        UtilAll.deleteFile(new File(storePath));
    }
}
 
Example 17
Source Project: rocketmq   Source File: Validators.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate topic
 *
 * @param topic
 * @throws MQClientException
 */
public static void checkTopic(String topic) throws MQClientException {
    if (UtilAll.isBlank(topic)) {
        throw new MQClientException("The specified topic is blank", null);
    }

    if (!regularExpressionMatcher(topic, PATTERN)) {
        throw new MQClientException(String.format(
            "The specified topic[%s] contains illegal characters, allowing only %s", topic,
            VALID_PATTERN_STR), null);
    }

    if (topic.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("The specified topic is longer than topic max length 255.", null);
    }

    //whether the same with system reserved keyword
    if (topic.equals(MixAll.DEFAULT_TOPIC)) {
        throw new MQClientException(
            String.format("The topic[%s] is conflict with default topic.", topic), null);
    }
}
 
Example 18
Source Project: DDMQ   Source File: FiltersrvController.java    License: Apache License 2.0 5 votes vote down vote up
public boolean initialize() {

        MixAll.printObjectProperties(log, this.filtersrvConfig);

        this.remotingServer = new NettyRemotingServer(this.nettyServerConfig);

        this.remotingExecutor =
            Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(),
                new ThreadFactoryImpl("RemotingExecutorThread_"));

        this.registerProcessor();

        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                FiltersrvController.this.registerFilterServerToBroker();
            }
        }, 3, 10, TimeUnit.SECONDS);

        this.defaultMQPullConsumer.setBrokerSuspendMaxTimeMillis(this.defaultMQPullConsumer
            .getBrokerSuspendMaxTimeMillis() - 1000);
        this.defaultMQPullConsumer.setConsumerTimeoutMillisWhenSuspend(this.defaultMQPullConsumer
            .getConsumerTimeoutMillisWhenSuspend() - 1000);

        this.defaultMQPullConsumer.setNamesrvAddr(this.filtersrvConfig.getNamesrvAddr());
        this.defaultMQPullConsumer.setInstanceName(String.valueOf(UtilAll.getPid()));

        return true;
    }
 
Example 19
Source Project: rocketmq-4.3.0   Source File: MessageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
public static String createMessageId(SocketAddress socketAddress, long transactionIdhashCode) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH);
    InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
    byteBuffer.put(inetSocketAddress.getAddress().getAddress());
    byteBuffer.putInt(inetSocketAddress.getPort());
    byteBuffer.putLong(transactionIdhashCode);
    byteBuffer.flip();
    return UtilAll.bytes2string(byteBuffer.array());
}
 
Example 20
Source Project: DDMQ   Source File: Validators.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate group
 */
public static void checkGroup(String group) throws MQClientException {
    if (UtilAll.isBlank(group)) {
        throw new MQClientException("the specified group is blank", null);
    }
    if (!regularExpressionMatcher(group, PATTERN)) {
        throw new MQClientException(String.format(
            "the specified group[%s] contains illegal characters, allowing only %s", group,
            VALID_PATTERN_STR), null);
    }
    if (group.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("the specified group is longer than group max length 255.", null);
    }
}
 
Example 21
Source Project: DDMQ   Source File: Validators.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate group
 */
public static void checkGroup(String group) throws MQClientException {
    if (UtilAll.isBlank(group)) {
        throw new MQClientException("the specified group is blank", null);
    }
    if (!regularExpressionMatcher(group, PATTERN)) {
        throw new MQClientException(String.format(
            "the specified group[%s] contains illegal characters, allowing only %s", group,
            VALID_PATTERN_STR), null);
    }
    if (group.length() > CHARACTER_MAX_LENGTH) {
        throw new MQClientException("the specified group is longer than group max length 255.", null);
    }
}
 
Example 22
Source Project: rocketmq-read   Source File: DefaultMessageStoreTest.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void destory() {
    messageStore.shutdown();
    messageStore.destroy();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    File file = new File(messageStoreConfig.getStorePathRootDir());
    UtilAll.deleteFile(file);
}
 
Example 23
Source Project: rocketmq-read   Source File: MappedFile.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 销毁文件
 * @param intervalForcibly 周期
 * @return ;
 */
public boolean destroy(final long intervalForcibly) {
    //shutdown
    this.shutdown(intervalForcibly);

    //执行cleanupOver成功
    if (this.isCleanupOver()) {
        try {
            //fileChannel.close()
            this.fileChannel.close();
            log.info("close file channel " + this.fileName + " OK");

            long beginTime = System.currentTimeMillis();
            boolean result = this.file.delete();
            log.info("delete file[REF:" + this.getRefCount() + "] " + this.fileName
                + (result ? " OK, " : " Failed, ") + "W:" + this.getWrotePosition() + " M:"
                + this.getFlushedPosition() + ", "
                + UtilAll.computeEclipseTimeMilliseconds(beginTime));
        } catch (Exception e) {
            log.warn("close file channel " + this.fileName + " Failed. ", e);
        }

        return true;
    } else {
        log.warn("destroy mapped file[REF:" + this.getRefCount() + "] " + this.fileName
            + " Failed. cleanupOver: " + this.cleanupOver);
    }

    return false;
}
 
Example 24
Source Project: DDMQ   Source File: AdminBrokerProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    CloneGroupOffsetRequestHeader requestHeader =
        (CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class);

    Set<String> topics;
    if (UtilAll.isBlank(requestHeader.getTopic())) {
        topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getSrcGroup());
    } else {
        topics = new HashSet<String>();
        topics.add(requestHeader.getTopic());
    }

    for (String topic : topics) {
        TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
        if (null == topicConfig) {
            log.warn("[cloneGroupOffset], topic config not exist, {}", topic);
            continue;
        }

        if (!requestHeader.isOffline()) {

            SubscriptionData findSubscriptionData =
                this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getSrcGroup(), topic);
            if (this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getSrcGroup()) > 0
                && findSubscriptionData == null) {
                log.warn("[cloneGroupOffset], the consumer group[{}], topic[{}] not exist", requestHeader.getSrcGroup(), topic);
                continue;
            }
        }

        this.brokerController.getConsumerOffsetManager().cloneOffset(requestHeader.getSrcGroup(), requestHeader.getDestGroup(),
            requestHeader.getTopic());
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example 25
Source Project: rocketmq-read   Source File: MessageDecoder.java    License: Apache License 2.0 5 votes vote down vote up
public static String createMessageId(SocketAddress socketAddress, long transactionIdhashCode) {
    ByteBuffer byteBuffer = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH);
    InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
    byteBuffer.put(inetSocketAddress.getAddress().getAddress());
    byteBuffer.putInt(inetSocketAddress.getPort());
    byteBuffer.putLong(transactionIdhashCode);
    byteBuffer.flip();
    return UtilAll.bytes2string(byteBuffer.array());
}
 
Example 26
Source Project: DDMQ   Source File: SendMessageProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private String diskUtil() {
    String storePathPhysic = this.brokerController.getMessageStoreConfig().getStorePathCommitLog();
    double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic);

    String storePathLogis =
        StorePathConfigHelper.getStorePathConsumeQueue(this.brokerController.getMessageStoreConfig().getStorePathRootDir());
    double logisRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogis);

    String storePathIndex =
        StorePathConfigHelper.getStorePathIndex(this.brokerController.getMessageStoreConfig().getStorePathRootDir());
    double indexRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathIndex);

    return String.format("CL: %5.2f CQ: %5.2f INDEX: %5.2f", physicRatio, logisRatio, indexRatio);
}
 
Example 27
Source Project: rocketmq   Source File: ResetOffsetByTimeOldCommand.java    License: Apache License 2.0 5 votes vote down vote up
public static void resetOffset(DefaultMQAdminExt defaultMQAdminExt, String consumerGroup, String topic, long timestamp, boolean force,
    String timeStampStr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    List<RollbackStats> rollbackStatsList = defaultMQAdminExt.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force);
    System.out.printf(
        "rollback consumer offset by specified consumerGroup[%s], topic[%s], force[%s], timestamp(string)[%s], timestamp(long)[%s]%n",
        consumerGroup, topic, force, timeStampStr, timestamp);

    System.out.printf("%-20s  %-20s  %-20s  %-20s  %-20s  %-20s%n",
        "#brokerName",
        "#queueId",
        "#brokerOffset",
        "#consumerOffset",
        "#timestampOffset",
        "#rollbackOffset"
    );

    for (RollbackStats rollbackStats : rollbackStatsList) {
        System.out.printf("%-20s  %-20d  %-20d  %-20d  %-20d  %-20d%n",
            UtilAll.frontStringAtLeast(rollbackStats.getBrokerName(), 32),
            rollbackStats.getQueueId(),
            rollbackStats.getBrokerOffset(),
            rollbackStats.getConsumerOffset(),
            rollbackStats.getTimestampOffset(),
            rollbackStats.getRollbackOffset()
        );
    }
}
 
Example 28
Source Project: rocketmq_trans_message   Source File: TopAddressing.java    License: Apache License 2.0 5 votes vote down vote up
public final String fetchNSAddr(boolean verbose, long timeoutMills) {
    String url = this.wsAddr;
    try {
        if (!UtilAll.isBlank(this.unitName)) {
            url = url + "-" + this.unitName + "?nofix=1";
        }
        HttpTinyClient.HttpResult result = HttpTinyClient.httpGet(url, null, null, "UTF-8", timeoutMills);
        if (200 == result.code) {
            String responseStr = result.content;
            if (responseStr != null) {
                return clearNewLine(responseStr);
            } else {
                log.error("fetch nameserver address is null");
            }
        } else {
            log.error("fetch nameserver address failed. statusCode={}", result.code);
        }
    } catch (IOException e) {
        if (verbose) {
            log.error("fetch name server address exception", e);
        }
    }

    if (verbose) {
        String errorMsg =
            "connect to " + url + " failed, maybe the domain name " + MixAll.WS_DOMAIN_NAME + " not bind in /etc/hosts";
        errorMsg += FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL);

        log.warn(errorMsg);
    }
    return null;
}
 
Example 29
Source Project: DDMQ   Source File: PrintMessageByQueueCommand.java    License: Apache License 2.0 5 votes vote down vote up
public static long timestampFormat(final String value) {
    long timestamp = 0;
    try {
        timestamp = Long.parseLong(value);
    } catch (NumberFormatException e) {

        timestamp = UtilAll.parseDate(value, UtilAll.YYYY_MM_DD_HH_MM_SS_SSS).getTime();
    }

    return timestamp;
}
 
Example 30
Source Project: rocketmq-4.3.0   Source File: DefaultRequestProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private boolean checksum(ChannelHandlerContext ctx, RemotingCommand request,
    RegisterBrokerRequestHeader requestHeader) {
    if (requestHeader.getBodyCrc32() != 0) {
        final int crc32 = UtilAll.crc32(request.getBody());
        if (crc32 != requestHeader.getBodyCrc32()) {
            log.warn(String.format("receive registerBroker request,crc32 not match,from %s",
                RemotingHelper.parseChannelRemoteAddr(ctx.channel())));
            return false;
        }
    }
    return true;
}