Skip to content

Commit

Permalink
replace ConcurrentOpenHashMap with ConcurrentHashmap (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoran10 committed Sep 24, 2024
1 parent c5a7b05 commit 82ef279
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import static io.streamnative.pulsar.handlers.amqp.utils.ExchangeUtil.isDefaultExchange;

import io.streamnative.pulsar.handlers.amqp.common.exception.AoPException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.service.persistent.PersistentTopic;
import org.apache.pulsar.common.naming.NamespaceName;
Expand Down Expand Up @@ -168,8 +169,8 @@ public CompletableFuture<Integer> exchangeBound(NamespaceName namespaceName, Str
if (null == amqpExchange) {
replyCode = ExchangeBoundOkBody.EXCHANGE_NOT_FOUND;
} else {
List<String> subs = amqpExchange.getTopic().getSubscriptions().keys();
if (null == subs || subs.isEmpty()) {
Set<String> subs = amqpExchange.getTopic().getSubscriptions().keySet();
if (CollectionUtils.isEmpty(subs)) {
replyCode = ExchangeBoundOkBody.QUEUE_NOT_FOUND;
} else {
replyCode = ExchangeBoundOkBody.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -54,7 +55,6 @@
import org.apache.pulsar.common.naming.TopicDomain;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;

/**
* Persistent Exchange.
Expand All @@ -72,7 +72,7 @@ public class PersistentExchange extends AbstractAmqpExchange {
private static final String BINDINGS = "BINDINGS";

private PersistentTopic persistentTopic;
private final ConcurrentOpenHashMap<String, CompletableFuture<ManagedCursor>> cursors;
private final ConcurrentHashMap<String, CompletableFuture<ManagedCursor>> cursors;
private AmqpExchangeReplicator messageReplicator;
private AmqpEntryWriter amqpEntryWriter;

Expand All @@ -97,7 +97,7 @@ public PersistentExchange(String exchangeName, Type type, PersistentTopic persis
super(exchangeName, type, Sets.newConcurrentHashSet(), durable, autoDelete, internal, arguments);
this.persistentTopic = persistentTopic;
topicNameValidate();
cursors = new ConcurrentOpenHashMap<>(16, 1);
cursors = new ConcurrentHashMap<>(16, 1);
for (ManagedCursor cursor : persistentTopic.getManagedLedger().getCursors()) {
cursors.put(cursor.getName(), CompletableFuture.completedFuture(cursor));
log.info("PersistentExchange {} recover cursor {}", persistentTopic.getName(), cursor.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import lombok.extern.log4j.Log4j2;
import org.apache.bookkeeper.common.util.OrderedExecutor;
Expand All @@ -59,7 +60,6 @@
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.HierarchyTopicPolicies;
import org.apache.pulsar.common.policies.data.Policies;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
import org.apache.qpid.server.protocol.ProtocolVersion;
import org.apache.qpid.server.protocol.v0_8.AMQShortString;
import org.apache.qpid.server.protocol.v0_8.transport.AMQBody;
Expand Down Expand Up @@ -189,7 +189,7 @@ private void initMockAmqpTopicManager(){
Mockito.any(), Mockito.anyBoolean(), Mockito.any())).thenReturn(subFuture);
when(subscription.getDispatcher()).thenReturn(mock(Dispatcher.class));
when(subscription.addConsumer(Mockito.any())).thenReturn(CompletableFuture.completedFuture(null));
when(persistentTopic.getSubscriptions()).thenReturn(new ConcurrentOpenHashMap<>());
when(persistentTopic.getSubscriptions()).thenReturn(new ConcurrentHashMap<>());
ManagedLedger managedLedger = mock(ManagedLedgerImpl.class);
when(managedLedger.getCursors()).thenReturn(new ManagedCursorContainer());
when(persistentTopic.getManagedLedger()).thenReturn(managedLedger);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<project.compiler.release>${maven.compiler.target}</project.compiler.release>

<!-- dependencies -->
<pulsar.version>4.0.0-ursa-4-SNAPSHOT</pulsar.version>
<pulsar.version>4.0.0-ursa-10-SNAPSHOT</pulsar.version>
<qpid-protocol-plugin.version>8.0.0</qpid-protocol-plugin.version>
<rabbitmq.version>5.8.0</rabbitmq.version>

Expand Down

0 comments on commit 82ef279

Please sign in to comment.