internal virtual long Send() { // Sort in reverse, so the elements we want to send first are at the end. _batches.sort(_ticketedBatchComparator); long idleTimeSum = 0; long batchesDone = 0; for (int i = _batches.Count - 1; i >= 0; i--) { TicketedBatch batch = _batches[i]; if (batch.Ticket == _lastSendTicket + 1) { _batches.RemoveAt(i); _lastSendTicket = batch.Ticket; idleTimeSum += _downstream.receive(batch.Ticket, batch.Batch); batchesDone++; } else { break; } } _doneBatches.getAndAdd(batchesDone); return(idleTimeSum); }
internal SendDownstream(long ticket, object batch, LongAdder downstreamIdleTime) { this._downstreamIdleTime = downstreamIdleTime; TicketedBatch b = new TicketedBatch(ticket, batch); _head = b; _tail = b; }
internal virtual void Queue(TicketedBatch batch) { // Check that this is not a marker to flush the downstream. if (batch.Ticket != -1 && batch.Batch != null) { _batches.Add(batch); } }
public override void Apply(Downstream downstream) { TicketedBatch next = _head; do { downstream.Queue(next); next = next.Next; } while (next != null); _downstreamIdleTime.add(downstream.Send()); }
public override SendDownstream Combine(SendDownstream work) { _tail.next = work._head; _tail = work._tail; return(this); }