Search in sources :

Example 1 with SimpleReconcilerEvent

use of com.netflix.titus.common.framework.simplereconciler.SimpleReconcilerEvent in project titus-control-plane by Netflix.

the class EventDistributor method doLoop.

private void doLoop() {
    while (true) {
        if (shutdown) {
            completeEmitters();
            return;
        }
        Stopwatch start = Stopwatch.createStarted();
        List<SimpleReconcilerEvent<DATA>> events = new ArrayList<>();
        try {
            SimpleReconcilerEvent<DATA> event = eventQueue.poll(1, TimeUnit.MILLISECONDS);
            if (event != null) {
                events.add(event);
            }
        } catch (InterruptedException ignore) {
        }
        // Build snapshot early before draining the event queue
        List<SimpleReconcilerEvent<DATA>> snapshot = null;
        if (!sinkQueue.isEmpty()) {
            snapshot = snapshotSupplier.get();
        }
        eventQueue.drainTo(events);
        eventQueueDepth.accumulateAndGet(events.size(), (current, delta) -> current - delta);
        // We emit events to already connected sinks first. For new sinks, we build snapshot and merge it with the
        // pending event queue in addNewSinks method.
        processEvents(events);
        removeUnsubscribedSinks();
        if (snapshot != null) {
            addNewSinks(snapshot, events);
        }
        metricEmittedEvents.increment(events.size());
        metricLoopExecutionTime.record(start.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
    }
}
Also used : SimpleReconcilerEvent(com.netflix.titus.common.framework.simplereconciler.SimpleReconcilerEvent) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 SimpleReconcilerEvent (com.netflix.titus.common.framework.simplereconciler.SimpleReconcilerEvent)1 ArrayList (java.util.ArrayList)1