mirror of
https://github.com/apache/rocketmq.git
synced 2026-09-21 05:44:03 +08:00
[ISSUE #4327] Init collection size
This commit is contained in:
@@ -640,7 +640,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSubscription(Map<String, String> subscription) {
|
||||
Map<String, String> subscriptionWithNamespace = new HashMap<String, String>();
|
||||
Map<String, String> subscriptionWithNamespace = new HashMap<String, String>(subscription.size(), 1);
|
||||
for (Entry<String, String> topicEntry : subscription.entrySet()) {
|
||||
subscriptionWithNamespace.put(withNamespace(topicEntry.getKey()), topicEntry.getValue());
|
||||
}
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@ public class LocalFileOffsetStore implements OffsetStore {
|
||||
|
||||
@Override
|
||||
public Map<MessageQueue, Long> cloneOffsetTable(String topic) {
|
||||
Map<MessageQueue, Long> cloneOffsetTable = new HashMap<MessageQueue, Long>();
|
||||
Map<MessageQueue, Long> cloneOffsetTable = new HashMap<MessageQueue, Long>(this.offsetTable.size(), 1);
|
||||
for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
|
||||
MessageQueue mq = entry.getKey();
|
||||
if (!UtilAll.isBlank(topic) && !topic.equals(mq.getTopic())) {
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
|
||||
|
||||
@Override
|
||||
public Map<MessageQueue, Long> cloneOffsetTable(String topic) {
|
||||
Map<MessageQueue, Long> cloneOffsetTable = new HashMap<MessageQueue, Long>();
|
||||
Map<MessageQueue, Long> cloneOffsetTable = new HashMap<MessageQueue, Long>(this.offsetTable.size(), 1);
|
||||
for (Map.Entry<MessageQueue, AtomicLong> entry : this.offsetTable.entrySet()) {
|
||||
MessageQueue mq = entry.getKey();
|
||||
if (!UtilAll.isBlank(topic) && !topic.equals(mq.getTopic())) {
|
||||
|
||||
@@ -388,7 +388,7 @@ public class MQClientAPIImpl {
|
||||
clusterAclVersionInfo.setBrokerAddr(responseHeader.getBrokerAddr());
|
||||
clusterAclVersionInfo.setAclConfigDataVersion(DataVersion.fromJson(responseHeader.getVersion(), DataVersion.class));
|
||||
HashMap<String, Object> dataVersionMap = JSON.parseObject(responseHeader.getAllAclFileVersion(), HashMap.class);
|
||||
Map<String, DataVersion> allAclConfigDataVersion = new HashMap<String, DataVersion>();
|
||||
Map<String, DataVersion> allAclConfigDataVersion = new HashMap<String, DataVersion>(dataVersionMap.size(), 1);
|
||||
for (Map.Entry<String, Object> entry : dataVersionMap.entrySet()) {
|
||||
allAclConfigDataVersion.put(entry.getKey(),DataVersion.fromJson(JSON.toJSONString(entry.getValue()), DataVersion.class));
|
||||
}
|
||||
|
||||
+3
-2
@@ -28,6 +28,7 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.rocketmq.client.QueryResult;
|
||||
import org.apache.rocketmq.client.Validators;
|
||||
@@ -962,8 +963,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
for (String topic : rebalanceImpl.getSubscriptionInner().keySet()) {
|
||||
Set<MessageQueue> mqs = rebalanceImpl.getTopicSubscribeInfoTable().get(topic);
|
||||
Map<MessageQueue, Long> offsetTable = new HashMap<MessageQueue, Long>();
|
||||
if (mqs != null) {
|
||||
if (CollectionUtils.isNotEmpty(mqs)) {
|
||||
Map<MessageQueue, Long> offsetTable = new HashMap<MessageQueue, Long>(mqs.size(), 1);
|
||||
for (MessageQueue mq : mqs) {
|
||||
long offset = searchOffset(mq, timeStamp);
|
||||
offsetTable.put(mq, offset);
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class RebalanceImpl {
|
||||
}
|
||||
|
||||
private HashMap<String/* brokerName */, Set<MessageQueue>> buildProcessQueueTableByBrokerName() {
|
||||
HashMap<String, Set<MessageQueue>> result = new HashMap<String, Set<MessageQueue>>();
|
||||
HashMap<String, Set<MessageQueue>> result = new HashMap<String, Set<MessageQueue>>(this.processQueueTable.size(), 1);
|
||||
for (MessageQueue mq : this.processQueueTable.keySet()) {
|
||||
Set<MessageQueue> mqs = result.get(mq.getBrokerName());
|
||||
if (null == mqs) {
|
||||
|
||||
@@ -366,7 +366,7 @@ public class MQClientInstance {
|
||||
* @return newOffsetTable
|
||||
*/
|
||||
public Map<MessageQueue, Long> parseOffsetTableFromBroker(Map<MessageQueue, Long> offsetTable, String namespace) {
|
||||
HashMap<MessageQueue, Long> newOffsetTable = new HashMap<MessageQueue, Long>();
|
||||
HashMap<MessageQueue, Long> newOffsetTable = new HashMap<MessageQueue, Long>(offsetTable.size(), 1);
|
||||
if (StringUtils.isNotEmpty(namespace)) {
|
||||
for (Entry<MessageQueue, Long> entry : offsetTable.entrySet()) {
|
||||
MessageQueue queue = entry.getKey();
|
||||
@@ -387,7 +387,7 @@ public class MQClientInstance {
|
||||
try {
|
||||
if (this.lockNamesrv.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS))
|
||||
try {
|
||||
ConcurrentHashMap<String, HashMap<Long, String>> updatedTable = new ConcurrentHashMap<String, HashMap<Long, String>>();
|
||||
ConcurrentHashMap<String, HashMap<Long, String>> updatedTable = new ConcurrentHashMap<String, HashMap<Long, String>>(this.brokerAddrTable.size(), 1);
|
||||
|
||||
Iterator<Entry<String, HashMap<Long, String>>> itBrokerTable = this.brokerAddrTable.entrySet().iterator();
|
||||
while (itBrokerTable.hasNext()) {
|
||||
@@ -395,7 +395,7 @@ public class MQClientInstance {
|
||||
String brokerName = entry.getKey();
|
||||
HashMap<Long, String> oneTable = entry.getValue();
|
||||
|
||||
HashMap<Long, String> cloneAddrTable = new HashMap<Long, String>();
|
||||
HashMap<Long, String> cloneAddrTable = new HashMap<Long, String>(oneTable.size(), 1);
|
||||
cloneAddrTable.putAll(oneTable);
|
||||
|
||||
Iterator<Entry<Long, String>> it = cloneAddrTable.entrySet().iterator();
|
||||
|
||||
@@ -330,6 +330,7 @@ public class AsyncTraceDispatcher implements TraceDispatcher {
|
||||
traceExecutor.submit(asyncDataSendTask);
|
||||
|
||||
this.clear();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user