Skip to content

Commit a8b8826

Browse files
author
Shakeel Mohamed
committed
Make Job constructor public, add example for getting a single job
1 parent 8a032b8 commit a8b8826

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2015 Splunk, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"): you may
5+
* not use this file except in compliance with the License. You may obtain
6+
* a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package com.splunk.examples.get_job;
17+
18+
import com.splunk.*;
19+
20+
public class Program {
21+
public static void main(String[] args) {
22+
Command command = Command.splunk("info").parse(args);
23+
Service service = Service.connect(command.opts);
24+
25+
String sid = service.search("search index=_internal | head 5").getSid();
26+
Job job = new Job(service, "search/jobs/" + sid);
27+
28+
while (!job.isDone()) {
29+
job.refresh();
30+
try {
31+
Thread.sleep(1000);
32+
} catch (Exception e) {
33+
System.out.println(e.getMessage());
34+
}
35+
}
36+
37+
// Now job is done
38+
System.out.println(job.getEventCount());
39+
}
40+
}

splunk/com/splunk/Job.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Job extends Entity {
3636
* @param service The connected {@code Service} instance.
3737
* @param path The search jobs endpoint.
3838
*/
39-
Job(Service service, String path) {
39+
public Job(Service service, String path) {
4040
super(service, path);
4141
}
4242

0 commit comments

Comments
 (0)