F
farseer
Looking for some "best practice" advice.
The problem i am trying to solve is the following:
I have a server that waits for OP_ACCEPT and when that happens,
registers OP_READ for that channel).
When an OP_READ event is fired, my handling routine creates a "client"
object (which contains the Selection Key as a member) and add this to a
synchronized "queue". I have a number of threads blocking on that
queue when it's empty...so that when something is added, one of the
threads picks it up and processes it (reads from the socket).
However, once an OP_READ is fired, it continues to be fired until a
read occurs from that socket channel i believe. This means that if a
thread happens to not read from the queue'd client i just added, that
event is fired again, and in this case, i could have more than one
object added to my queue for the same event (i.e. if a client socket is
sending to my server, when OP_READ fires, i create a client object and
add it to the queue. Now OP_READ fires again for that same client send
(a thread did not process the read yet), and again a client object is
created and added to the queue for that same client.).
how do i prevent this? the one way is to make my Queue contain only
unique objects based on the Selection Key. but that is wasted
processing i think. i would prefer a way to say "i have queued this
event, please don't fire it again".
any thoughts.
The problem i am trying to solve is the following:
I have a server that waits for OP_ACCEPT and when that happens,
registers OP_READ for that channel).
When an OP_READ event is fired, my handling routine creates a "client"
object (which contains the Selection Key as a member) and add this to a
synchronized "queue". I have a number of threads blocking on that
queue when it's empty...so that when something is added, one of the
threads picks it up and processes it (reads from the socket).
However, once an OP_READ is fired, it continues to be fired until a
read occurs from that socket channel i believe. This means that if a
thread happens to not read from the queue'd client i just added, that
event is fired again, and in this case, i could have more than one
object added to my queue for the same event (i.e. if a client socket is
sending to my server, when OP_READ fires, i create a client object and
add it to the queue. Now OP_READ fires again for that same client send
(a thread did not process the read yet), and again a client object is
created and added to the queue for that same client.).
how do i prevent this? the one way is to make my Queue contain only
unique objects based on the Selection Key. but that is wasted
processing i think. i would prefer a way to say "i have queued this
event, please don't fire it again".
any thoughts.