/** * Get the executor * @param work The work instance * @return The executor */ private BlockingExecutor getExecutor(Work work) { BlockingExecutor executor = shortRunningExecutor; if (longRunningExecutor != null && WorkManagerUtil.isLongRunning(work)) { executor = longRunningExecutor; } fireHintsComplete(work); return executor; }
/** * Get explicit work manager override * @param wmId The work manager identifier * @param work The work instance * @return The selection map */ protected Map<Address, Long> getSelectionMap(String wmId, DistributableWork work) { log.tracef("getSelectionMap(%s, %s)", wmId, work); log.tracef("ShortRunning: %s", shortRunning); log.tracef("LongRunning: %s", longRunning); Map<Address, Long> sorted = null; if (WorkManagerUtil.isLongRunning(work)) { if (longRunning.get(wmId) != null) sorted = new HashMap<Address, Long>(longRunning.get(wmId)); } if (sorted == null && shortRunning.get(wmId) != null) sorted = new HashMap<Address, Long>(shortRunning.get(wmId)); return sorted; }
/** * {@inheritDoc} */ @Override public synchronized boolean shouldDistribute(DistributedWorkManager dwm, DistributableWork work) { log.tracef("Work=%s", work); Boolean override = WorkManagerUtil.getShouldDistribute(work); if (override != null) return override.booleanValue(); if (WorkManagerUtil.isLongRunning(work) && dwm.getLongRunningThreadPool() != null) { return !(dwm.getLongRunningThreadPool().getNumberOfFreeThreads() > watermark); } else { return !(dwm.getShortRunningThreadPool().getNumberOfFreeThreads() > watermark); } }
/** * {@inheritDoc} */ public void localScheduleWork(Work work) throws WorkException { if (transport != null) { checkTransport(); if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work)) { transport.updateLongRunningFree(getLocalAddress(), getLongRunningThreadPool().getNumberOfFreeThreads() - 1); } else { transport.updateShortRunningFree(getLocalAddress(), getShortRunningThreadPool().getNumberOfFreeThreads() - 1); } WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work), getShortRunningThreadPool(), getLongRunningThreadPool(), getLocalAddress(), transport); super.scheduleWork(work, WorkManager.INDEFINITE, null, wel); } else { super.scheduleWork(work); } }
/** * {@inheritDoc} */ public void localDoWork(Work work) throws WorkException { if (transport != null) { checkTransport(); if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work)) { transport.updateLongRunningFree(getLocalAddress(), getLongRunningThreadPool().getNumberOfFreeThreads() - 1); } else { transport.updateShortRunningFree(getLocalAddress(), getShortRunningThreadPool().getNumberOfFreeThreads() - 1); } WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work), getShortRunningThreadPool(), getLongRunningThreadPool(), getLocalAddress(), transport); super.doWork(work, WorkManager.INDEFINITE, null, wel); } else { super.doWork(work); } }
/** * {@inheritDoc} */ public long localStartWork(Work work) throws WorkException { if (transport != null) { checkTransport(); if (getLongRunningThreadPool() != null && WorkManagerUtil.isLongRunning(work)) { transport.updateLongRunningFree(getLocalAddress(), getLongRunningThreadPool().getNumberOfFreeThreads() - 1); } else { transport.updateShortRunningFree(getLocalAddress(), getShortRunningThreadPool().getNumberOfFreeThreads() - 1); } WorkEventListener wel = new WorkEventListener(WorkManagerUtil.isLongRunning(work), getShortRunningThreadPool(), getLongRunningThreadPool(), getLocalAddress(), transport); return super.startWork(work, WorkManager.INDEFINITE, null, wel); } else { return super.startWork(work); } }