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

ca.sm360.cronitor.client.CronitorClient Maven / Gradle / Ivy

Go to download

cronitor-client is a simple Java library designed to help you monitoring, with www.cronitor.io, the routines of your Java projects

There is a newer version: 1.0.1
Show newest version
package ca.sm360.cronitor.client;

import ca.sm360.cronitor.client.urlgenerators.CompleteCommandUrlGenerator;
import ca.sm360.cronitor.client.urlgenerators.FailCommandUrlGenerator;
import ca.sm360.cronitor.client.urlgenerators.PauseCommandUrlGenerator;
import ca.sm360.cronitor.client.urlgenerators.RunCommandUrlGenerator;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

public class CronitorClient {

    private CronitorPinger cronitorPinger = new CronitorPinger();

    private String apiKey;

    public CronitorClient() {

        this(null);
    }

    public CronitorClient(String apiKey) {

        this.apiKey = apiKey;
    }

    public void run(String monitorCode) throws IOException, URISyntaxException {

        URL commandUrl = new RunCommandUrlGenerator().buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void run(String monitorCode, String message) throws IOException, URISyntaxException {

        URL commandUrl = new RunCommandUrlGenerator().withMessage(message).buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void complete(String monitorCode) throws URISyntaxException, IOException {
        URL commandUrl = new CompleteCommandUrlGenerator().buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void complete(String monitorCode, String message) throws URISyntaxException, IOException {
        URL commandUrl = new CompleteCommandUrlGenerator().withMessage(message).buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void fail(String monitorCode) throws URISyntaxException, IOException {
        URL commandUrl = new FailCommandUrlGenerator().buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void fail(String monitorCode, String message) throws URISyntaxException, IOException {
        URL commandUrl = new FailCommandUrlGenerator().withMessage(message).buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void pause(String monitorCode, int timeoutInHouirs) throws URISyntaxException, IOException {
        URL commandUrl = new PauseCommandUrlGenerator(timeoutInHouirs).buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }

    public void unpause(String monitorCode) throws URISyntaxException, IOException {
        URL commandUrl = new PauseCommandUrlGenerator(0).buildURI(monitorCode, apiKey);
        cronitorPinger.ping(commandUrl);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy