Source:
public void run() { while (true) { Pair<Event, FutureTask<EventResult>> pair; lock.lock(); try { pair = poolsEventsMap.get(storagePoolId).poll(); if (pair != null) { poolCurrentEventMap.put(storagePoolId, pair.getFirst()); } else { poolCurrentEventMap.remove(storagePoolId); poolsEventsMap.remove(storagePoolId); log.debug("All task for event query were executed pool '{}'", storagePoolId); break; } } finally { lock.unlock(); } Future<EventResult> futureResult = ThreadPoolUtil.execute(pair.getSecond()); try { if (futureResult.get() == null) { EventResult result = pair.getSecond().get(); if (result != null && result.getEventType() == EventType.RECONSTRUCT) { log.info("Finished reconstruct for pool '{}'. Clearing event queue", storagePoolId); lock.lock(); try { LinkedList<Pair<Event, FutureTask<EventResult>>> queue = new LinkedList<Pair<Event, FutureTask<EventResult>>>(); for (Pair<Event, FutureTask<EventResult>> task : poolsEventsMap.get(storagePoolId)) { EventType eventType = task.getFirst().getEventType(); if (eventType == EventType.VDSCONNECTTOPOOL || ((eventType == EventType.RECOVERY || eventType == EventType.DOMAINFAILOVER || eventType == EventType.VDSCLEARCACHE) && !result.isSuccess())) { queue.add(task); } else { log.info("The following operation '{}' was cancelled, because of reconstruct was run before", task.getFirst()); task.getSecond().cancel(true); } } if (queue.isEmpty()) { poolCurrentEventMap.remove(storagePoolId); poolsEventsMap.remove(storagePoolId); break; } else { poolsEventsMap.put(storagePoolId, queue); } } finally { lock.unlock(); } } } } catch (Exception e) { log.error("Exception during process of events for pool '{}'", storagePoolId); log.error("Exception", e); } } }

Target:
public void run() { while (true) { Pair<Event, FutureTask<EventResult>> pair; lock.lock(); try { pair = poolsEventsMap.get(storagePoolId).poll(); if (pair != null) { poolCurrentEventMap.put(storagePoolId, pair.getFirst()); } else { poolCurrentEventMap.remove(storagePoolId); poolsEventsMap.remove(storagePoolId); log.debug("All task for event query were executed pool '{}'", storagePoolId); break; } } finally { lock.unlock(); } Future<EventResult> futureResult = ThreadPoolUtil.execute(pair.getSecond()); try { if (futureResult.get() == null) { EventResult result = pair.getSecond().get(); if (result != null && result.getEventType() == EventType.RECONSTRUCT) { log.info("Finished reconstruct for pool '{}'. Clearing event queue", storagePoolId); lock.lock(); try { LinkedList<Pair<Event, FutureTask<EventResult>>> queue = new LinkedList<Pair<Event, FutureTask<EventResult>>>(); for (Pair<Event, FutureTask<EventResult>> task : poolsEventsMap.get(storagePoolId)) { EventType eventType = task.getFirst().getEventType(); if (eventType == EventType.VDSCONNECTTOPOOL || ((eventType == EventType.RECOVERY || eventType == EventType.DOMAINFAILOVER || eventType == EventType.VDSCLEARCACHE) && !result.isSuccess())) { queue.add(task); } else { log.info("The following operation '{}' was cancelled, because of reconstruct was run before", task.getFirst()); task.getSecond().cancel(true); } } if (queue.isEmpty()) { poolCurrentEventMap.remove(storagePoolId); poolsEventsMap.remove(storagePoolId); break; } else { poolsEventsMap.put(storagePoolId, queue); } } finally { lock.unlock(); } } } } catch (Exception e) { log.error("Exception during process of events for pool '{}': {}", storagePoolId, e.getMessage()); log.debug("Exception", e); } } }