/** * Add the given operation to the tail of this queue. * * @param operation the operation to be added to the queue */ public void enqueue(IndexOperation operation) { synchronized (nonQueryOperations) { if (operation instanceof RemoveResourceOperation) { Resource resource = ((RemoveResourceOperation) operation).getResource(); for (int i = nonQueryOperations.size() - 1; i >= 0; i--) { if (nonQueryOperations.get(i).removeWhenResourceRemoved(resource)) { nonQueryOperations.remove(i); } } for (int i = queryOperations.size() - 1; i >= 0; i--) { if (queryOperations.get(i).removeWhenResourceRemoved(resource)) { queryOperations.remove(i); } } } if (operation.isQuery()) { queryOperations.add(operation); } else { nonQueryOperations.add(operation); } nonQueryOperations.notifyAll(); } }