/** * Schedule a rate-limit task if necessary. Lock must be acquired before calling this method! */ private void schedule() { schedule(_period); }
/** * Increment the period. */ public void incrementPeriod() { synchronized (this) { setPeriod(Math.min(_maxPeriod, (_period == 0 ? _initialIncrement : _period * 2))); } }
@Override public AsyncPool<Channel> getPool(SocketAddress address) { return new AsyncPoolImpl<>(address.toString(), new ChannelPoolLifecycle(address, _bootstrap, _allChannels, false), _maxPoolSize, _idleTimeout, _scheduler, _maxPoolWaiterSize, _strategy, _minPoolSize, new ExponentialBackOffRateLimiter(0, ChannelPoolLifecycle.MAX_PERIOD_BEFORE_RETRY_CONNECTIONS, ChannelPoolLifecycle.INITIAL_PERIOD_BEFORE_RETRY_CONNECTIONS, _scheduler, _maxConcurrentConnectionInitializations), SystemClock.instance(), NoopLongTracker.instance() ); }
@Override public AsyncPool<Channel> getPool(SocketAddress address) { return new AsyncPoolImpl<>(address.toString(), new ChannelPoolLifecycle(address, _bootstrap, _allChannels, _tcpNoDelay), _maxPoolSize, _idleTimeout, _scheduler, _maxPoolWaiterSize, _strategy, _minPoolSize, new ExponentialBackOffRateLimiter(0, ChannelPoolLifecycle.MAX_PERIOD_BEFORE_RETRY_CONNECTIONS, ChannelPoolLifecycle.INITIAL_PERIOD_BEFORE_RETRY_CONNECTIONS, _scheduler, _maxConcurrentConnectionInitializations), SystemClock.instance(), NoopLongTracker.instance() ); } }
@Override public void submit(Task t) { boolean runNow = false; synchronized (this) { if (_period == 0 && _pending.isEmpty() && _runningTasks < _maxRunningTasks) { _runningTasks ++; runNow = true; } else { _pending.add(t); schedule(); } } if (runNow) { t.run(_doneCallback); } }
public void setPeriod(long ms) { Long previous = null; ms = Math.min(_maxPeriod, Math.max(_minPeriod, ms)); synchronized (this) { if (ms != _period) { previous = _period; _period = ms; if (!_pending.isEmpty() && (_task == null || _task.cancel(false))) { long adjustedPeriod = _period; if (_task != null) { long elapsedTime = previous - _task.getDelay(TimeUnit.MILLISECONDS); adjustedPeriod = Math.max(_period - elapsedTime, 0); _task = null; } schedule(adjustedPeriod); } } } if (previous != null) { // Use previous to avoid logging in the synchronized block LOG.debug("Minimum period changed from {} to {}", previous, ms); } }