I am trying to do a Splunk Seach from Splunk java SDK. Here is the working code. My question is do I need to close service after each search. If yes, how to close it? Else is there a maximum number of jobs that I can create in each service?
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setUsername(splunkUserName);
serviceArgs.setHost(splunkHostname);
serviceArgs.setPort(Integer.parseInt(splunkPort));
serviceArgs.setPassword(splunkPassword));
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
Service service = Service.connect(serviceArgs);
JobArgs jobArgs = new JobArgs();
jobArgs.setExecutionMode(JobArgs.ExecutionMode.NORMAL);
jobArgs.setEarliestTime(startDate);
jobArgs.setLatestTime(endData);
jobArgs.setMaximumCount(maxResultCount);
Job job = service.getJobs().create(query,jobArgs);
My question is do I need to close service after each search
I would say it depends on your needs, I don't know well enough your application.
If yes, how to close it?
Anyway, you can : the com.splunk.Service
have a logout
method for this :
/**
* Forgets the current session token.
*
* @return The current {@code Service} instance.
*/
public Service logout() {
this.token = null;
this.removeAllCookies();
return this;
}
Else is there a maximum number of jobs that I can create in each service?
I would say yes, it should be the same limitation that the user have by making search through th UI.