I'm doing a little stock application using NIO as a demo that I want to
migrate to grizzly. The goal is really to create a migration guide, that we
be used by anyone that want to start grizzly or how to migration a current
nio gateway to grizzly.
I posted a question how to start with grizzly few weeks ago, but I didn't
have enough knowledge in nio to really understand what I was doing in
grizzly. I could I done copy paste, but that won't made good applications.
I'll want your advice on my actual demo.
I been in the presentation of Grizzly and Comet at Montreal last week, and
Jean-Francois told that one problem often found was One thread by incoming
connection. Adn guest what.. it's what I'm doing. That's one of my
problems that I want to solve. Using nio if possible in the current
implementation of my demo, and after that how to do it right using grizzly.
I hope that my future guide will help people.
here a description of the application :
This project is a little real-time quote stock server.
The goal of this project was to create a demo and
a migration guide : "How to convert NIO server to Grizzly.
A client can ask for a quote or a quote feed (the client will receive all
update on the stock)
This server simulate a 3th party connection (where it will get the quotes
for the symbols).
When this server lost the connection will the 3th party, it will reconnect
and resend all the
quote feed request to the 3th party.
In a real application the server should be able to handle this :
50 clients simultany and 5000 symbols cached. Of theses clients, there will
be 5 admin (they will receive
all the symbols updates in realtime). There will be around 20 clients that
will ask for 100 symbols quote feed.
And the others clients, will ask for a quote and disconnect after that. We
can expect have a request each second
from theses clients.
Remarks :
The server will listen on a TCP port for incoming client. A thread will be
created for each client.
The server had a limited buffer size for parsing the client request. If the
buffer limit is reach,
the server will close the connection with the client.
When a client request a quote, the server will return the latest quote from
it cache if there was a quote feed requested.
When the client disconnect from the server, the server will stop the quote
feed if there is no more client subscribe to the feed.
When a client disconnect the server throws a
java.nio.channels.AsynchronousCloseException.
When the server lost the connection with the 3th party, it will resend all
the quote feed, but if the 3th party can't handle all the requests in the
same time, it could close the connection, and we will be in a loop. The
server will resend all the request, and the 3th party will reclose the
connection. Need to be able to add delay between the sending.
to test the demo is really simple.. start the main class NIOGateway
and connect using telnet localhost 5000
you can send theses command in the telcnet console
this command will ask for a quote and quit after that
quote|aaa[eoq]
this command will ask for a feed. You will receive all the update on the
symbol
feed|aaa[eoq]
You can ask multiple feed in the same console.. that will works.
to stop a feed use this :
quit|aaa[eoq]
In a second implementation of the demo, I'll add Queue in the server.
something the server is not able to parse all the requests in the same time,
so the buffer will explode :)
to faster to process the server will read the query and put it in a
BlockQueue suing Producer/Consumer. It work well in a real application.
any comments ?
my email it just to big.. Who read it completly ? :)