void removeFromStarterQueue( SendableRequest req, ObjectContainer container, boolean reqAlreadyActive) { PersistentChosenRequest dumped = null; synchronized (starterQueue) { for (int i = 0; i < starterQueue.size(); i++) { PersistentChosenRequest pcr = starterQueue.get(i); if (pcr.request == req) { starterQueue.remove(i); dumped = pcr; break; } } } if (dumped != null) dumped.onDumped(schedCore, container, reqAlreadyActive); }
private void trimStarterQueue(ObjectContainer container) { ArrayList<PersistentChosenRequest> dumped = null; synchronized (starterQueue) { int length = starterQueueLength(); while (length > MAX_STARTER_QUEUE_SIZE) { // Find the lowest priority/retry count request. // If we can dump it without going below the limit, then do so. // If we can't, return. PersistentChosenRequest worst = null; short worstPrio = -1; int worstIndex = -1; int worstLength = -1; if (starterQueue.isEmpty()) { break; } length = 0; for (int i = 0; i < starterQueue.size(); i++) { PersistentChosenRequest req = starterQueue.get(i); short prio = req.prio; int size = req.sizeNotStarted(); length += size; if (prio > worstPrio) { worstPrio = prio; worst = req; worstIndex = i; worstLength = size; continue; } } int lengthAfter = length - worstLength; if (lengthAfter >= MAX_STARTER_QUEUE_SIZE) { if (dumped == null) dumped = new ArrayList<PersistentChosenRequest>(2); dumped.add(worst); starterQueue.remove(worstIndex); if (lengthAfter == MAX_STARTER_QUEUE_SIZE) break; } else { // Can't remove any more. break; } } } if (dumped == null) return; for (PersistentChosenRequest req : dumped) { req.onDumped(schedCore, container, false); } }
/** * @param request * @param container * @return True if the queue is now full/over-full. */ boolean addToStarterQueue(SendableRequest request, ObjectContainer container) { if (logMINOR) Logger.minor(this, "Adding to starter queue: " + request); container.activate(request, 1); PersistentChosenRequest chosen; try { chosen = new PersistentChosenRequest( request, request.getPriorityClass(container), container, ClientRequestScheduler.this, clientContext); } catch (NoValidBlocksException e) { return false; } if (logMINOR) Logger.minor(this, "Created PCR: " + chosen); container.deactivate(request, 1); boolean dumpNew = false; synchronized (starterQueue) { for (PersistentChosenRequest req : starterQueue) { if (req.request == request) { Logger.error( this, "Already on starter queue: " + req + " for " + request, new Exception("debug")); dumpNew = true; break; } } if (!dumpNew) { starterQueue.add(chosen); int length = starterQueueLength(); length += chosen.sizeNotStarted(); runningPersistentRequests.add(request); if (logMINOR) Logger.minor( this, "Added to running persistent requests, size now " + runningPersistentRequests.size() + " : " + request); return length > MAX_STARTER_QUEUE_SIZE; } } if (dumpNew) chosen.onDumped(schedCore, container, false); return false; }