use of org.apache.pulsar.broker.service.Replicator in project incubator-pulsar by apache.
the class NonPersistentTopic method publishMessage.
@Override
public void publishMessage(ByteBuf data, PublishContext callback) {
AtomicInteger msgDeliveryCount = new AtomicInteger(2);
ENTRIES_ADDED_COUNTER_UPDATER.incrementAndGet(this);
// retain data for sub/replication because io-thread will release actual payload
data.retain(2);
this.executor.submitOrdered(topic, SafeRun.safeRun(() -> {
subscriptions.forEach((name, subscription) -> {
ByteBuf duplicateBuffer = data.retainedDuplicate();
Entry entry = create(0L, 0L, duplicateBuffer);
// entry internally retains data so, duplicateBuffer should be release here
duplicateBuffer.release();
if (subscription.getDispatcher() != null) {
subscription.getDispatcher().sendMessages(Lists.newArrayList(entry));
} else {
// it happens when subscription is created but dispatcher is not created as consumer is not added
// yet
entry.release();
}
});
data.release();
if (msgDeliveryCount.decrementAndGet() == 0) {
callback.completed(null, 0L, 0L);
}
}));
this.executor.submitOrdered(topic, SafeRun.safeRun(() -> {
replicators.forEach((name, replicator) -> {
ByteBuf duplicateBuffer = data.retainedDuplicate();
Entry entry = create(0L, 0L, duplicateBuffer);
// entry internally retains data so, duplicateBuffer should be release here
duplicateBuffer.release();
((NonPersistentReplicator) replicator).sendMessage(entry);
});
data.release();
if (msgDeliveryCount.decrementAndGet() == 0) {
callback.completed(null, 0L, 0L);
}
}));
}
use of org.apache.pulsar.broker.service.Replicator in project incubator-pulsar by apache.
the class PersistentTopic method startReplProducers.
public void startReplProducers() {
// read repl-cluster from policies to avoid restart of replicator which are in process of disconnect and close
try {
Policies policies = brokerService.pulsar().getConfigurationCache().policiesCache().get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())).orElseThrow(() -> new KeeperException.NoNodeException());
if (policies.replication_clusters != null) {
Set<String> configuredClusters = Sets.newTreeSet(policies.replication_clusters);
replicators.forEach((region, replicator) -> {
if (configuredClusters.contains(region)) {
replicator.startProducer();
}
});
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("[{}] Error getting policies while starting repl-producers {}", topic, e.getMessage());
}
replicators.forEach((region, replicator) -> replicator.startProducer());
}
}
Aggregations