Skip to main content

Getting started with Comet and GlassFish v2

Posted by jfarcand on July 2, 2008 at 9:39 AM PDT

This blog has moved here

Related Topics >>

Comments

Hi all, I am still struggling with getting my comet-based servlet to work. Any help would be much appreciated I guess what would be helpful for me is a simple step-by-step procedure. So far, what I have found is scattered and fragmented bits and pieces of information, critical details appear to be glossed over. I suppose I can boil down my request to the following set of questions: 1) APP SERVER: What do I need to get comet-based servlet working? e.g. glassfish V2UR2 with comet support enabled. 2) API: What compatible comet api should I compile the source code with? 3) API DOWNLOAD: Where do I download the API from? 4) CLASSPATH: Do I copy the API to ${as.home}/lib for example 5) TEST: How do I positively verify that comet support is indeed enabled? 6)Last question: Does the app server come bundled with the comet api

Salut Jeanfrancois, Thank you very much for being so responsive. Your answers to step 2 and 6 got me unstuck. I appreciate your help. 2) API: What compatible comet api should I compile the source code against? If you plan to deploy against v2ur2, you need to build against the API that ship with v2. Hence, in your classpath, you need to add: ${glassfish.home}/lib/appserv-rt.jar. 6)Last question: Does the app server come bundled with the comet api yes, in v2: com.sun.enterprise.web.connector.grizzly.comet.* in v3 and grizzly standalone: com.sun.grizzly.comet Keep up the great work! Regards, Hiram A+

Hello Jean-Francois, Let me start by thanking you for all your good work on the Grizzly/comet front. Kudos! I wrote a simple comet app based on the tutorial found at: http://docs.sun.com/app/docs/doc/820-4496/ggrgt?a=view. I get the following exception when a request is received by my servlet: java.lang.IllegalStateException: Make sure you have enabled Comet or make sure the Thread invoking that method is the same a the request Thread. at com.sun.grizzly.comet.CometContext.addCometHandler(CometContext.java:263) at com.sun.grizzly.comet.CometContext.addCometHandler(CometContext.java:311) .... I have already combed through your blogs. I have tried all the suggestions that I have come across. So far, i haven't had any success. I noticed a peculiar behavior with my glassfish instance; whether <property name="cometSupport" value="true"/> is added to domain.xml or not seems to make not a bit of a difference. I have made sure to bounce the server every time i make a change to domain.xml to ensure that the changes will be recognized. I have tried several experiments with the "cometSupport" property added and removed from domain.xml. I ave tried similar experiments with <property name="proxiedProtocols" value="ws/tcp"/> I have even enabled the flag through the command line using "asadmin set server.http-service.http-listener.http-listener-1.property.cometSupport=true" Relevant environment information: Sun Java System Application Server 9.1 (build b58g-fcs) (GlassfishV2) excerpt from domain.xml: .... <http-listener acceptor-threads="1" address="0.0.0.0" blocking-enabled="false" default-virtual-server="server" enabled="true" family="inet" id="http-listener-1" port="8080" security-enabled="false" server-name="" xpowered-by="true"> <property name="proxiedProtocols" value="ws/tcp"/> <property name="cometSupport" value="true"/> </http-listener> .... excerpt from app server output console: .... WEB0302: Starting Sun-Java-System/Application-Server. Enabling Grizzly ARP Comet support. WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 8080 .... excerpt from web.xml ... <servlet> <servlet-name>RefreshServlet</servlet-name> <servlet-class>package.RefreshServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> ... The following bit of code registers the handler and is invoked only once, upon receipt of first request. private void registerHandler(HttpServletResponse response) throws IllegalStateException{ if (oneShot) { RefreshHandler handler = new RefreshHandler(); handler.attach(response); CometEngine engine = CometEngine.getEngine(); CometContext context = engine.getCometContext(contextPath); try{ context.addCometHandler(handler); oneShot = false; }catch(IllegalStateException ex){ logger.error(ex.getMessage(), ex); throw ex; } } } Two questions: 1) Any suggestions? 2) How can I positively tell that comet support is indeed enabled?

Salut, can you send your questions to users@grizzly.dev.java.net? This way you will get a more faster answer :-) Thanks!

Hi Jean, I have been trying Comet several times in my sailfin environment... what I am trying is to push messages (received from a SIP remote entity) from the server to the http client. I am following the steps of your "counter" example... but somehow, my asynchronous events are not notified back to the http client... I see in my logs that the onEvent methods is called... but I don't see the answer in the client... TO be more clear I have something like: CLIENT SERVER SIP ENTITY -------- POST --------> (add handler to context) --------- PUBLISH -----> ...... ..... <--------- OK --------------- (notify context) onEvent is called <------------------------- (this steps seems to be missing) At least i don't see the answer in the client. Any idea what can be ?

Salut, we don't officially have a load balancer implemented on top of Grizzly, but the users list contains a lot of users that have build customized lb. Just post your questions to users@grizzly.dev.java.net. I'm sure someone can share its code :-). Thanks!

Can grizzly load balance?