Re: [Simpleweb-Support] Keep-alives and Connection close
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-10-23 18:01:15
|
Hi,
PipelineFactory factory = new MyPipelineFactory();
ProtocolHandler server = new MyProtocolHandler();
PipelineHandler handler = PipelineHandlerFactory.getInstance(server);
Connection connection = ConnectionFactory.getConnection(handler, factory);
public class MyPipelineFactory implements PipelineFactory {
pubilic Pipeline getInstance(Socket socket) {
Pipeline pipeline = new BufferedPipeline(socket, 2048);
pipeline.put("socket", socket);
return pipeline;
}
}
Now the request has the socket.
Socket socket = (Socket)request.getAttribute("socket");
Is there any reason you are not using 4.0.5. Just as easy to do this and more performant.
Niall
________________________________
From: "Agarwal, Rahul" <rag...@ea...>
To: Simple support and user issues <sim...@li...>
Sent: Thursday, October 23, 2008 6:41:48 PM
Subject: Re: [Simpleweb-Support] Keep-alives and Connection close
Hi Niall,
Thanks for your reply. I actually got a
hold of the server side socket for the connection in the Dispatcher (Poller.sock)
and using that as a key I can drive what I need to do (I wrote a small test and
it looks to do what I want). However that means having to modify Simple code
which I want to avoid. This is like your #2 idea.
If I could get the Socket in a
ProtocolHandler that would be ideal! I can create my own and add it to the
chain without changing simple.
When I look at Request.getAttribute, it is
empty and searching the code statically I don’t see anything trying to ‘put’
anything in there either.
Is it possible to get the socket in a
ProtocolHandler?
-Rahul
________________________________
From:Nia...@ub... [mailto:Nia...@ub...]
Sent: Wednesday, October 22, 2008
11:23 PM
To: sim...@li...
Subject: Re: [Simpleweb-Support]
Keep-alives and Connection close
Hi,
You will notice every connectionis
represented as a Pipline. Each pipeline has attributes and a Socket. So you can
do one of the following.
1) When the pipeline is created add an
AtomicInteger to it, each time it enters a ProtocolHandler add one to this
integer keyed by some know key, when it reaches above a threshold then add a
Connection: close
2) Get the server side port of the socket
(or the socket itself) for the pipeline so that each time it enters a
ProtocolHandler you can register a count. When the threshold has passed then
add a connection close.
To expose this data to the ProtocolHandler
simply look at the Request.getAttribute, this takes its attributes from the
Pipeline attributes, which are maintained across the lifetime of the
connection. Of particular interest is the PipelineFactory. Also, just to
mention, Simple 4.0.5 has been released and it uses NIO. You should find
this more responsive with pretty much the same feature set.
Niall
________________________________
From:Agarwal, Rahul [mailto:rag...@ea...]
Sent: 22 October 2008 19:42
To: sim...@li...
Subject: [Simpleweb-Support]
Keep-alives and Connection close
Hi folks,
I have a Simple 3.1.3 integration (with Spring) where I need
to add a new feature: send a connection close header after say 1000 requests
from each persistent connection and keep sending it until the client opens a
new connection. (some of our clients don’t respect the header).
My main question is how do I know when simple starts
executing a new request and how to identity if that is on a persistent
connection or a new one? (How do I hook into this?)
All I see are a series of ProtocolHandler getting called and
adding a new handler in the chain doesn’t look to be the answer.
Any suggestions on how to best tackle this in Simple?
My next concern would be how not to impact performance doing
this check (depends how I hook in).
Thanks
Rahul
|