ca.sm360.cronitor.client.CronitorClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cronitor-client Show documentation
Show all versions of cronitor-client Show documentation
cronitor-client is a simple Java library designed to help you monitoring, with www.cronitor.io, the routines of your Java projects
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);
}
}