dev@grizzly.java.net

wired idea :)

From: rama <rama.rama_at_tiscali.it>
Date: Wed, 28 Jan 2009 10:18:21 +0100

Hello :D

i have a bad piece of code, and i need some idea to move it to grizzly.


the code basically work like this


sock = ss.accept();
String msg = sock.read.blablalba;

if ("cd".equals(msg))
        new thread1(sock);
if ("bla".equals(msg))
        new thread2(sock)

and so on...


suppose that thread1 need to be blocking and do
sock.read
blabla
sock.write

with blocking (means that he will wait for a connection indefinetly)


the thread2 will do the same, but the difference is
that i expect only 2 threads(1) and many thread(2).

for this reason thread2 could be reduced to a pool of worker, using
nonblocking,
while thread1 could stay the same.

Can grizzly help me in some way?


The easy solution that come into my mind is to split the problem in 2
part

1) thread1 will listen on port X
2) thread2 will listen on port X+1

Thread1 will use the normal thread on connection approach
while thread2 will use nio (with grizzly) approach.

But with this impl i need to change a lot of stuff, and probably i
can do it a bit better.

The second idea, that i want to share with you, is
when a socket go to thread1, it's managed with blocking read/write
when a socket go to thread2, it's added to a pool of connection, set
as nonblocking, and then managed in this way.
can i use grizzly to achive this result?

best regards
Rama