|
|
|
@ -28,12 +28,14 @@ import io.netty.util.AttributeKey; |
|
|
|
|
*/ |
|
|
|
|
public class ClientChannelMannager { |
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ClientChannelMannager.class); |
|
|
|
|
private static Logger LOGGER = LoggerFactory.getLogger(ClientChannelMannager.class); |
|
|
|
|
|
|
|
|
|
private static final AttributeKey<Boolean> USER_CHANNEL_WRITEABLE = AttributeKey.newInstance("user_channel_writeable"); |
|
|
|
|
|
|
|
|
|
private static final AttributeKey<Boolean> CLIENT_CHANNEL_WRITEABLE = AttributeKey.newInstance("client_channel_writeable"); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 最大连接数 |
|
|
|
|
*/ |
|
|
|
|
private static final int MAX_POOL_SIZE = 100; |
|
|
|
|
|
|
|
|
|
private static Map<String, Channel> realServerChannels = new ConcurrentHashMap<String, Channel>(); |
|
|
|
@ -58,7 +60,7 @@ public class ClientChannelMannager { |
|
|
|
|
if (future.isSuccess()) { |
|
|
|
|
borrowListener.success(future.channel()); |
|
|
|
|
} else { |
|
|
|
|
logger.warn("connect proxy server failed", future.cause()); |
|
|
|
|
LOGGER.warn("connect proxy server failed", future.cause()); |
|
|
|
|
borrowListener.error(future.cause()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -72,7 +74,7 @@ public class ClientChannelMannager { |
|
|
|
|
proxyChanel.config().setOption(ChannelOption.AUTO_READ, true); |
|
|
|
|
proxyChanel.attr(Constants.NEXT_CHANNEL).set(null); |
|
|
|
|
proxyChannelPool.offer(proxyChanel); |
|
|
|
|
logger.debug("return ProxyChanel to the pool, channel is {}, pool size is {} ", proxyChanel, proxyChannelPool.size()); |
|
|
|
|
LOGGER.debug("return ProxyChanel to the pool, channel is {}, pool size is {} ", proxyChanel, proxyChannelPool.size()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -113,7 +115,7 @@ public class ClientChannelMannager { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void clearRealServerChannels() { |
|
|
|
|
logger.warn("channel closed, clear real server channels"); |
|
|
|
|
LOGGER.warn("channel closed, clear real server channels"); |
|
|
|
|
|
|
|
|
|
Iterator<Entry<String, Channel>> ite = realServerChannels.entrySet().iterator(); |
|
|
|
|
while (ite.hasNext()) { |
|
|
|
|