Sean;

> (1) Now, with sessions: If a browser window is open
> and the guy makes
> a query and, say, the busy and progress indicator is
> showing whilst the
> server is processing
> the results, the user goes "BACK" to the initial
> query page and does another
> query. Is it still
> the same session (i.e. the same session ID) when the
> request gets to the
> server or what does
> actually happen?

It is up to you how to handle this, but I foresee two
options:

1. If a search is already running when your user
submitts a new one, then they would "rejoin" that
search and continue to get progress messages from the
search that was running.

2. If a search is already running when your user
submitts a new one, ditch the running process and
submit the new one.

> (2) "Once it is running, it places the worker object
> in state indexed by
> session.getId()." This
> is actually using the putValue of the Session to
> save your Thread object in
> the Session object ?

Yes it is. However, you may ultimately want to store
several objects in the session so I would advise you
to use an additional pre/suffix with the
session.getId() value.


//Nicholas

--- Sean Snyders <[EMAIL PROTECTED]> wrote:
> Nicholas,
>
> Thanx for the detailed explanation. Over the
> weekend, I sort-of came to
> the same solution but still have a few questions:
>
> Here is the scenario:
> I'm writing a small scale search engine. The browser
> sends the query
> to the server to do processing:
>
> (1) Now, with sessions: If a browser window is open
> and the guy makes
> a query and, say, the busy and progress indicator is
> showing whilst the
> server is processing
> the results, the user goes "BACK" to the initial
> query page and does another
> query. Is it still
> the same session (i.e. the same session ID) when the
> request gets to the
> server or what does
> actually happen?
>
> (2) "Once it is running, it places the worker object
> in state indexed by
> session.getId()." This
> is actually using the putValue of the Session to
> save your Thread object in
> the Session object ?
>
> Thank you, for this excellent response.
>
> Sean.
>
> >Sean;
> >
> >I have had several requests to explain this so at
> some
> >point I will post a working sample.
> >
> >It goes like this:
> >
> >1. Browser sends request to servlet for long
> running
> >process.
> >
> >2. Servlet receives request. The servlet thread
> >(requester) instantiates a "worker" object that
> >extends Thread.
> >
> >3. The worker object has 3 public methods:
> >a) StringBuffer getStatus()
> >b) boolean isComplete()
> >c) void run()  // for running Thread
> >
> >Internally, the worker places progress messages in
> a
> >string buffer. This buffer is returned by
> getStatus().
> >
> >When the worker is initialized, a boolean bComplete
> is
> >set to false. The run() method sets this boolean to
> >true when the run process is complete. (Preferably
> in
> >a finally block so it is guaranteed to "complete").
> >
> >4. The requester initializes the worker and starts
> it
> >running.(start()) Once it is running, it places the
> >worker object in state indexed by session.getId().
> >
> >5. The servlet now builds a web page that has
> >something like:
> >a) A status (IN PROGRESS)
> >b) A list of messages showing the progress of the
> >worker. (from worker.getStatus())
> >c) A refresh tag to resubmit the request to get an
> >update.
> >
> >6. Every time the refresh submits, the servlet
> grabs
> >the worker from state (possibly still runing) and
> >grabs the status messages and tests to see if it is
> >complete.
> >
> >7. If the worker is not complete, go to 5.
> >
> >8. When the worker returns isComplete()==true, then
> >your long running process has finished.
> >
> >9. The servlet now builds a web page that has
> >something like:
> >a) A status (COMPLETE)
> >b) A list of messages showing the progress of the
> >worker. (from worker.getStatus())
> >c) **NO** refresh tag.
> >
> >10. The servlet removes the worker from state.
> >
> >Done.
> >
> >//Nicholas
> >
> >--- Sean Snyders <[EMAIL PROTECTED]> wrote:
> >> The problem is as follows:
> >>
> >> I am not using 'n client side program (applet)
> for
> >> reasons
> >> of distribution and availability, thus I only
> have a
> >> browser doing "gets"
> >> from the server.
> >>
> >> This limits my application to one request from
> the
> >> server and then the
> >> client receives the result.
> >> If I have to do a refresh from the server as you
> >> suggested, the server will
> >> process this as a new request
> >> and start afresh. Does this mean session
> management?
> >> and does session
> >> management need a client application?
> >>
> >> Another question: What do you mean by: "Then I
> put
> >> the thread object in
> >> state."
> >>
> >> Thanx
> >>
> >> Sean.
> >>
> >> -: Sean Snyders
> >>  -: mailto:[EMAIL PROTECTED]
> >> www.cs.sun.ac.za/~snyders
> >>  -: Computer Science Department       ph:
> >> +27-21-808-4393
> >>  -: University of Stellenbosch               fax:
> >> +27-21-808-4416
> >>  -: Republic of South Africa
> >>
> >>
> >> -----Original Message-----
> >> From: Nicholas Whitehead <[EMAIL PROTECTED]>
> >> To: [EMAIL PROTECTED]
> >> <[EMAIL PROTECTED]>
> >> Date: 13 January 2000 19:03
> >> Subject: Re: Timing out of response data
> >>
> >>
> >> >There was recently a post about this issue. The
> >> person
> >> >was using IE though, and I believe they fixed it
> >> with
> >> >a patch.
> >> >
> >> >Alternatively, I tend to send a progress refresh
> >> back
> >> >to the browser when I have a long running
> process.
> >> >
> >> >Basically, I start a new thread and run the
> process
> >> in
> >> >that. Internally the thread updates a string
> buffer
> >> >with messages that tell the user the status of
> the
> >> >running process. Then I put the thread object in
> >> >state. I send a page back to the user trhat
> >> contains
> >> >the buffer messages plus a refresh tag.
> >> >
> >> >The page comes back and then periodically
> refreshes
> >> >with new data from the message buffer, until the
> >> >process completes. Then the complete message
> buffer
> >> is
> >> >returned with a completion announcement and no
> >> refresh
> >> >tag.
> >> >
> >> >Wasthatamouthful,itfeltlikeit.
> >> >
> >> >//Nicholas
> >> >
> >> >--- Sean Snyders <[EMAIL PROTECTED]> wrote:
> >> >> Hi,
> >> >>
> >> >> The following situation exists:
> >> >>
> >> >> I have a servlet that answers a request from a
> >> >> browser (the browser sending
> >> >> a request eg:
> >> >>
>
=== message truncated ===

=====
"Piper, Piper the red red worm
awoke last night to the sound of the storm
the words are the words I sailed upon."
Piper, Phish

--
Nicholas Whitehead
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to