/** * @param ev * @return */ private final void decrementSyncCounter(Event ev) { final Object source = ev._ev.getSource(); synchronized (_sourcesEventCount) { final SynchronizedLimitedInt sli = (SynchronizedLimitedInt) _sourcesEventCount.get(source); if (sli != null && sli.decrement() <= 0) { _sourcesEventCount.remove(source); sli.destroy(); } } }
/** * @param ev * @return */ private final void incrementSyncCounter(Event ev, boolean doNotBlock) { final Object source = ev._ev.getSource(); SynchronizedLimitedInt sli; synchronized (_sourcesEventCount) { // NOTE: hash code of source should not change !!! sli = (SynchronizedLimitedInt) _sourcesEventCount.get(source); if (sli == null) { _sourcesEventCount.put(source, new SynchronizedLimitedInt(1, _limit)); return; } } // this will block when limit is reached // (NOTE: it might happen that sli is removed/destroyed here) sli.increment(doNotBlock); }