/** * Offer an element to the container. * @return true if the element was added, false if there was no space and we could not evict any elements to make it fit. * Note that the element may get evicted by future offers, so a return of true is not a guarantee that the * element will be present at any time in the future. */ public boolean add(T t) { if (this.closed) { throw new RuntimeException( ConcurrentBoundedPriorityIterable.class.getSimpleName() + " is no longer accepting requests!"); } AllocatedRequestsIteratorBase.RequestWithResourceRequirement<T> newElement = new AllocatedRequestsIteratorBase.RequestWithResourceRequirement<>(t, this.estimator.estimateRequirement(t, this.resourcePool)); boolean addedWorkunits = addImpl(newElement); if (!addedWorkunits) { this.rejectedElement = true; } return addedWorkunits; }
this.maxResourceRequirement.entryWiseMax(newElement.getResourceRequirement()); this.requestsOffered++; if (this.resourcePool.exceedsHardBound(newElement.getResourceRequirement(), false)) { + "it will never be selected. Request: %s.", newElement.getT(), this.resourcePool.stringifyRequirement(newElement.getResourceRequirement()))); if (!this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.NONE.name())) { this.requestsExceedingAvailableResourcePool.add(newElement.getT()); .add(this.currentRequirement, newElement.getResourceRequirement(), this.candidateRequirement); if (this.comparator.compare(this.elements.last().getT(), newElement.getT()) <= 0) { log.debug( "Request {} does not fit in resource pool and is lower priority than current lowest priority request. " + "Rejecting", newElement.getT()); this.requestsRefused++; if (this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.ALL.name())) { this.requestsRejectedWithLowPriority.add(newElement.getT()); if (this.comparator.compare(dropCandidate.getT(), newElement.getT()) <= 0) { log.debug("Cannot evict enough requests to fit request {}. " + "Rejecting", newElement.getT()); this.requestsRefused++; if (this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.ALL.name())) { this.requestsRejectedDueToInsufficientEviction.add(newElement.getT());
this.maxResourceRequirement.entryWiseMax(newElement.getResourceRequirement()); this.requestsOffered++; if (this.resourcePool.exceedsHardBound(newElement.getResourceRequirement(), false)) { + "it will never be selected. Request: %s.", newElement.getT(), this.resourcePool.stringifyRequirement(newElement.getResourceRequirement()))); if (!this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.NONE.name())) { this.requestsExceedingAvailableResourcePool.add(newElement.getT()); .add(this.currentRequirement, newElement.getResourceRequirement(), this.candidateRequirement); if (this.comparator.compare(this.elements.last().getT(), newElement.getT()) <= 0) { log.debug( "Request {} does not fit in resource pool and is lower priority than current lowest priority request. " + "Rejecting", newElement.getT()); this.requestsRefused++; if (this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.ALL.name())) { this.requestsRejectedWithLowPriority.add(newElement.getT()); if (this.comparator.compare(dropCandidate.getT(), newElement.getT()) <= 0) { log.debug("Cannot evict enough requests to fit request {}. " + "Rejecting", newElement.getT()); this.requestsRefused++; if (this.storeRejectedRequestsSetting .equalsIgnoreCase(RequestAllocatorConfig.StoreRejectedRequestsConfig.ALL.name())) { this.requestsRejectedDueToInsufficientEviction.add(newElement.getT());
/** * Offer an element to the container. * @return true if the element was added, false if there was no space and we could not evict any elements to make it fit. * Note that the element may get evicted by future offers, so a return of true is not a guarantee that the * element will be present at any time in the future. */ public boolean add(T t) { if (this.closed) { throw new RuntimeException( ConcurrentBoundedPriorityIterable.class.getSimpleName() + " is no longer accepting requests!"); } AllocatedRequestsIteratorBase.RequestWithResourceRequirement<T> newElement = new AllocatedRequestsIteratorBase.RequestWithResourceRequirement<>(t, this.estimator.estimateRequirement(t, this.resourcePool)); boolean addedWorkunits = addImpl(newElement); if (!addedWorkunits) { this.rejectedElement = true; } return addedWorkunits; }
@Override public T apply(RequestWithResourceRequirement<T> ttAndRequirement) { return ttAndRequirement.getT(); } }
@Override public T next() { RequestWithResourceRequirement<T> nextElement = this.underlying.next(); VectorAlgebra.addVector(this.currentRequirement, nextElement.getResourceRequirement().getResourceVector(), 1.0, this.currentRequirement); return nextElement.getT(); }
@Override public T apply(RequestWithResourceRequirement<T> ttAndRequirement) { return ttAndRequirement.getT(); } }
@Override public T next() { RequestWithResourceRequirement<T> nextElement = this.underlying.next(); VectorAlgebra.addVector(this.currentRequirement, nextElement.getResourceRequirement().getResourceVector(), 1.0, this.currentRequirement); return nextElement.getT(); }