diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-11-17 23:51:24 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-11-17 23:51:24 +0100 |
commit | c266c3e36007d968d3126b4f8475d3e29e219a19 (patch) | |
tree | ffa93f9a2c97dc23d47fb981cc97e4446dbdb106 /src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java | |
parent | 751e580672cc384e20f62e9440d44bdcb04f1ef0 (diff) | |
download | esper-testing-c266c3e36007d968d3126b4f8475d3e29e219a19.tar.gz esper-testing-c266c3e36007d968d3126b4f8475d3e29e219a19.tar.bz2 esper-testing-c266c3e36007d968d3126b4f8475d3e29e219a19.tar.xz esper-testing-c266c3e36007d968d3126b4f8475d3e29e219a19.zip |
o Creating jobs for polling a jenkins servers and jobs.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java')
-rw-r--r-- | src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java new file mode 100644 index 0000000..6596dfa --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJob.java @@ -0,0 +1,83 @@ +package io.trygvis.esper.testing.jenkins; + +import org.codehaus.httpcache4j.util.*; + +import java.io.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.*; + +public class JenkinsJob implements Closeable { + + private final JenkinsClient client; + private final URI uri; + + private JenkinsJobXml latestStatus; + // private boolean shouldRun = true; + // private final Thread thread; + private final ScheduledFuture<?> future; + + public JenkinsJob(ScheduledExecutorService executorService, JenkinsClient client, URI uri) { + this.client = client; + this.uri = URIBuilder.fromURI(uri).addRawPath("api/xml").toURI(); + + long initialDelay = (long) Math.random() + 1; + long period = (long) (Math.random() * 10d) + 1; + future = executorService.scheduleAtFixedRate(new Runnable() { + public void run() { + JenkinsJob.this.doWork(); + } + }, initialDelay, period, TimeUnit.SECONDS); + +// thread = new Thread(new Runnable() { +// public void run() { +// JenkinsJob.this.run(); +// } +// }); +// thread.setDaemon(true); +// thread.start(); + } + + public JenkinsJobXml getLatestStatus() { + return latestStatus; + } + + /* + public void close() throws IOException { + shouldRun = false; + thread.interrupt(); + while (thread.isAlive()) { + try { + thread.join(); + } catch (InterruptedException e) { + continue; + } + } + } + + private void run() { + Random r = new Random(); + while (shouldRun) { + doWork(); + + try { + Thread.sleep(1000 + r.nextInt(10) * 1000); + } catch (InterruptedException e) { + // ignore + } + } + } + */ + + public void close() throws IOException { + future.cancel(true); + } + + private void doWork() { + try { + latestStatus = client.fetchJob(uri); + } catch (Exception e) { + e.printStackTrace(System.out); + } + } +} |