From: Adam R. <Ad...@Kn...> - 2003-03-04 21:58:06
|
A few short notes: 1. People are using Pushlets to try to build instant messaging = environments. 2. The suggestion from the email thread below is to use a polling = mechanism (via JS timers) to check to see if the Pushlet client is still connected = to the Pushlet server. Presence-by-polling may not scale, but it's = probably a serviceable solution for what they're using it for. -- Adam function checkClient() { var frame1 =3D chkPushletLocation(); var errorString =3D "Screen "+subject; if(frame1=3D=3Dfalse){ errorString =3D errorString+" Pushlet has failed. "; pushletFrame.pushReceiverFrame.location.href =3D pushletFrame.pushletURL; } //Send info to servlet to send email to the administrator. setTimeout('checkClient();', 5000); } function chkPushletLocation() { if (pushletFrame.pushletIsLive) { =20 window.pushletFrame.framesetController.document.body.style.backgroundColo= r=3D" white"; return true; } else { // sets background colour of frameset controller to red so = you know it's trying to resuscitate the pushlet =20 window.pushletFrame.framesetController.document.body.style.backgroundColo= r=3D" red"; return false; } } -----Original Message----- From: pu...@ya... [mailto:pu...@ya...] Sent: Tuesday, March 04, 2003 9:05 AM To: pu...@ya... Subject: [pushlet] Digest Number 192 To Post a message, send it to: pu...@eG... To Unsubscribe, send a blank message to: pus...@eG... ------------------------------------------------------------------------ There are 5 messages in this issue. Topics in this digest: 1. Stopping the server From: "walruszz <fi...@ti...>" <fi...@ti...> 2. RE: Stopping the server From: "Briggs, Ben" <ben...@ed...> 3. RE: Stopping the server From: "Briggs, Ben" <ben...@ed...> 4. Re: Stopping the server From: "walruszz <fi...@ti...>" <fi...@ti...> 5. RE: Re: Stopping the server From: "Briggs, Ben" <ben...@ed...> ________________________________________________________________________ ________________________________________________________________________ Message: 1 Date: Tue, 04 Mar 2003 10:50:50 -0000 From: "walruszz <fi...@ti...>" <fi...@ti...> Subject: Stopping the server Hi! I'm using this framework to develop an istant messaging environment,=20 and it's working pretty fine. I use apache/tomcat 4.0.1. Here's the little problem: when I want to stop and republish the=20 server, it waits until all the client browser pages are closed, or=20 moved to other locations. How can I stop the server if someone (possibly far) has the page=20 open? Is there a way to force it? Thank you very much! Filippo Mescoli ________________________________________________________________________ ________________________________________________________________________ Message: 2 Date: Tue, 4 Mar 2003 11:16:45 -0000 From: "Briggs, Ben" <ben...@ed...> Subject: RE: Stopping the server Buon giorno Filippo, =20 I haven't noticed this problem; perhaps WebLogic has different behaviour from Tomcat in this regard. When I stop the server to republish it, it automatically kills the pushlet servlets and the connections to the = browser close. =20 Perhaps someone will suggest a way to close connections that already = exists. If not, you might change things a little, and see if it's good enough to contribute to Just's project. Here's a suggestion for a change: =20 To force it to close, you could cause the PushletSubscriber to break out = of its infinite loop. So instead of it doing "while(true)", it could do a "while(finished=3D=3Dfalse)" and if it ever receives an event with the = subject "killAllSubscribers" or something, then it would set finished=3Dtrue. = Just an idea. =20 Alternatively, you could do it on the client side, and when the clients received the "killAllSubscribers" event, then they could disconnect by changing the location.href to a benign location. However, I wouldn't recommend this route since JavaScript is so browser-dependent. =20 It's worth noting that some colleagues and I have written some = JavaScript that ties in with the Pushlet framework and detects when the connection = has been lost between the client and the server (due to the server being restarted, or a cable coming unplugged or anything). It then = automatically reopens the connection to the servlet as soon as the HTTP connection can = be reestablished. I'd be happy to share this with the project. =20 Cheers, Ben =20 =20 -----Original Message----- From: walruszz <fi...@ti...> [mailto:fi...@ti...] Sent: 04 March 2003 10:51 To: pu...@ya... Subject: [pushlet] Stopping the server Hi! I'm using this framework to develop an istant messaging environment,=20 and it's working pretty fine. I use apache/tomcat 4.0.1. Here's the little problem: when I want to stop and republish the=20 server, it waits until all the client browser pages are closed, or=20 moved to other locations. How can I stop the server if someone (possibly far) has the page=20 open? Is there a way to force it? Thank you very much! Filippo Mescoli ________________________________________________________________________ ________________________________________________________________________ Message: 3 Date: Tue, 4 Mar 2003 15:02:56 -0000 From: "Briggs, Ben" <ben...@ed...> Subject: RE: Stopping the server Greg, It's not been written for cross-browser compatibility yet, but it works = in IE6 (on Weblogic 7). The primary modification is the <b>ONLOAD=3D"pushletStopped()"</b> added = to the frame loading the pushlet servlet. If the connection dies, the frame stops loading and in a sense receives the end of the page. This triggers = the browser's onLoad event handler, and then some javascript -- in this case pushletStopped() -- can handle what to do if it's lost the connection. The "frameset controller" frame polls the pushlet frame to see if its = still alive. Mine does this every 5 seconds, but it doesn't have to be this = often. I've changed the architecture a bit and would need to go back to the original pushlet framework to see what needs doing to make these ideas = fit in with the Pushlet project. But maybe these code snippets will be = enough for you to understand the basic premise. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D in pushlet.html: <SCRIPT LANGUAGE=3D"JavaScript"> self.document.writeln('<FRAMESET BORDER=3D1 ROWS=3D"30,*">'); self.document.writeln('<FRAME SRC=3D"frameset-controller.html" NAME=3D"framesetController" BORDER=3D0 SCROLLING=3Dno>'); self.document.writeln('<FRAME = SRC=3D"/PubDisp/servlet/pushlet?subject=3D' + subject + '&bgColor=3D' + bgColor + '" NAME=3D"pushReceiverFrame" = BORDER=3D0 SCROLLING=3Dno ONLOAD=3D"pushletStopped()">'); self.document.writeln('</FRAMESET>'); statusFrameReady=3Dtrue; </SCRIPT> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D in pushlet.html: function pushletStopped() { if (pushletIsLive =3D=3D true) { // inform the admin if the pushlet = just died // call a servlet that sends an email to the administrator } pushletIsLive =3D false; } setTimeout('parent.checkClient();', 5000); function restartPushlet() { // alert('restarting pushlet'); pushReceiverFrame.src =3D "/PubDisp/servlet/pushlet?subject=3D"+subject+"&bgColor=3D"+bgColor; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D in client.js: function checkClient() { var frame1 =3D chkPushletLocation(); var errorString =3D "Screen "+subject; if(frame1=3D=3Dfalse){ errorString =3D errorString+" Pushlet has failed. "; pushletFrame.pushReceiverFrame.location.href =3D pushletFrame.pushletURL; } //Send info to servlet to send email to the administrator. setTimeout('checkClient();', 5000); } function chkPushletLocation() { if (pushletFrame.pushletIsLive) { =20 window.pushletFrame.framesetController.document.body.style.backgroundColo= r=3D" white"; return true; } else { // sets background colour of frameset controller to red so = you know it's trying to resuscitate the pushlet =20 window.pushletFrame.framesetController.document.body.style.backgroundColo= r=3D" red"; return false; } } Cheers, Ben =20 -----Original Message----- From: Greg Bohmann [mailto:gcb...@ya...] Sent: 04 March 2003 14:38 To: Briggs, Ben Subject: RE: [pushlet] Stopping the server Ben - You mentioned that you and some other individuals have already developed JavaScript code that can reestablish a lost HTTP connection.=20 I am interested in seeing the code and am sure others in the pushlet community are as well. The increased availability gained through this modification would benefit all applications utilizing the pushlet framework whether in a single server or clustered setting. Thanks, Greg --- "Briggs, Ben" <ben...@ed...> wrote: > Buon giorno Filippo, > =20 > I haven't noticed this problem; perhaps WebLogic has different > behaviour > from Tomcat in this regard. When I stop the server to republish it, > it > automatically kills the pushlet servlets and the connections to the > browser > close. > =20 > Perhaps someone will suggest a way to close connections that already > exists. > If not, you might change things a little, and see if it's good enough > to > contribute to Just's project. Here's a suggestion for a change: > =20 > To force it to close, you could cause the PushletSubscriber to break > out of > its infinite loop. So instead of it doing "while(true)", it could do > a > "while(finished=3D=3Dfalse)" and if it ever receives an event with the > subject > "killAllSubscribers" or something, then it would set finished=3Dtrue. > Just an > idea. > =20 > Alternatively, you could do it on the client side, and when the > clients > received the "killAllSubscribers" event, then they could disconnect > by > changing the location.href to a benign location. However, I wouldn't > recommend this route since JavaScript is so browser-dependent. > =20 > It's worth noting that some colleagues and I have written some > JavaScript > that ties in with the Pushlet framework and detects when the > connection has > been lost between the client and the server (due to the server being > restarted, or a cable coming unplugged or anything). It then > automatically > reopens the connection to the servlet as soon as the HTTP connection > can be > reestablished. I'd be happy to share this with the project. > =20 > Cheers, > Ben ________________________________________________________________________ ________________________________________________________________________ Message: 4 Date: Tue, 04 Mar 2003 15:38:21 -0000 From: "walruszz <fi...@ti...>" <fi...@ti...> Subject: Re: Stopping the server --- In pu...@ya..., "Briggs, Ben" <ben.briggs@e...> wrote: > Here's a suggestion for a change: > =20 > To force it to close, you could cause the PushletSubscriber to=20 break out of > its infinite loop. So instead of it doing "while(true)", it could=20 do a > "while(finished=3D=3Dfalse)" and if it ever receives an event with the = subject > "killAllSubscribers" or something, then it would set finished=3Dtrue.=20 Just an > idea. Thank you very much Ben, so I have to send a message to the servlet, prior to stop the server? I'll try this one first. Then I will look for an automatic mechanism to force it to step out=20 from the loop when I try to stop the server. Bye! Filippo Mescoli ________________________________________________________________________ ________________________________________________________________________ Message: 5 Date: Tue, 4 Mar 2003 15:57:31 -0000 From: "Briggs, Ben" <ben...@ed...> Subject: RE: Re: Stopping the server Filippo, =20 You might be able to write an exit servlet that runs when you deactivate = the web application. You can then configure this in your web.xml file to = listen for this event. =20 I'm not sure if this would work because it might be a case of the = chicken and the egg. If this event isn't fired until after the pushlets are = closed, then you can't expect these methods to cause the pushlets to close. You could then make a request to this servlet, such as http://localhost:8080/pushlet/ExitServlet <http://localhost:8080/pushlet/ExitServlet> . But if you don't require authentication, then anyone can kill all your pushlets. =20 =20 Something like this =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D in ExitServlet.java =20 package ###path###; =20 import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter; =20 import ###path###.Publisher; public class ExitServlet extends HttpServlet implements ServletContextListener { static final private String CONTENT_TYPE =3D "text/html"; //Initialize global variables public void init() throws ServletException { } =20 public void contextInitialized(ServletContextEvent e) { =20 System.out.println("#####################################################= ### #"); System.out.println("Pushlet application loading..."); =20 System.out.println("#####################################################= ### #"); } =20 public void contextDestroyed(ServletContextEvent e) { =20 System.out.println("#####################################################= ### #"); System.out.println("Telling all pushlets to close..."); shutDownPushlets(); =20 System.out.println("#####################################################= ### #"); System.out.println("Pushlet application shutting down..."); =20 System.out.println("#####################################################= ### #"); } =20 private void shutDownPushlets() { Publisher.getInstance().publish(/* event with subject "killAllSubscribers" */); } =20 public void doGet(HttpServletRequest request, HttpServletResponse = response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out =3D response.getWriter(); out.println("Shutting down pushlets"); shutDownPushlets(); } =20 } =20 =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 in web.xml =20 <listener> <listener-class>###path###.ExitServlet</listener-class> </listener> =20 Cheers, Ben =20 -----Original Message----- From: walruszz <fi...@ti...> [mailto:fi...@ti...] Sent: 04 March 2003 15:38 To: pu...@ya... Subject: [pushlet] Re: Stopping the server --- In pu...@ya..., "Briggs, Ben" <ben.briggs@e...> wrote: > Here's a suggestion for a change: > =20 > To force it to close, you could cause the PushletSubscriber to=20 break out of > its infinite loop. So instead of it doing "while(true)", it could=20 do a > "while(finished=3D=3Dfalse)" and if it ever receives an event with the = subject > "killAllSubscribers" or something, then it would set finished=3Dtrue.=20 Just an > idea. Thank you very much Ben, so I have to send a message to the servlet, prior to stop the server? I'll try this one first. Then I will look for an automatic mechanism to force it to step out=20 from the loop when I try to stop the server. Bye! Filippo Mescoli [Non-text portions of this message have been removed] ________________________________________________________________________ ________________________________________________________________________ |