/** Returns the number of messages that can be delivered */ public int getNumDeliverable() { NumDeliverable visitor=new NumDeliverable(); lock.lock(); try { forEach(hd+1, hr, visitor); return visitor.getResult(); } finally { lock.unlock(); } }
/** Returns the highest deliverable (= removable) seqno. This may be higher than {@link #getHighestDelivered()}, * e.g. if elements have been added but not yet removed */ public long getHighestDeliverable() { HighestDeliverable visitor=new HighestDeliverable(); lock.lock(); try { forEach(hd+1, hr, visitor); long retval=visitor.getResult(); return retval == -1? hd : retval; } finally { lock.unlock(); } }
/** * Removes elements from the table and adds them to the result created by result_creator. Between 0 and max_results * elements are removed. If no elements were removed, processing will be set to true while the table lock is held. * @param nullify if true, the x,y location of the removed element in the matrix will be nulled * @param max_results the max number of results to be returned, even if more elements would be removable * @param filter a filter which accepts (or rejects) elements into the result. If null, all elements will be accepted * @param result_creator a supplier required to create the result, e.g. ArrayList::new * @param accumulator an accumulator accepting the result and an element, e.g. ArrayList::add * @param <R> the type of the result * @return the result */ public <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R,T> accumulator) { lock.lock(); try { Remover<R> remover=new Remover<>(nullify, max_results, filter, result_creator, accumulator); forEach(hd+1, hr, remover); return remover.getResult(); } finally { lock.unlock(); } }
/** * Returns a list of missing messages * @param max_msgs If > 0, the max number of missing messages to be returned (oldest first), else no limit * @return A SeqnoList of missing messages, or null if no messages are missing */ public SeqnoList getMissing(int max_msgs) { lock.lock(); try { if(size == 0) return null; long start_seqno=getHighestDeliverable() +1; int capacity=(int)(hr - start_seqno); int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity; if(max_size <= 0) return null; Missing missing=new Missing(start_seqno, max_size); long to=max_size > 0? Math.min(start_seqno + max_size-1, hr-1) : hr-1; forEach(start_seqno, to, missing); return missing.getMissingElements(); } finally { lock.unlock(); } }
hr=seqno; if(remove_filter != null && hd +1 == seqno) { forEach(hd + 1, hr, (seq, msg, r, c) -> { if(msg == null || !remove_filter.test(msg))
/** Returns the number of messages that can be delivered */ public int getNumDeliverable() { NumDeliverable visitor=new NumDeliverable(); lock.lock(); try { forEach(hd+1, hr, visitor); return visitor.getResult(); } finally { lock.unlock(); } }
/** Returns the highest deliverable (= removable) seqno. This may be higher than {@link #getHighestDelivered()}, * e.g. if elements have been added but not yet removed */ public long getHighestDeliverable() { HighestDeliverable visitor=new HighestDeliverable(); lock.lock(); try { forEach(hd+1, hr, visitor); long retval=visitor.getResult(); return retval == -1? hd : retval; } finally { lock.unlock(); } }
/** * Removes elements from the table and adds them to the result created by result_creator. Between 0 and max_results * elements are removed. If no elements were removed, processing will be set to true while the table lock is held. * @param nullify if true, the x,y location of the removed element in the matrix will be nulled * @param max_results the max number of results to be returned, even if more elements would be removable * @param filter a filter which accepts (or rejects) elements into the result. If null, all elements will be accepted * @param result_creator a supplier required to create the result, e.g. ArrayList::new * @param accumulator an accumulator accepting the result and an element, e.g. ArrayList::add * @param <R> the type of the result * @return the result */ public <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R,T> accumulator) { lock.lock(); try { Remover<R> remover=new Remover<>(nullify, max_results, filter, result_creator, accumulator); forEach(hd+1, hr, remover); return remover.getResult(); } finally { lock.unlock(); } }
/** * Returns a list of missing messages * @param max_msgs If > 0, the max number of missing messages to be returned (oldest first), else no limit * @return A SeqnoList of missing messages, or null if no messages are missing */ public SeqnoList getMissing(int max_msgs) { lock.lock(); try { if(size == 0) return null; long start_seqno=getHighestDeliverable() +1; int capacity=(int)(hr - start_seqno); int max_size=max_msgs > 0? Math.min(max_msgs, capacity) : capacity; if(max_size <= 0) return null; Missing missing=new Missing(start_seqno, max_size); long to=max_size > 0? Math.min(start_seqno + max_size-1, hr-1) : hr-1; forEach(start_seqno, to, missing); return missing.getMissingElements(); } finally { lock.unlock(); } }
hr=seqno; if(remove_filter != null && hd +1 == seqno) { forEach(hd + 1, hr, (seq, msg, r, c) -> { if(msg == null || !remove_filter.test(msg))