@Override public boolean addJobToCurrent(Job j) throws Exception { IAtomicReference<Job> r = h.getAtomicReference("job-" + j.getWorkerId()); if (r.get() != null || !r.isNull()) { boolean sent = false; while (!sent) { // always update for (String s : workers()) { if (jobFor(s) == null) { log.info( "Redirecting worker " + j.getWorkerId() + " to " + s + " due to work already being allocated"); r = h.getAtomicReference("job-" + s); j.setWorkerId(s); sent = true; } } } } r.set(j); // iterate over jobs without the work/data j.setWork(null); jobs.add(j); return true; }
@Override public void addWorker(String worker) { heartbeat.put(worker, System.currentTimeMillis()); if (!workers.contains(worker)) { log.info("Adding worker " + worker); workers.add(worker); log.info("Number of workers is now " + workers.size()); } }
/** * Adds an update to the current mini batch * * @param id the id of the worker who did the update * @param update the update to add */ @Override public void addUpdate(String id, E update) { try { updateSaver().save(id, update); } catch (Exception e) { throw new RuntimeException(e); } updates.add(id); }
@Override public void availableForWork(String id) { if (!workers.contains(id)) workers.add(id); }
@Override public void addTopic(String topic) throws Exception { topics.add(topic); }
/** * Adds a worker to the list to be replicate d * * @param workerId the worker id to add */ @Override public void addReplicate(String workerId) { if (!replicate.contains(workerId)) replicate.add(workerId); }