/** * Creates a new instance with a new default {@link IoEventQueueThrottle}. */ public WriteRequestFilter() { this(new IoEventQueueThrottle()); }
/** * {@inheritDoc} */ @Override public void offered(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(eventSize); logState(); if (currentCounter >= threshold) { block(); } }
/** * {@inheritDoc} */ @Override public void polled(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(-eventSize); logState(); if (currentCounter < threshold) { unblock(); } }
private int estimateSize(IoEvent event) { int size = getEventSizeEstimator().estimateSize(event); if (size < 0) { throw new IllegalStateException(IoEventSizeEstimator.class.getSimpleName() + " returned " + "a negative value (" + size + "): " + event); } return size; }
private void logState() { if (LOGGER.isDebugEnabled()) { LOGGER.debug(Thread.currentThread().getName() + " state: " + counter.get() + " / " + getThreshold()); } }
/** * Creates a new IoEventQueueThrottle instance * * @param eventSizeEstimator The IoEventSizeEstimator instance * @param threshold The events threshold */ public IoEventQueueThrottle(IoEventSizeEstimator eventSizeEstimator, int threshold) { if (eventSizeEstimator == null) { throw new IllegalArgumentException("eventSizeEstimator"); } this.eventSizeEstimator = eventSizeEstimator; setThreshold(threshold); }
private int estimateSize(IoEvent event) { int size = getEventSizeEstimator().estimateSize(event); if (size < 0) { throw new IllegalStateException(IoEventSizeEstimator.class.getSimpleName() + " returned " + "a negative value (" + size + "): " + event); } return size; }
private void logState() { if (LOGGER.isDebugEnabled()) { LOGGER.debug(Thread.currentThread().getName() + " state: " + counter.get() + " / " + getThreshold()); } }
public IoEventQueueThrottle(IoEventSizeEstimator eventSizeEstimator, int threshold) { if (eventSizeEstimator == null) { throw new NullPointerException("eventSizeEstimator"); } this.eventSizeEstimator = eventSizeEstimator; setThreshold(threshold); }
/** * {@inheritDoc} */ @Override public void offered(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(eventSize); logState(); if (currentCounter >= threshold) { block(); } }
/** * {@inheritDoc} */ @Override public void polled(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(-eventSize); logState(); if (currentCounter < threshold) { unblock(); } }
private int estimateSize(IoEvent event) { int size = getEventSizeEstimator().estimateSize(event); if (size < 0) { throw new IllegalStateException( IoEventSizeEstimator.class.getSimpleName() + " returned " + "a negative value (" + size + "): " + event); } return size; }
private void logState() { if (LOGGER.isDebugEnabled()) { LOGGER.debug(Thread.currentThread().getName() + " state: " + counter.get() + " / " + getThreshold()); } }
/** * Creates a new instance with a new default {@link IoEventQueueThrottle}. */ public WriteRequestFilter() { this(new IoEventQueueThrottle()); }
/** * Creates a new IoEventQueueThrottle instance * * @param eventSizeEstimator The IoEventSizeEstimator instance * @param threshold The events threshold */ public IoEventQueueThrottle(IoEventSizeEstimator eventSizeEstimator, int threshold) { if (eventSizeEstimator == null) { throw new IllegalArgumentException("eventSizeEstimator"); } this.eventSizeEstimator = eventSizeEstimator; setThreshold(threshold); }
public void offered(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(eventSize); logState(); if (currentCounter >= threshold) { block(); } }
public void polled(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(-eventSize); logState(); if (currentCounter < threshold) { unblock(); } }
/** * Creates a new instance with a new default {@link IoEventQueueThrottle}. */ public WriteRequestFilter() { this(new IoEventQueueThrottle()); }