The external process creates a socket on a port and keeps waiting on it. All the webserver has to do is to bind to it.
1. When you say we can store the reference in servlet context, you mean through setattribute? I can look more into that.
2. Since blocking on the request/response thread is not good, can I reply for a session from a different thread?
3. I can get the session id from the http request. But how do I convert it back to http request and use to send response back?
Hi Mark,
There is no doubt in how the IPC / Thread communication needs to work here. There are only 3 clarifications I need from the servlet environment:
The external client (X) is not going to give me the info of which web client I need to respond to. This needs to be stored in some global data structure in the webserver and when the response comes from the external client I need to figure which webclient to respond to.
1. How do I store the global data structure in servlets (across all sessions) with each web client's connection info?
2. Does my servlet thread have to be blocked in condvar till the response comes from the external client? Or can I respond from a different thread?
3. If I can respond, what is the web client's connection info we need to hold? In case of normal ipc, its just fd's. Would storing "HttpServletResponse response" be good enough for responding later for that client?
In a standard application, C1 sends some info to the webserver. I can have the connection info of C1 stored in some data structure and send the non blocking request to X.
When the response for X comes back on a different thread, I can look up the connection info of C1 from the data structure and reply on that.
Ok. This is how it would have been done on a standard client app
Events are shown in timeline here:
T1 C1 ------> Web Server
T2 Web Server ---(nb socket send Request1)------> X
T3 C2 ------> Web Server
T4 Web Server ---(nb socket send Request 2)-----> X
T5 Web Server <---(nb socket resp Response 1)----X
T6 Web Server <---(nb socket resp Response 2)----X
The webserver would receive responses on a dedicated thread from X. Now how would it respond to C1 and C2?
Thanks for the input. But the response to the servlet should be back in less than a second. Still I dont want this thread to be blocked for that 1 second just for the response from the external process.
Say I get client requests A1, A2 and then the servlet sends the non blocking msg for these to X. When the response comes for A1 on the dedicated thread, how can the servlet respond for A1 to the client?
Each time a new request from a client is obtained, the webserver needs to send out a non blocking msg on the socket out to a process X. Later it receives a msg over socket from X and has to correlate it to which client request it got that reply for and respond to the client.
Hi,
If the webserver want to communicate through non-blocking with some process for each http request it gets, the webserver will need to store some information to handle the reply part of it. But the current mechanisms I see dont really provide a nice method to store and retrieve that info. Is there any known methods for that?
Thanks for the info. Shall look at connection pools. But is there any code sample for using the application context? Googling returns it mostly as the context info the deployment desc file...