@Override public Confirmation begin(MessageContext context, Message message) { return NopConfirmation.getInstance(); } }
static FlowConfirmation anchor(Flow flow) { return new FlowConfirmation(flow, null); } }
public FlowConfirmation begin(Object id, Runnable task) { final FlowConfirmation confirmation = confirmations.computeIfAbsent(id, __id -> { final FlowConfirmation newConfirmation = new FlowConfirmation(id, task); newConfirmation.appendTo(tail); return newConfirmation; }); confirmation.addRequest(); return confirmation; }
@Override public void cycle(WorkerThread thread) throws InterruptedException { if (current != null) { if (current.isAnchor()) { // skip the anchor } else if (current.isConfirmed()) { flow.removeWithoutCompleting(current.getId()); complete = current; } else { if (complete != null) { flow.complete(complete); complete = null; } Thread.sleep(CYCLE_IDLE_INTERVAL_MILLIS); return; } } else { Thread.sleep(CYCLE_IDLE_INTERVAL_MILLIS); } current = head.next(); if (current != null) { head = current; } else if (complete != null) { flow.complete(complete); complete = null; } } }
@Override public void cycle(WorkerThread thread) throws InterruptedException { if (current != null) { if (current.isAnchor()) { // skip the anchor } else if (current.isConfirmed()) { flow.complete(current); } else { Thread.sleep(CYCLE_IDLE_INTERVAL_MILLIS); return; } } else { Thread.sleep(CYCLE_IDLE_INTERVAL_MILLIS); } current = head.next(); if (current != null) { head = current; } } }
@Override public Confirmation begin(MessageContext context, Message message) { final Flow flow = flows.computeIfAbsent(message.getShard(), shard -> { final Flow newFlow = new Flow(firingStrategyFactory, Flow.class.getSimpleName() + "-shard-[" + shard + "]"); synchronized (terminateLock) { createdFlows.add(newFlow); if (terminated) { // the container was already terminated -- terminate the newly created flow; the resulting Confirmation // objects won't do anything newFlow.terminate(); } } return newFlow; }); final MessageId messageId = message.getMessageId(); return flow.begin(messageId, new ConfirmTask(context, messageId)); }
default void beginAndConfirm(Message message) { begin(message).confirm(); } }
public Flow(FiringStrategy.Factory firingStrategyFactory, String threadName) { executor = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(firingStrategyFactory.create(this, tail)) .buildAndStart(); }
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)); } }); }