@Override public void publishAsync(Record record, PublishCallback callback) { queue.add(new AsyncRecord(record, callback)); }
public ProducerPipe(ProducerPipeConfig config, Producer<K, V> producer, String threadName, ExceptionHandler exceptionHandler) { this.producer = producer; this.exceptionHandler = exceptionHandler; if (config.isAsync()) { queue = new NodeQueue<>(); queueConsumer = queue.consumer(); thread = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(this::cycle) .buildAndStart(); } else { queue = null; queueConsumer = null; thread = null; } }
@Override public void attach(MessageHandler handler) { if (handler.getGroupId() != null && ! groups.add(handler.getGroupId())) return; final WorkerThread thread = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(MultiNodeQueueLedger.class, handler.getGroupId())) .onCycle(new NodeWorker(handler, handler.getGroupId(), queue.consumer())) .buildAndStart(); threads.add(thread); }
@Override public void append(Message message, AppendCallback callback) { if (debugMessageCounts != 0) { final long appends = this.appends.getAndIncrement(); if (appends % debugMessageCounts == 0) { logLine.accept(String.format("appends=%,d", appends)); } } queue.add(message); callback.onAppend(message.getMessageId(), null); }
@Override public void append(Message message, AppendCallback callback) { queue.add(message); callback.onAppend(message.getMessageId(), null); }
/** * Pushes a record and an optional send callback through the pipeline. * * @param record The record. * @param callback The callback (may be {@code null}). */ public void send(ProducerRecord<K, V> record, Callback callback) { if (thread != null) { queue.add(new AsyncRecord<>(record, callback)); } else { sendNow(record, callback); } }
private void decideBallot(PendingBallot ballot) { zlg.t("Decided ballot for %s: resolution: %s", z -> z.arg(ballot::getProposal).arg(ballot::getResolution)); final Proposal proposal = ballot.getProposal(); final String xid = proposal.getXid(); final Object metadata = metadataEnabled ? new OutcomeMetadata(proposal.getTimestamp()) : null; final Outcome outcome = new Outcome(xid, ballot.getResolution(), ballot.getAbortReason(), ballot.getResponses(), metadata) .inResponseTo(proposal).withSource(groupId); pending.remove(xid); if (trackingEnabled) { additions.add(outcome); } action.appendOutcome(outcome, (id, x) -> { if (x == null) { ballot.getConfirmation().confirm(); } else { zlg.w("Error appending to ledger [message: %s]", z -> z.arg(outcome).threw(x)); } }); }