producer.start();
}
public void httptest(String fileName) {
ClientBootstrap client = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
client.setPipelineFactory(new ClientPipelineFactory());
Channel channel = null;
HttpRequest request;
ChannelBuffer buffer;
try {
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
long starttimestamp = System.currentTimeMillis();
long endtimestamp = System.currentTimeMillis();
int recCount = 0;
while ((strLine = br.readLine()) != null) {
channel = client
.connect(new InetSocketAddress("127.0.0.1", 8080))
.awaitUninterruptibly().getChannel();
request = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.POST, "/insert");
recCount++;
if ((recCount % 1000) == 1) {
endtimestamp = System.currentTimeMillis();
System.out.print("It took " );
System.out.print( endtimestamp - starttimestamp );
System.out.println(" ms to load 1000 records through http");
starttimestamp = endtimestamp;
}
buffer = ChannelBuffers.copiedBuffer(strLine,
Charset.defaultCharset());
request.addHeader(
org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH,
buffer.readableBytes());
request.setContent(buffer);
channel.write(request).awaitUninterruptibly().getChannel()
.getCloseFuture().awaitUninterruptibly();
;
}
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
channel.getCloseFuture().awaitUninterruptibly();
client.releaseExternalResources();
}