public synchronized void setAllTimeoutsToZero() { flushPending(); for(ReaperElement reaperElement : elementsOrderedByTimeout) { reaperElement.setAbsoluteTimeout(0); } }
/** * @param reaperElement the reaper element to reorder in the sorted set. * @param delayMillis the amount of time to increment the element's timeout by. * @return the new soonest timeout in the set (not necessarily that of the reordered element) */ public synchronized long reorder(ReaperElement reaperElement, long delayMillis) { // assume it must be in the sorted list, as it was likely obtained via getFirst... removeSorted(reaperElement); // we could add delay to the original timeout, but using current time is probably safer. reaperElement.setAbsoluteTimeout((System.currentTimeMillis() + delayMillis)); // reinsert into its new position. insertSorted(reaperElement); // getFirst takes care of flushing the pending set for us. return getFirst().getAbsoluteTimeout(); }
private final void removeElementClient(ReaperElement reaperElement) { _reaperElements.remove(reaperElement); _timeouts.remove(reaperElement._control); // don't recalc time, just wake up as planned if(_inShutdown) { synchronized (this) { this.notifyAll(); // TODO: use different lock for shutdown? } } }
return; ReaperElement reaperElement = new ReaperElement(control, timeout); _lifetime.addAndGet(timeout); if ((_timeouts.putIfAbsent(reaperElement._control, reaperElement) == null)) { _reaperElements.add(reaperElement); } else { throw new IllegalStateException(tsLogger.i18NLogger.get_coordinator_TransactionReaper_1()); if (_dynamic && reaperElement.getAbsoluteTimeout() < nextDynamicCheckTime.get()) { updateCheckTimeForEarlierInsert(reaperElement.getAbsoluteTimeout());
private final void removeElementReaper(ReaperElement reaperElement) { _reaperElements.remove(reaperElement); _timeouts.remove(reaperElement._control); synchronized (this) { // TODO set needs tobe atomic to getFirst? ReaperElement first = _reaperElements.getFirst(); if(first != null) { nextDynamicCheckTime.set(first.getAbsoluteTimeout()); } else { nextDynamicCheckTime.set(Long.MAX_VALUE); if(_inShutdown) { this.notifyAll(); // TODO: use different lock for shutdown? } } } }
final long next = nextDynamicCheckTime.get(); reaperElement = _reaperElements.getFirst(); tsLogger.i18NLogger.warn_coordinator_TransactionReaper_18(reaperElement._control.get_uid(), reaperElement.statusName()); reinsertElement(reaperElement, _cancelWaitPeriod); reinsertElement(reaperElement, _cancelWaitPeriod); reinsertElement(reaperElement, _cancelFailWaitPeriod); tsLogger.i18NLogger.error_coordinator_TransactionReaper_5(Integer.toString(_zombieCount)); _reaperWorkerThread = new ReaperWorkerThread(TransactionReaper._theReaper); _reaperWorkerThread.setDaemon(true); _reaperWorkerThread.start(); tsLogger.i18NLogger.warn_coordinator_TransactionReaper_6(reaperElement._worker.toString(), reaperElement._control.get_uid());
/** * called by check, this method removes and reinserts an element in the timeout * ordered set, recalculating the next wakeup time accordingly. */ private void reinsertElement(ReaperElement e, long delay) { synchronized (this) { long newWakeup = _reaperElements.reorder(e, delay); nextDynamicCheckTime.set(newWakeup); // TODO - set should be atomic with reorder? } }
_reaperElements.setAllTimeoutsToZero(); while (!_reaperElements.isEmpty()) { try { this.wait(); _reaperWorkerThread.shutdown(); _workQueue.notifyAll(); _reaperWorkerThread.interrupt(); _reaperWorkerThread.join();
/** * @return the number of items in the reaper's list. * @since JTS 2.2. * * Note: this is a) expensive and b) an approximation. Should be called only by test code. */ public final long numberOfTransactions() { return _reaperElements.size(); }
public void remove(ReaperElement reaperElement) { if(pendingInsertions.remove(reaperElement) != null) { return; } // we missed finding it in the unsorted set - perhaps it has already been copied to the sorted set... synchronized(this) { removeSorted(reaperElement); } }
/** * @return the first (i.e. earliest to time out) element of the colleciton or null if empty */ public synchronized ReaperElement getFirst() { flushPending(); // we need to order the elements before we can tell which is first. if(elementsOrderedByTimeout.isEmpty()) { return null; } else { return elementsOrderedByTimeout.get(0); } }
return; ReaperElement reaperElement = new ReaperElement(control, timeout); _lifetime.addAndGet(timeout); if ((_timeouts.putIfAbsent(reaperElement._control, reaperElement) == null)) { _reaperElements.add(reaperElement); } else { throw new IllegalStateException(tsLogger.i18NLogger.get_coordinator_TransactionReaper_1()); if (_dynamic && reaperElement.getAbsoluteTimeout() < nextDynamicCheckTime.get()) { updateCheckTimeForEarlierInsert(reaperElement.getAbsoluteTimeout());
private final void removeElementReaper(ReaperElement reaperElement) { _reaperElements.remove(reaperElement); _timeouts.remove(reaperElement._control); synchronized (this) { // TODO set needs tobe atomic to getFirst? ReaperElement first = _reaperElements.getFirst(); if(first != null) { nextDynamicCheckTime.set(first.getAbsoluteTimeout()); } else { nextDynamicCheckTime.set(Long.MAX_VALUE); if(_inShutdown) { this.notifyAll(); // TODO: use different lock for shutdown? } } } }
/** * called by check, this method removes and reinserts an element in the timeout * ordered set, recalculating the next wakeup time accordingly. */ private void reinsertElement(ReaperElement e, long delay) { synchronized (this) { long newWakeup = _reaperElements.reorder(e, delay); nextDynamicCheckTime.set(newWakeup); // TODO - set should be atomic with reorder? } }
_reaperElements.setAllTimeoutsToZero(); while (!_reaperElements.isEmpty()) { try { this.wait(); _reaperWorkerThread.shutdown(); _workQueue.notifyAll(); _reaperWorkerThread.interrupt(); _reaperWorkerThread.join();
/** * @return the number of items in the reaper's list. * @since JTS 2.2. * * Note: this is a) expensive and b) an approximation. Should be called only by test code. */ public final long numberOfTransactions() { return _reaperElements.size(); }
public void remove(ReaperElement reaperElement) { if(pendingInsertions.remove(reaperElement) != null) { return; } // we missed finding it in the unsorted set - perhaps it has already been copied to the sorted set... synchronized(this) { removeSorted(reaperElement); } }
/** * @return the first (i.e. earliest to time out) element of the colleciton or null if empty */ public synchronized ReaperElement getFirst() { flushPending(); // we need to order the elements before we can tell which is first. if(elementsOrderedByTimeout.isEmpty()) { return null; } else { return elementsOrderedByTimeout.get(0); } }
return; ReaperElement reaperElement = new ReaperElement(control, timeout); _lifetime.addAndGet(timeout); if ((_timeouts.putIfAbsent(reaperElement._control, reaperElement) == null)) { _reaperElements.add(reaperElement); } else { throw new IllegalStateException(tsLogger.i18NLogger.get_coordinator_TransactionReaper_1()); if (_dynamic && reaperElement.getAbsoluteTimeout() < nextDynamicCheckTime.get()) { updateCheckTimeForEarlierInsert(reaperElement.getAbsoluteTimeout());
private final void removeElementReaper(ReaperElement reaperElement) { _reaperElements.remove(reaperElement); _timeouts.remove(reaperElement._control); synchronized (this) { // TODO set needs tobe atomic to getFirst? ReaperElement first = _reaperElements.getFirst(); if(first != null) { nextDynamicCheckTime.set(first.getAbsoluteTimeout()); } else { nextDynamicCheckTime.set(Long.MAX_VALUE); if(_inShutdown) { this.notifyAll(); // TODO: use different lock for shutdown? } } } }