package com.lanyuanxiaoyao.service.queue.controller;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import java.util.Collection;
import java.util.Map;
import org.eclipse.collections.api.factory.Lists;

/**
 * 队列通用操作
 *
 * @author lanyuanxiaoyao
 * @date 2023-05-07
 */
public abstract class QueueOperator {
    abstract void updateMetrics();

    protected void updateMetrics(MeterRegistry registry, String name, Map<String, ? extends Collection<?>> map) {
        map.forEach((queue, collection) -> registry.gaugeCollectionSize(
                "service_queue_size",
                Lists.immutable.of(
                        Tag.of("type", name),
                        Tag.of("name", queue)
                ),
                collection
        ));
    }
}
