/** * Removes requests as long as they match - breaks at the first non-matching request or when requests is empty * This method must catch all exceptions; or else process() might return without setting processing to true again! */ protected void removeAndProcess(Collection<R> requests) { try { Collection<R> removed=new ArrayList<>(); Iterator<R> it=requests.iterator(); R first_req=it.next(); removed.add(first_req); it.remove(); while(it.hasNext()) { R next=it.next(); if(req_matcher.test(first_req, next)) { removed.add(next); it.remove(); } else break; } req_processor.accept(removed); } catch(Throwable t) { log().error("failed processing requests", t); } }
protected boolean _add(Collection<R> reqs) { if(reqs == null || reqs.isEmpty() || suspended.get()) { log().trace("%s: queue is suspended; requests are discarded", gms.getLocalAddress()); return false; } count.incrementAndGet(); lock.lock(); try { for(R req: reqs) { if(!requests.contains(req)) { requests.add(req); history.add(new Date() + ": " + req.toString()); } } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }
protected boolean _add(R req) { if(req == null || suspended.get()) { log().trace("%s: queue is suspended; request %s is discarded", gms.getLocalAddress(), req); return false; } String log=new Date() + ": " + req.toString(); count.incrementAndGet(); lock.lock(); try { if(!requests.contains(req)) { requests.add(req); history.add(log); } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }
@SuppressWarnings("unchecked") protected boolean _add(R ... reqs) { if(reqs == null || reqs.length == 0 || suspended.get()) { log().trace("%s: queue is suspended; requests are discarded", gms.getLocalAddress()); return false; } count.incrementAndGet(); lock.lock(); try { for(R req: reqs) { if(!requests.contains(req)) { requests.add(req); history.add(new Date() + ": " + req.toString()); } } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }
/** * Removes requests as long as they match - breaks at the first non-matching request or when requests is empty * This method must catch all exceptions; or else process() might return without setting processing to true again! */ protected void removeAndProcess(Collection<R> requests) { try { Collection<R> removed=new ArrayList<>(); Iterator<R> it=requests.iterator(); R first_req=it.next(); removed.add(first_req); it.remove(); while(it.hasNext()) { R next=it.next(); if(req_matcher.test(first_req, next)) { removed.add(next); it.remove(); } else break; } req_processor.accept(removed); } catch(Throwable t) { log().error("failed processing requests", t); } }
protected boolean _add(R req) { if(req == null || suspended.get()) { log().trace("%s: queue is suspended; request %s is discarded", gms.getLocalAddress(), req); return false; } String log=new Date() + ": " + req.toString(); count.incrementAndGet(); lock.lock(); try { if(!requests.contains(req)) { requests.add(req); history.add(log); } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }
protected boolean _add(Collection<R> reqs) { if(reqs == null || reqs.isEmpty() || suspended.get()) { log().trace("%s: queue is suspended; requests are discarded", gms.getLocalAddress()); return false; } count.incrementAndGet(); lock.lock(); try { for(R req: reqs) { if(!requests.contains(req)) { requests.add(req); history.add(new Date() + ": " + req.toString()); } } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }
@SuppressWarnings("unchecked") protected boolean _add(R ... reqs) { if(reqs == null || reqs.length == 0 || suspended.get()) { log().trace("%s: queue is suspended; requests are discarded", gms.getLocalAddress()); return false; } count.incrementAndGet(); lock.lock(); try { for(R req: reqs) { if(!requests.contains(req)) { requests.add(req); history.add(new Date() + ": " + req.toString()); } } return count.decrementAndGet() == 0 && !processing && setProcessing(true); } finally { lock.unlock(); } }