use of org.jboss.netty.channel.ChannelFuture in project storm by nathanmarz.
the class StormClientHandler method sendRequests.
/**
* Retrieve a request from message queue, and send to server
* @param channel
*/
private void sendRequests(Channel channel, final MessageBatch requests) {
if (requests == null || requests.size() == 0 || being_closed.get())
return;
//if task==CLOSE_MESSAGE for our last request, the channel is to be closed
Object last_msg = requests.get(requests.size() - 1);
if (last_msg == ControlMessage.CLOSE_MESSAGE) {
being_closed.set(true);
requests.remove(last_msg);
}
//we may don't need do anything if no requests found
if (requests.isEmpty()) {
if (being_closed.get())
client.close_n_release();
return;
}
//write request into socket channel
ChannelFuture future = channel.write(requests);
future.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
LOG.info("failed to send requests:", future.getCause());
future.getChannel().close();
} else {
LOG.debug("{} request(s) sent", requests.size());
}
if (being_closed.get())
client.close_n_release();
}
});
}
use of org.jboss.netty.channel.ChannelFuture in project pinpoint by naver.
the class DefaultPinpointClientFactory method connect.
public PinpointClient connect(InetSocketAddress connectAddress) throws PinpointSocketException {
ChannelFuture connectFuture = bootstrap.connect(connectAddress);
PinpointClientHandler pinpointClientHandler = getSocketHandler(connectFuture, connectAddress);
PinpointClient pinpointClient = new DefaultPinpointClient(pinpointClientHandler);
traceSocket(pinpointClient);
return pinpointClient;
}
use of org.jboss.netty.channel.ChannelFuture in project pinpoint by naver.
the class PinpointClientHandshaker method handshake.
private void handshake(HandshakeJob handshakeJob) {
handshakeCount.incrementAndGet();
Channel channel = handshakeJob.getChannel();
ControlHandshakePacket packet = handshakeJob.getHandshakePacket();
logger.info("{} do handshake({}/{}). channel:{}.", simpleClassNameAndHashCodeString(), handshakeCount.get(), maxHandshakeCount, channel);
final ChannelFuture future = channel.write(packet);
future.addListener(handShakeFailFutureListener);
}
use of org.jboss.netty.channel.ChannelFuture in project pinpoint by naver.
the class PinpointClientStateTest method connect.
private DefaultPinpointClientHandler connect(PinpointClientFactory factory) {
ChannelFuture future = factory.reconnect(new InetSocketAddress("127.0.0.1", bindPort));
PinpointClientHandler handler = getSocketHandler(future, new InetSocketAddress("127.0.0.1", bindPort));
return (DefaultPinpointClientHandler) handler;
}
use of org.jboss.netty.channel.ChannelFuture in project bagheera by mozilla-metrics.
the class SubmissionHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Throwable cause = e.getCause();
HttpResponse response = null;
if (cause instanceof ClosedChannelException) {
// NOOP
} else if (cause instanceof TooLongFrameException) {
response = new DefaultHttpResponse(HTTP_1_1, REQUEST_ENTITY_TOO_LARGE);
} else if (cause instanceof InvalidPathException) {
response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
} else if (cause instanceof HttpSecurityException) {
LOG.error(cause.getMessage());
response = new DefaultHttpResponse(HTTP_1_1, FORBIDDEN);
} else {
LOG.error(cause.getMessage());
response = new DefaultHttpResponse(HTTP_1_1, INTERNAL_SERVER_ERROR);
}
if (response != null) {
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
updateResponseMetrics(null, response.getStatus().getCode());
}
}
Aggregations