// Consumer methods
// job-related
// ****************************************************************
@Override
public Job reserve(Integer timeoutSeconds) {
Job job = null;
String command = (timeoutSeconds == null) ? "reserve" : "reserve-with-timeout " + timeoutSeconds.toString();
Request request = new Request(command, new String[] { "RESERVED" }, new String[] { "DEADLINE_SOON",
"TIMED_OUT", }, null, ExpectedResponse.ByteArray, 2);
Response response = getProtocolHandler().processRequest(request);
if (response != null && response.getStatus().equals("DEADLINE_SOON")) {
BeanstalkException be = new BeanstalkException(response.getStatus());
throw be;
}
if (response != null && response.isMatchOk()) {
long jobId = Long.parseLong(response.getReponse());
job = new JobImpl(jobId);
job.setData((byte[]) response.getData());
}
return job;
}