List of usage examples for io.netty.util Timer newTimeout
Timeout newTimeout(TimerTask task, long delay, TimeUnit unit);
From source file:com.king.platform.net.http.netty.pool.PoolingChannelPool.java
License:Apache License
public PoolingChannelPool(final Timer cleanupTimer, TimeProvider timeProvider, long timeoutInSeconds, final MetricCallback metricCallback) { this.timeProvider = timeProvider; this.metricCallback = metricCallback; maxTtl = TimeUnit.SECONDS.toMillis(timeoutInSeconds); cleanupTimer.newTimeout(new TimerTask() { @Override//from w w w .j ava 2 s. c o m public void run(Timeout timeout) throws Exception { for (Map.Entry<ServerInfo, ServerPool> poolEntry : serverPoolMap.entrySet()) { ServerPool serverPool = poolEntry.getValue(); ServerInfo serverInfo = poolEntry.getKey(); serverPool.cleanExpiredConnections(); if (serverPool.shouldRemovePool()) { ServerPool remove = serverPoolMap.remove(serverInfo); if (remove != null) { metricCallback.onRemovedServerPool(serverInfo.getHost()); } } } cleanupTimer.newTimeout(timeout.task(), maxTtl, TimeUnit.MILLISECONDS); } }, maxTtl, TimeUnit.MILLISECONDS); }