public String submitJobInBackground(String callback, byte[] data, JobPriority priority) throws NoServersAvailableException { String jobid = UUID.randomUUID().toString(); try { ServerResponse response = sendJobPacket(new SubmitJob(callback, jobid, data, true, priority)); if(response != null) { LOG.debug("Sent background job request to " + response.getConnection()); // If we get back a JOB_CREATED packet, we can continue, // otherwise try the next job manager if (response.getPacket().getType() == PacketType.JOB_CREATED) { String jobHandle = ((JobCreated)response.getPacket()).getJobHandle(); LOG.debug(format("Created background job %s, with priority %s\n", jobHandle, priority.toString())); return jobHandle; } } } catch (NoServersAvailableException nsae) { LOG.warn("No servers available to submit the job."); throw nsae; } return null; }
result = response.getConnection().getNextPacket();
private ServerResponse sendJobPacket(SubmitJob jobPacket) throws NoServersAvailableException { Packet result; Connection connection; while ( (connection = connectionPool.getConnection()) != null) { try { connection.sendPacket(jobPacket); LOG.debug("Sent job request to " + connection.toString()); // We need to get back a JOB_CREATED packet result = connection.getNextPacket(); // If we get back a JOB_CREATED packet, we can continue // otherwise try the next job manager if (result != null && result.getType() == PacketType.JOB_CREATED) { LOG.debug("Created job " + ((JobCreated) result).getJobHandle()); return new ServerResponse(connection, result); } } catch (IOException ioe) { LOG.error("Connection to " + connection.toString() + " flaky, marking as bad."); } } // The only way we get here is if connection == null, by which point we would have been // thrown a NoServersAvailableException() throw new NoServersAvailableException(); }
@Override public String submitFutureJob(String callback, byte[] data, Date whenToRun) throws NoServersAvailableException { String uniqueID = UUID.randomUUID().toString(); try { ServerResponse response = sendJobPacket(new SubmitJob(callback, uniqueID, data, whenToRun)); if(response != null) { LOG.debug("Sent future job request to " + response.getConnection()); // If we get back a JOB_CREATED packet, we can continue, // otherwise try the next job manager if (response.getPacket().getType() == PacketType.JOB_CREATED) { String jobHandle = ((JobCreated)response.getPacket()).getJobHandle(); LOG.debug("Created future job %s\n", jobHandle); return jobHandle; } } } catch (NoServersAvailableException nsae) { LOG.warn("No servers available to submit the job."); throw nsae; } return null; }