use of org.jboss.netty.channel.SucceededChannelFuture in project opentsdb by OpenTSDB.
the class TestRpcHandler method emptyPathIsBadRequest.
@Test
public void emptyPathIsBadRequest() throws Exception {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
final Channel mockChan = handleHttpRpc(req, new Answer<ChannelFuture>() {
public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
assertEquals(HttpResponseStatus.BAD_REQUEST, response.getStatus());
return new SucceededChannelFuture((Channel) args.getMock());
}
});
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
Whitebox.invokeMethod(rpc, "handleHttpQuery", tsdb, mockChan, req);
}
use of org.jboss.netty.channel.SucceededChannelFuture in project camel by apache.
the class NettyProducer method openConnection.
protected ChannelFuture openConnection() throws Exception {
ChannelFuture answer;
if (isTcp()) {
// its okay to create a new bootstrap for each new channel
ClientBootstrap clientBootstrap = new ClientBootstrap(channelFactory);
clientBootstrap.setOption("keepAlive", configuration.isKeepAlive());
clientBootstrap.setOption("tcpNoDelay", configuration.isTcpNoDelay());
clientBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
clientBootstrap.setOption("connectTimeoutMillis", configuration.getConnectTimeout());
// set any additional netty options
if (configuration.getOptions() != null) {
for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
clientBootstrap.setOption(entry.getKey(), entry.getValue());
}
}
// set the pipeline factory, which creates the pipeline for each newly created channels
clientBootstrap.setPipelineFactory(pipelineFactory);
answer = clientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
if (LOG.isDebugEnabled()) {
LOG.debug("Created new TCP client bootstrap connecting to {}:{} with options: {}", new Object[] { configuration.getHost(), configuration.getPort(), clientBootstrap.getOptions() });
}
return answer;
} else {
// its okay to create a new bootstrap for each new channel
ConnectionlessBootstrap connectionlessClientBootstrap = new ConnectionlessBootstrap(datagramChannelFactory);
connectionlessClientBootstrap.setOption("child.keepAlive", configuration.isKeepAlive());
connectionlessClientBootstrap.setOption("child.tcpNoDelay", configuration.isTcpNoDelay());
connectionlessClientBootstrap.setOption("child.reuseAddress", configuration.isReuseAddress());
connectionlessClientBootstrap.setOption("child.connectTimeoutMillis", configuration.getConnectTimeout());
connectionlessClientBootstrap.setOption("child.broadcast", configuration.isBroadcast());
connectionlessClientBootstrap.setOption("sendBufferSize", configuration.getSendBufferSize());
connectionlessClientBootstrap.setOption("receiveBufferSize", configuration.getReceiveBufferSize());
// set any additional netty options
if (configuration.getOptions() != null) {
for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
connectionlessClientBootstrap.setOption(entry.getKey(), entry.getValue());
}
}
// set the pipeline factory, which creates the pipeline for each newly created channels
connectionlessClientBootstrap.setPipelineFactory(pipelineFactory);
// if no one is listen on the port
if (!configuration.isUdpConnectionlessSending()) {
answer = connectionlessClientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
} else {
// bind and store channel so we can close it when stopping
Channel channel = connectionlessClientBootstrap.bind(new InetSocketAddress(0));
allChannels.add(channel);
answer = new SucceededChannelFuture(channel);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Created new UDP client bootstrap connecting to {}:{} with options: {}", new Object[] { configuration.getHost(), configuration.getPort(), connectionlessClientBootstrap.getOptions() });
}
return answer;
}
}
Aggregations