Author: jfrederic.clere(a)jboss.com
Date: 2009-11-25 05:14:32 -0500 (Wed, 25 Nov 2009)
New Revision: 1290
Added:
sandbox/webapps/src/CometServletTest1.java
Modified:
sandbox/webapps/build.xml
Log:
Add a comet test application...
Modified: sandbox/webapps/build.xml
===================================================================
--- sandbox/webapps/build.xml 2009-11-25 01:50:35 UTC (rev 1289)
+++ sandbox/webapps/build.xml 2009-11-25 10:14:32 UTC (rev 1290)
@@ -5,16 +5,18 @@
<!--
<javac srcdir="src"
classpath="/home/jfclere/tc6.0.x/output/build/lib/servlet-api.jar"
destdir="classes" />
-->
- <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/apache-tomcat-5.5.17/common/lib/servlet-api.jar"
destdir="classes" />
+ <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/apache-tomcat-5.5.17/common/lib/servlet-api.jar"
destdir="classes" excludes="Comet*" />
- <jar destfile="./lib/myservlets.jar" basedir="./classes"/>
+ <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/jbossweb_trunk/output/jars/jbossweb.jar:/home/jfclere/jbossweb_trunk/output/jars/servlet-api.jar"
destdir="classes" includes="Comet*" />
+ <jar destfile="./lib/myservlets.jar" basedir="./classes"
excludes="Comet*" />
+
<war destfile="myapp.war" webxml="myapp.xml">
<fileset dir="html" />
<lib dir="./lib">
<include name="**/myservlets.jar"/>
</lib>
- <classes dir="./classes" />
+ <classes dir="./classes" excludes="Comet*" />
<metainf dir="./metainf">
<include name="**/context.xml"/>
</metainf>
@@ -41,7 +43,7 @@
<lib dir="./lib">
<include name="**/myservlets.jar"/>
</lib>
- <classes dir="./classes" />
+ <classes dir="./classes" excludes="Comet*" />
<metainf dir="./metainf">
<include name="**/context.xml"/>
</metainf>
@@ -55,5 +57,9 @@
<ear destfile="sslapp.ear"
appxml="./metadata/application.xml">
<fileset dir="." includes="*.war"/>
</ear>
+
+ <war destfile="comet.war" needxmlfile="false" >
+ <classes dir="./classes" includes="Comet*" />
+ </war>
</target>
</project>
Added: sandbox/webapps/src/CometServletTest1.java
===================================================================
--- sandbox/webapps/src/CometServletTest1.java (rev 0)
+++ sandbox/webapps/src/CometServletTest1.java 2009-11-25 10:14:32 UTC (rev 1290)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+
+// package org.jboss.web.comet;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.servlet.annotation.WebServlet;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+
+import org.jboss.servlet.http.HttpEvent;
+import org.jboss.servlet.http.HttpEventServlet;
+
+/* Copied from org.jboss.web.comet.CometServletTest1 (by Remy) */
+@WebServlet("/CometServletTest1")
+public class CometServletTest1 extends HttpServlet implements HttpEventServlet {
+
+ int count = 0;
+
+ public void event(HttpEvent event) throws IOException, ServletException {
+ System.out.println("[" +
event.getHttpServletRequest().getSession(true).getId() + "] " +
event.getType());
+ switch (event.getType()) {
+ case BEGIN:
+ event.setTimeout(1000);
+ break;
+ case END:
+ break;
+ case ERROR:
+ event.close();
+ break;
+ case EVENT:
+ ServletOutputStream os = event.getHttpServletResponse().getOutputStream();
+ // Using while (true): Not checking if the connection is available to writing
immediately
+ // will cause the write to be performed in blocking mode.
+ // boolean b = true;
+ // while (b) {
+ while (event.isWriteReady()) {
+ if (count % 100 == 0) {
+ os.println((count++) + " ");
+ } else {
+ os.print((count++) + " ");
+ }
+ }
+ // }
+ //if (event.ready())
+ // os.flush();
+ break;
+ case READ:
+ ServletInputStream is = event.getHttpServletRequest().getInputStream();
+ // Using while (true): Not checking if input is available will trigger a
blocking
+ // read. No other event should be triggered (the current READ event will be
in progress
+ // until the read timeouts, which will trigger an ERROR event due to an
IOException).
+ // while (true) {
+ while (is.available() > 0) {
+ int c = is.read();
+ count++;
+ }
+ // }
+ break;
+ case TIMEOUT:
+ // This will cause a generic event to be sent to the servlet every time the
connection is idle for
+ // a while.
+ event.resume();
+ break;
+ case WRITE:
+ break;
+ }
+ }
+
+}