use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method pollPooledChannel.
private Channel pollPooledChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) {
try {
asyncHandler.onConnectionPoolAttempt();
} catch (Exception e) {
LOGGER.error("onConnectionPoolAttempt crashed", e);
}
Uri uri = request.getUri();
String virtualHost = request.getVirtualHost();
final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getChannelPoolPartitioning());
if (channel != null) {
LOGGER.debug("Using pooled Channel '{}' for '{}' to '{}'", channel, request.getMethod(), uri);
}
return channel;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method sendRequestThroughProxy.
/**
* Using CONNECT depends on wither we can fetch a valid channel or not Loop
* until we get a valid channel from the pool and it's still valid once the
* request is built @
*/
private <T> ListenableFuture<T> sendRequestThroughProxy(Request request, AsyncHandler<T> asyncHandler, NettyResponseFuture<T> future, ProxyServer proxyServer) {
NettyResponseFuture<T> newFuture = null;
for (int i = 0; i < 3; i++) {
Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
if (channel == null) {
// pool is empty
break;
}
if (newFuture == null) {
newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, false);
}
if (Channels.isChannelActive(channel)) {
// otherwise, channel was closed by the time we computed the request, try again
return sendRequestWithOpenChannel(newFuture, asyncHandler, channel);
}
}
// couldn't poll an active channel
newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, true);
return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project async-http-client by AsyncHttpClient.
the class NettyChannelConnector method connect0.
private void connect0(Bootstrap bootstrap, final NettyConnectListener<?> connectListener, InetSocketAddress remoteAddress) {
bootstrap.connect(remoteAddress, localAddress).addListener(new SimpleChannelFutureListener() {
@Override
public void onSuccess(Channel channel) {
try {
asyncHandler.onTcpConnectSuccess(remoteAddress, channel);
} catch (Exception e) {
LOGGER.error("onTcpConnectSuccess crashed", e);
connectListener.onFailure(channel, e);
return;
}
connectListener.onSuccess(channel, remoteAddress);
}
@Override
public void onFailure(Channel channel, Throwable t) {
try {
asyncHandler.onTcpConnectFailure(remoteAddress, t);
} catch (Exception e) {
LOGGER.error("onTcpConnectFailure crashed", e);
connectListener.onFailure(channel, e);
return;
}
boolean retry = pickNextRemoteAddress();
if (retry) {
NettyChannelConnector.this.connect(bootstrap, connectListener);
} else {
connectListener.onFailure(channel, t);
}
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class DefaultConsumerIdsChangeListener method handle.
@Override
public void handle(ConsumerGroupEvent event, String group, Object... args) {
if (event == null) {
return;
}
switch(event) {
case CHANGE:
if (args == null || args.length < 1) {
return;
}
List<Channel> channels = (List<Channel>) args[0];
if (channels != null && brokerController.getBrokerConfig().isNotifyConsumerIdsChangedEnable()) {
for (Channel chl : channels) {
this.brokerController.getBroker2Client().notifyConsumerIdsChanged(chl, group);
}
}
break;
case UNREGISTER:
this.brokerController.getConsumerFilterManager().unRegister(group);
break;
case REGISTER:
if (args == null || args.length < 1) {
return;
}
Collection<SubscriptionData> subscriptionDataList = (Collection<SubscriptionData>) args[0];
this.brokerController.getConsumerFilterManager().register(group, subscriptionDataList);
break;
default:
throw new RuntimeException("Unknown event " + event);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class Broker2Client method getConsumeStatus.
public RemotingCommand getConsumeStatus(String topic, String group, String originClientId) {
final RemotingCommand result = RemotingCommand.createResponseCommand(null);
GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
requestHeader.setTopic(topic);
requestHeader.setGroup(group);
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, requestHeader);
Map<String, Map<MessageQueue, Long>> consumerStatusTable = new HashMap<String, Map<MessageQueue, Long>>();
ConcurrentMap<Channel, ClientChannelInfo> channelInfoTable = this.brokerController.getConsumerManager().getConsumerGroupInfo(group).getChannelInfoTable();
if (null == channelInfoTable || channelInfoTable.isEmpty()) {
result.setCode(ResponseCode.SYSTEM_ERROR);
result.setRemark(String.format("No Any Consumer online in the consumer group: [%s]", group));
return result;
}
for (Map.Entry<Channel, ClientChannelInfo> entry : channelInfoTable.entrySet()) {
int version = entry.getValue().getVersion();
String clientId = entry.getValue().getClientId();
if (version < MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) {
result.setCode(ResponseCode.SYSTEM_ERROR);
result.setRemark("the client does not support this feature. version=" + MQVersion.getVersionDesc(version));
log.warn("[get-consumer-status] the client does not support this feature. version={}", RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version));
return result;
} else if (UtilAll.isBlank(originClientId) || originClientId.equals(clientId)) {
try {
RemotingCommand response = this.brokerController.getRemotingServer().invokeSync(entry.getKey(), request, 5000);
assert response != null;
switch(response.getCode()) {
case ResponseCode.SUCCESS:
{
if (response.getBody() != null) {
GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
consumerStatusTable.put(clientId, body.getMessageQueueTable());
log.info("[get-consumer-status] get consumer status success. topic={}, group={}, channelRemoteAddr={}", topic, group, clientId);
}
}
default:
break;
}
} catch (Exception e) {
log.error("[get-consumer-status] get consumer status exception. topic={}, group={}, offset={}", new Object[] { topic, group }, e);
}
if (!UtilAll.isBlank(originClientId) && originClientId.equals(clientId)) {
break;
}
}
}
result.setCode(ResponseCode.SUCCESS);
GetConsumerStatusBody resBody = new GetConsumerStatusBody();
resBody.setConsumerTable(consumerStatusTable);
result.setBody(resBody.encode());
return result;
}
Aggregations