Java Code Examples for org.apache.rocketmq.common.utils.ThreadUtils

The following examples show how to use org.apache.rocketmq.common.utils.ThreadUtils. 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
@Override
public void run() {
    log.info(this.getServiceName() + " service started");

    while (!this.isStopped()) {
        try {
            DispatchRequestCollections requests = dispatchRequestBufferQueue.peek();
            if (requests.requestlist.size() > FLOW_CONTROLLER / REQUEST_BUFFER_IN_QUEUE
                    || flushCounter > CHECK_THREAD_LOOP) {
                this.doFlushDB(false);
                flushCounter = 0;
                continue;
            }
            ++flushCounter;
            ThreadUtils.sleep(10);
        } catch (Exception e) {
            log.warn(this.getServiceName() + " service has exception. ", e);
        }
    }
    log.info(this.getServiceName() + " service end");
}
 
Example 2
Source Project: DDMQ   Source File: DefaultMessageStore.java    License: Apache License 2.0 5 votes vote down vote up
public ReputMessageService() {
    if (messageStoreConfig.isReputConcurrentEnable() && messageStoreConfig.getReputConcurrentThreadCount() > 0) {
        isReputConcurrentEnable = true;
        currentThreadCount = messageStoreConfig.getReputConcurrentThreadCount();
        executors = new ExecutorService[currentThreadCount];
        for (int i = 0; i < currentThreadCount; i++) {
            executors[i] = ThreadUtils.newSingleThreadExecutor("ReputMessageConcurrent_" + i, false);
        }
    } else {
        isReputConcurrentEnable = false;
        currentThreadCount = 0;
    }
}
 
Example 3
Source Project: DDMQ   Source File: DefaultMessageStore.java    License: Apache License 2.0 5 votes vote down vote up
public ReputMessageService() {
    if (messageStoreConfig.isReputConcurrentEnable() && messageStoreConfig.getReputConcurrentThreadCount() > 0) {
        isReputConcurrentEnable = true;
        currentThreadCount = messageStoreConfig.getReputConcurrentThreadCount();
        executors = new ExecutorService[currentThreadCount];
        for (int i = 0; i < currentThreadCount; i++) {
            executors[i] = ThreadUtils.newSingleThreadExecutor("ReputMessageConcurrent_" + i, false);
        }
    } else {
        isReputConcurrentEnable = false;
        currentThreadCount = 0;
    }
}
 
Example 4
Source Project: rocketmq   Source File: ConsumeMessageOrderlyService.java    License: Apache License 2.0 5 votes vote down vote up
public void shutdown(long awaitTerminateMillis) {
    this.stopped = true;
    this.scheduledExecutorService.shutdown();
    ThreadUtils.shutdownGracefully(this.consumeExecutor, awaitTerminateMillis, TimeUnit.MILLISECONDS);
    if (MessageModel.CLUSTERING.equals(this.defaultMQPushConsumerImpl.messageModel())) {
        this.unlockAllMQ();
    }
}
 
Example 5
Source Project: DDMQ   Source File: LocalMessageCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 6
Source Project: DDMQ   Source File: PullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 7
Source Project: rocketmq-4.3.0   Source File: LocalMessageCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 8
Source Project: rocketmq-4.3.0   Source File: PullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 9
Source Project: DeFiBus   Source File: DeFiBusPullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.executorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 10
Source Project: rocketmq-read   Source File: LocalMessageCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 11
Source Project: rocketmq-read   Source File: PullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 12
Source Project: DDMQ   Source File: LocalMessageCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 13
Source Project: DDMQ   Source File: PullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 14
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 15
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 16
private void doFlushDB(boolean shutdown) {
    DispatchRequestCollections requests = dispatchRequestBufferQueue.poll();
    if (requests == null) {
        return;
    }
    if (!shutdown) {
        putEmptyRequestList();
    }
    boolean addSuccess = false, removeSuccess = false;
    LinkedHashMap<Long, TransactionRecord> prepareTrs = null;
    LinkedHashMap<Long, Void> confirmTrs = null;
    while (true) {
        if (requests.latch.get() != requests.requestlist.size() && requests.latch.get() > 0) {
            continue;
        }
        requests.latch.set(Integer.MIN_VALUE);

        if (requests.requestlist.size() == 0) {
            break;
        }
        try {
            long transactionOffset = -1L;
            //数据处理
            if (prepareTrs == null && confirmTrs == null) {
                prepareTrs = new LinkedHashMap<Long, TransactionRecord>();
                confirmTrs = new LinkedHashMap<Long, Void>();
                for (DispatchRequest request : requests.requestlist) {
                    final int tranType = MessageSysFlag.getTransactionValue(request.getSysFlag());
                    switch (tranType) {
                        case MessageSysFlag.TRANSACTION_NOT_TYPE:
                            break;
                        case MessageSysFlag.TRANSACTION_PREPARED_TYPE:
                            if (this.maxTransOffset.get() < request.getCommitLogOffset()) {
                                prepareTrs.put(request.getCommitLogOffset(), new TransactionRecord(request.getCommitLogOffset(),
                                        request.getCheckImmunityTimeOutTimestamp(), request.getMsgSize(), request.getProducerGroup()));
                                this.maxTransOffset.set(request.getCommitLogOffset());
                            } else {
                                log.info("[PREPARED] request ignore offset =" + request.getCommitLogOffset());
                            }
                            if (request.getPreparedTransactionOffset() == 0L) {
                                break;
                            }
                        case MessageSysFlag.TRANSACTION_COMMIT_TYPE:
                        case MessageSysFlag.TRANSACTION_ROLLBACK_TYPE:
                            if (this.maxTransOffset.get() < request.getCommitLogOffset()) {
                                if (prepareTrs.containsKey(request.getPreparedTransactionOffset())) {
                                    prepareTrs.remove(request.getPreparedTransactionOffset());
                                } else {
                                    confirmTrs.put(request.getPreparedTransactionOffset(), null);
                                }
                            } else {
                                log.info("[COMMIT] request ignore offset =" + request.getCommitLogOffset()
                                        + ",isCommitMessge=" + (tranType == MessageSysFlag.TRANSACTION_COMMIT_TYPE));
                            }
                            break;
                    }
                }
                transactionOffset = requests.requestlist.get(requests.requestlist.size() - 1).getCommitLogOffset();
            }

            long startTime = System.currentTimeMillis();
            addSuccess = addSuccess || transactionStore.parpare(new ArrayList<>(prepareTrs.values()));
            if (addSuccess && (removeSuccess = transactionStore.confirm(new ArrayList<>(confirmTrs.keySet())))) {
                log.info("pull TransactionRecord consume {}ms ,size={},realParpareSize={},realConfirmSize:{}",
                        (System.currentTimeMillis() - startTime), requests.requestlist.size(), prepareTrs.size(), confirmTrs.size());
                //更新最新的offset
                if (transactionOffset > 0) {
                    transactionOffsetConifgService.putOffset(transactionOffset);
                }
                break;
            }
        } catch (Throwable e) {
            log.error("transactionStore error:", e);
            ThreadUtils.sleep(2000);
        } finally {
            if (addSuccess && removeSuccess) {
                flowController.release(requests.requestlist.size());
            }
        }
    }
}
 
Example 17
Source Project: rocketmq   Source File: LocalMessageCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    ThreadUtils.shutdownGracefully(cleanExpireMsgExecutors, 5000, TimeUnit.MILLISECONDS);
}
 
Example 18
Source Project: rocketmq   Source File: PullMessageService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown(boolean interrupt) {
    super.shutdown(interrupt);
    ThreadUtils.shutdownGracefully(this.scheduledExecutorService, 1000, TimeUnit.MILLISECONDS);
}
 
Example 19
public void shutdown(long awaitTerminateMillis) {
    this.scheduledExecutorService.shutdown();
    ThreadUtils.shutdownGracefully(this.consumeExecutor, awaitTerminateMillis, TimeUnit.MILLISECONDS);
    this.cleanExpireMsgExecutors.shutdown();
}