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

org.neo4j.scheduler.JobMonitoringParams Maven / Gradle / Ivy

There is a newer version: 2025.03.0
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.scheduler;

import static org.neo4j.common.Subject.AUTH_DISABLED;
import static org.neo4j.common.Subject.SYSTEM;

import java.util.Objects;
import java.util.function.Supplier;
import org.neo4j.common.Subject;

public class JobMonitoringParams {
    public static final JobMonitoringParams NOT_MONITORED = new JobMonitoringParams(null, null, null, null);

    private final Subject submitter;
    private final String targetDatabaseName;
    private final String description;
    private final Supplier currentStateDescriptionSupplier;

    public JobMonitoringParams(
            Subject submitter,
            String targetDatabaseName,
            String description,
            Supplier currentStateDescriptionSupplier) {
        this.submitter = Objects.requireNonNullElse(submitter, AUTH_DISABLED);
        this.targetDatabaseName = targetDatabaseName;
        this.description = description;
        this.currentStateDescriptionSupplier = currentStateDescriptionSupplier;
    }

    public JobMonitoringParams(Subject submitter, String targetDatabaseName, String description) {
        this(submitter, targetDatabaseName, description, null);
    }

    /**
     * A convenience method for a background job performed by the DBMS itself (not triggered explicitly by an end user) and not linked to a single database.
     *
     * @param description description of the job used for monitoring purposes.
     */
    public static JobMonitoringParams systemJob(String description) {
        return new JobMonitoringParams(SYSTEM, null, description);
    }

    /**
     * A convenience method for a background job on a single database performed by the DBMS itself (not triggered explicitly by an end user).
     *
     * @param targetDatabaseName name of the database this job works with.
     * @param description description of the job used for monitoring purposes.
     */
    public static JobMonitoringParams systemJob(String targetDatabaseName, String description) {
        return new JobMonitoringParams(SYSTEM, targetDatabaseName, description);
    }

    public Subject getSubmitter() {
        return submitter;
    }

    public String getTargetDatabaseName() {
        return targetDatabaseName;
    }

    public String getDescription() {
        return description;
    }

    public String getCurrentStateDescription() {
        if (currentStateDescriptionSupplier == null) {
            return null;
        }

        return currentStateDescriptionSupplier.get();
    }

    @Override
    public String toString() {
        return "JobMonitoringParams{" + "submitter="
                + submitter + ", targetDatabaseName='"
                + targetDatabaseName + '\'' + ", description='"
                + description + '\'' + '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy