All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sirius.kernel.health.console.AsyncInfoCommand Maven / Gradle / Ivy

Go to download

Provides common core classes and the microkernel powering all Sirius applications

There is a newer version: 12.9.1
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.health.console;

import sirius.kernel.async.AsyncExecutor;
import sirius.kernel.async.BackgroundLoop;
import sirius.kernel.async.Operation;
import sirius.kernel.async.Tasks;
import sirius.kernel.commons.Tuple;
import sirius.kernel.di.PartCollection;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Parts;
import sirius.kernel.di.std.Register;
import sirius.kernel.nls.NLS;

import javax.annotation.Nonnull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * Console command which reports statistics for all known executors.
 */
@Register
public class AsyncInfoCommand implements Command {

    @Part
    private Tasks tasks;

    @Parts(BackgroundLoop.class)
    private PartCollection loops;

    @Override
    public void execute(Output output, String... params) throws Exception {
        output.apply("%-20s %8s %8s %8s %12s %8s %8s",
                     "POOL",
                     "ACTIVE",
                     "QUEUED",
                     "TOTAL",
                     "DURATION",
                     "BLOCKED",
                     "DROPPED");
        output.separator();
        for (AsyncExecutor exec : tasks.getExecutors()) {
            output.apply("%-20s %8d %8d %8d %12.1f %8d %8d",
                         exec.getCategory(),
                         exec.getActiveCount(),
                         exec.getQueue().size(),
                         exec.getExecuted(),
                         exec.getAverageDuration(),
                         exec.getBlocked(),
                         exec.getDropped());
        }
        output.separator();
        output.blankLine();
        output.apply("Frequency Limited Tasks");
        output.separator();
        for (Tuple task : tasks.getScheduledTasks()) {
            output.apply("%-60s %s", task.getFirst(), NLS.toUserString(task.getSecond()));
        }
        output.separator();
        output.blankLine();
        output.apply("Background Loops");
        output.separator();
        for (BackgroundLoop loop : loops) {
            output.apply("%-60s %s", loop.getName(), loop.getExecutionInfo());
        }
        output.separator();
        output.blankLine();
        List ops = Operation.getActiveOperations();
        if (!ops.isEmpty()) {
            output.blankLine();
            output.apply("Active Operations");
            output.separator();
            for (Operation op : ops) {
                output.line(op.toString());
            }
            output.separator();
        }
    }

    @Override
    @Nonnull
    public String getName() {
        return "async";
    }

    @Override
    public String getDescription() {
        return "Reports the status of the task queueing system";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy