NIO Server

Hi to all,

I have to create a server. Server will be bridge between clients and another server. I want to make architecture with worker threads. When selector selects a key it is passed to worker thread, if available. If worker thread is not available selection continue until worker thread is available.

1. In worker thread I remove OP_READ interest while reading from channel and after that return removed OP_READ interest. If reading (and doing something else with read data in worker thread) is time consuming operation what will happen if read data is not the whole packet from client and the rest of the packet arrives while reading first part of that packet in thread. The OP_READ interest is removed. I think that second part of the packet will be saved in kernel buffer and after returning OP_READ interest to channel the selector will select again that channel. But while reading first part of the packet kernel's buffer is full of data. It will be removed or data in kernel buffer is in queue.

2. Is it right to read all available data from channel in selector's thread and after reading to pass it to worker thread. Is this is acceptable for handling many clients(above 10 000).

[1218 byte] By [aleksndar.valcheva] at [2007-10-2 19:56:17]
# 1
Aleksndar, I would highly recommend to use something like Apache Mina to handle all these details. With Mina you can simply focus on your protocol and not worry about NIO, workers or threading. http://directory.apache.org/subprojects/mina/ S.
StefanArentza at 2007-7-13 22:35:37 > top of Java-index,Other Topics,Patterns & OO Design...