Sending large files

Jiang Bian timobj at gmail.com
Tue Jun 2 02:06:55 EDT 2009


Long story short, one part of my project requires to send large files using
netty. The large is split into small chunks, and at the end, the client is
suppose to send a "end command" signal. The problem is the "end command"
never gets to the server, when sending big files (20MB). 

Here is my code for the sendFile funciton.

   private void sendFile(MessageEvent e) throws InterruptedException {

	ChannelFuture lastWriteFuture = null;

	int count = wrappedFile.getSegmentCount();

	int sleepTime = SystemConfigHelper.getSystemConfigHelper()
		.getSleepTime();

	int i = 0;
	while (e.getChannel().isWritable() && i < count) {
	    for (; i < count; i++) {
		// logger.info("sending segment " + i);
		Chunk chunk = wrappedFile.getChunk(i);
		// logger.debug("sending: " + chunk.getMD5String());
		// logger.debug("length: " + chunk.getPayload().length);
		ChannelBuffer buffer = JigDFSProtocolRequestFactory
			.chunkData(chunk);

		this.bytesSent.addAndGet(buffer.capacity());

		lastWriteFuture = e.getChannel().write(buffer);

		try {
		    Thread.sleep(sleepTime);
		} catch (InterruptedException ex) {
		    ex.printStackTrace();
		    throw new InterruptedException(ex.getMessage());
		}

	    }
	}

	// Wait until all messages are flushed before closing the channel.
	if (lastWriteFuture != null) {
	    lastWriteFuture.awaitUninterruptibly();
	}

	logger.debug("end chunk data");

	logger.debug("write end_chunk_data command");

	lastWriteFuture = e.getChannel().write(
		JigDFSProtocolRequestFactory.endChunkData());

	// Wait until all messages are flushed...
	if (lastWriteFuture != null) {
	    lastWriteFuture.awaitUninterruptibly();
	}

	logger.info("file sent...");

    }

It works fine with small files. So, my question basically is: what's the
right way to  ensure a message gets to the server on the client side? 
Hope I am not making stupid mistakes here.
Please let me know if you need any other information. 

Thanks,

Jiang
-- 
View this message in context: http://n2.nabble.com/Sending-large-files-tp3010547p3010547.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list