public void addHostToList(String host) throws IOException { this.addHostToList(host, 4730); }
@Override public byte[] submitJob(String callback, byte[] data) throws JobSubmissionException, WorkException { return submitJob(callback, data, JobPriority.NORMAL); }
@Override public String submitJobInBackground(String callback, byte[] data) throws JobSubmissionException { return submitJobInBackground(callback, data, JobPriority.NORMAL); }
NetworkGearmanClient client = new NetworkGearmanClient("localhost", 4730); client.addHostToList("localhost", 4731); client.registerEventListener(eventListener); byte[] result = client.submitJob("reverse", data, JobPriority.NORMAL); System.err.println("Result: " + new String(result)); } catch (WorkException e) {
ServerResponse response = sendJobPacket(new SubmitJob(callback, jobid, data, false, priority)); if(response != null) WorkStatus ws = (WorkStatus) result; LOG.debug("Status data for job " + ws.getJobHandle()); handleWorkStatus(ws.getJobHandle(), ws.toJobStatus()); break; case WORK_DATA: WorkDataResponse wd = (WorkDataResponse) result; LOG.debug("Received data update for job " + wd.getJobHandle()); handleWorkData(wd.getJobHandle(), wd.getData()); break; case WORK_WARNING: WorkWarningResponse ww = (WorkWarningResponse) result; LOG.debug("Received warning for job " + ww.getJobHandle()); handleWorkWarning(ww.getJobHandle(), ww.getData()); break; default:
public void testTwoNodeHazelcastCluster() throws InterruptedException, IOException, JobSubmissionException, WorkException { WorkerRunner workerRunner = new WorkerRunner(); Thread t3 = new Thread(workerRunner); t3.start(); byte[] jobData = {'H','E','L','L','O'}; byte[] reversedData = jobData.clone(); ArrayUtils.reverse(reversedData); GearmanClient client = new NetworkGearmanClient("localhost", SERVER_TWO_PORT); byte[] result = client.submitJob("reverse", jobData); Assert.assertArrayEquals(result, reversedData); LOG.debug(String.format("Result: %s", new String(result))); workerRunner.stop(); t3.join(); }
@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; }
GearmanClient client = new NetworkGearmanClient("localhost", port); GearmanClientEventListener listener = new GearmanClientEventListener() { @Override
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; }