mirror of
https://github.com/apache/rocketmq.git
synced 2026-09-24 16:04:00 +08:00
Merge pull request #3182 from lwclover/develop
[ISSUE #3183]add synchronization for producer on method registerProducer & unregisterProducer
This commit is contained in:
@@ -882,24 +882,6 @@ public class MQClientInstance {
|
||||
this.unregisterClient(null, group);
|
||||
}
|
||||
|
||||
private void unregisterClientWithLock(final String producerGroup, final String consumerGroup) {
|
||||
try {
|
||||
if (this.lockHeartbeat.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
this.unregisterClient(producerGroup, consumerGroup);
|
||||
} catch (Exception e) {
|
||||
log.error("unregisterClient exception", e);
|
||||
} finally {
|
||||
this.lockHeartbeat.unlock();
|
||||
}
|
||||
} else {
|
||||
log.warn("lock heartBeat, but failed. [{}]", this.clientId);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("unregisterClientWithLock exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterClient(final String producerGroup, final String consumerGroup) {
|
||||
Iterator<Entry<String, HashMap<Long, String>>> it = this.brokerAddrTable.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
@@ -927,7 +909,7 @@ public class MQClientInstance {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean registerProducer(final String group, final DefaultMQProducerImpl producer) {
|
||||
public synchronized boolean registerProducer(final String group, final DefaultMQProducerImpl producer) {
|
||||
if (null == group || null == producer) {
|
||||
return false;
|
||||
}
|
||||
@@ -941,9 +923,9 @@ public class MQClientInstance {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void unregisterProducer(final String group) {
|
||||
public synchronized void unregisterProducer(final String group) {
|
||||
this.producerTable.remove(group);
|
||||
this.unregisterClientWithLock(group, null);
|
||||
this.unregisterClient(group, null);
|
||||
}
|
||||
|
||||
public boolean registerAdminExt(final String group, final MQAdminExtInner admin) {
|
||||
|
||||
Reference in New Issue
Block a user