|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH} Adding Grizzly Comet 'native' support to DWRHi,
over the last couple of months I got a lot of requests from users of Grizzly Comet[1] to support dwr (or have dwr have support :-)). I took a look at the code and came with the attached simple patch. Mainly, I've just added a new class called GrizzlyContinuationSleeper, "hacked" the Continuation classes to enable Grizzly when DWR is deployed in GlassFish or Grizzly Standalone Web Server. The classes I've touched are: + PollHandler + Continuation + Added GrizzlyContinuationSleeper + OutputAlarm (guard against null) PollHandler + Conyinuation looks a little bit hacky (might need to replace the isJetty/isGrizzly with a better design) but the idea is there. Let me know what you think and if you are interested to add support to the current dwr release. What needs to be done is if accepted is: + apply the patch. + add the following jar file http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar under the dwr/jar folder, and when packaging the war file, add it under WEB-INF/lib (and for the dwr/pom.xml file add) > <dependency> > <groupId>com.sun.grizzly</groupId> > <artifactId>continuation</artifactId> > <version>1.6-SNAPSHOT</version> > <scope>compile</scope> > </dependency> The later jar file contains the Grizzly's classes that detect with Grizzly version is installed and will make DWR works with all GlassFish version (9.1, 9.1 ur1, Sailfin, OpenESB). I will add those classes to GlassFish v3, but previous version are 'closed' for commit so I can't add them. If you think this is a bad idea, we can always document it so people knows how to enable dwr in GlassFish. Thanks! --Jeanfrancois [1] http://weblogs.java.net/blog/jfarcand/archive/2006/07/the_grizzly_com.html ? java/org/directwebremoting/dwrp/GrizzlyContinuationSleeper.java Index: java/org/directwebremoting/dwrp/OutputAlarm.java =================================================================== RCS file: /cvs/dwr/java/org/directwebremoting/dwrp/OutputAlarm.java,v retrieving revision 1.6 diff -u -r1.6 OutputAlarm.java --- java/org/directwebremoting/dwrp/OutputAlarm.java 30 Oct 2007 17:07:24 -0000 1.6 +++ java/org/directwebremoting/dwrp/OutputAlarm.java 22 Nov 2007 03:32:20 -0000 @@ -71,7 +71,9 @@ public void cancel() { scriptSession.removeScriptConduit(conduit); - future.cancel(false); + if (future != null){ + future.cancel(false); + } super.cancel(); } Index: java/org/directwebremoting/dwrp/PollHandler.java =================================================================== RCS file: /cvs/dwr/java/org/directwebremoting/dwrp/PollHandler.java,v retrieving revision 1.41 diff -u -r1.41 PollHandler.java --- java/org/directwebremoting/dwrp/PollHandler.java 30 Oct 2007 17:07:24 -0000 1.41 +++ java/org/directwebremoting/dwrp/PollHandler.java 22 Nov 2007 03:32:20 -0000 @@ -138,6 +138,10 @@ { sleeper = new JettyContinuationSleeper(request); } + else if (Continuation.isGrizzly()) + { + sleeper = new GrizzlyContinuationSleeper(request); + } else { sleeper = new ThreadWaitSleeper(); Index: java/org/directwebremoting/util/Continuation.java =================================================================== RCS file: /cvs/dwr/java/org/directwebremoting/util/Continuation.java,v retrieving revision 1.6 diff -u -r1.6 Continuation.java --- java/org/directwebremoting/util/Continuation.java 23 Jun 2007 19:28:28 -0000 1.6 +++ java/org/directwebremoting/util/Continuation.java 22 Nov 2007 03:32:20 -0000 @@ -36,6 +36,14 @@ public Continuation(HttpServletRequest request) { proxy = request.getAttribute(ATTRIBUTE_JETTY_CONTINUATION); + if (proxy == null && isGrizzly()){ + try{ + Class<?> gContinuation = LocalUtil.classForName("com.sun.grizzly.Continuation"); + Method gMethod = gContinuation.getMethod("getContinuation"); + proxy = gMethod.invoke((Object[])null,(Object[])null); + } catch (Throwable t){ + } + } } /** @@ -203,7 +211,12 @@ /** * Are we using Jetty at all? */ - protected static boolean isJetty; + protected static boolean isJetty = false; + + /** + * Are we using Grizzly at all? + */ + protected static boolean isGrizzly = false; /** * Can we use Jetty? @@ -212,25 +225,42 @@ { try { - continuationClass = LocalUtil.classForName("org.mortbay.util.ajax.Continuation"); + try{ + continuationClass = LocalUtil.classForName("org.mortbay.util.ajax.Continuation"); + isJetty = true; + } + catch (Exception ex) + { + Class<?> gContinuation = LocalUtil.classForName("com.sun.grizzly.Continuation"); + Method gMethod = gContinuation.getMethod("getContinuation"); + continuationClass = gMethod.invoke(gMethod).getClass(); + isGrizzly = true; + } suspendMethod = continuationClass.getMethod("suspend", Long.TYPE); resumeMethod = continuationClass.getMethod("resume"); getObject = continuationClass.getMethod("getObject"); setObject = continuationClass.getMethod("setObject", Object.class); - isJetty = true; } catch (Exception ex) { isJetty = false; - log.debug("No Jetty ContuniationSupport class, using standard Servlet API"); + log.debug("No Jetty or Grizzly Continuation class, using standard Servlet API"); } } /** - * @return True if we have detected Continuation classes + * @return True if we have detected Jetty classes */ public static boolean isJetty() { return isJetty; } + + /** + * @return True if we have detected Grizzly classes + */ + public static boolean isGrizzly() + { + return isGrizzly; + } } /* * Copyright 2005 Joe Walker * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.directwebremoting.dwrp; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.directwebremoting.util.Continuation; /** * A Sleeper that works with Grizzly Continuations * @author Jeanfrancois Arcand [jeanfrancois dot arcand at sun dot com] */ public class GrizzlyContinuationSleeper implements Sleeper { /** * @param request The request into which we store this as an attribute */ public GrizzlyContinuationSleeper(HttpServletRequest request) { continuation = new Continuation(request); } /* (non-Javadoc) * @see org.directwebremoting.dwrp.Sleeper#goToSleep(java.lang.Runnable) */ public void goToSleep(Runnable awakening) { this.onAwakening = awakening; try { continuation.suspend(-1); } catch (Exception ex) { Continuation.rethrowIfContinuation(ex); log.warn("Exception", ex); proxy = new ThreadWaitSleeper(); proxy.goToSleep(onAwakening); } } /* (non-Javadoc) * @see org.directwebremoting.dwrp.PollHandler.Sleeper#wakeUp() */ public void wakeUp() { if (proxy != null) { proxy.wakeUp(); } else { synchronized (continuation) { if (!resumed) { try { /* * Flush bytes if any first as before resuming the * as Grizzly Comet isn't allowing writes once the * continuation is resumed. * * This can be achieved * by using Grizzly CometHandler, which isn't exposed * with DWR. */ onAwakening.run(); continuation.resume(); } catch (Exception ex) { log.error("Broken reflection", ex); } resumed = true; } } } } /** * If continuations fail, we proxy to a Thread Wait version */ protected ThreadWaitSleeper proxy = null; /** * What we do when we are woken up */ protected Runnable onAwakening; /** * The continuation object */ protected final Continuation continuation; /** * Has the continuation been restarted already? */ protected boolean resumed = false; /** * We remember the notify conduit so we can reuse it */ public static final String ATTRIBUTE_JETTY_CONDUIT = "org.directwebremoting.dwrp.notifyConduit"; private static final Log log = LogFactory.getLog(GrizzlyContinuationSleeper.class); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWRJeanfrancois, Fantastic - it looks good and applies cleanly. Thanks. So here's the bad news - I'm trying to be a good citizen and ensure that DWR is covered by a CLA for all the code. That gives us a couple of options: - You get Sun to sign a CCLA saying that I'm allowed to use the IPR in the patch. - You tell me there isn't any IPR in the patch. I have to say, since the patch is so similar to the Jetty code, I think it's likely that the second option is a) honest and b) the fastest. What do you think? Joe. On Nov 22, 2007 3:37 AM, Jeanfrancois Arcand <Jeanfrancois.Arcand@...> wrote: Hi, |
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWROn Nov 22, 2007 3:37 AM, Jeanfrancois Arcand <Jeanfrancois.Arcand@...> wrote: http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar I got a 404 for this. Did I look too early? Joe. |
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWRHi Joe,
Joe Walker wrote: > > Jeanfrancois, > > Fantastic - it looks good and applies cleanly. Thanks. > So here's the bad news - I'm trying to be a good citizen and ensure that > DWR is covered by a CLA for all the code. That gives us a couple of > options: > - You get Sun to sign a CCLA saying that I'm allowed to use the IPR in > the patch. > - You tell me there isn't any IPR in the patch. > > I have to say, since the patch is so similar to the Jetty code, I think > it's likely that the second option is a) honest and b) the fastest. > What do you think? Yes I agree. This is almost the same code as Jetty except Grizzly isn't throwing an exception and you need to push bytes before resuming (Jetty still allow you to write after resuming, Grizzly isn't). Thanks!! -- Jeanfrancois > > Joe. > > > On Nov 22, 2007 3:37 AM, Jeanfrancois Arcand > <Jeanfrancois.Arcand@... <mailto:Jeanfrancois.Arcand@...>> wrote: > > Hi, > > over the last couple of months I got a lot of requests from users of > Grizzly Comet[1] to support dwr (or have dwr have support :-)). I took a > look at the code and came with the attached simple patch. Mainly, I've > just added a new class called GrizzlyContinuationSleeper, "hacked" the > Continuation classes to enable Grizzly when DWR is deployed in GlassFish > or Grizzly Standalone Web Server. > > The classes I've touched are: > > + PollHandler > + Continuation > + Added GrizzlyContinuationSleeper > + OutputAlarm (guard against null) > > PollHandler + Conyinuation looks a little bit hacky (might need to > replace the isJetty/isGrizzly with a better design) but the idea is > there. Let me know what you think and if you are interested to add > support to the current dwr release. > > What needs to be done is if accepted is: > > + apply the patch. > + add the following jar file > > http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar > <http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar> > > under the dwr/jar folder, and when packaging the war file, add it under > WEB-INF/lib > > (and for the dwr/pom.xml file add) > > > <dependency> > > <groupId>com.sun.grizzly </groupId> > > <artifactId>continuation</artifactId> > > <version>1.6-SNAPSHOT</version> > > <scope>compile</scope> > > </dependency> > > The later jar file contains the Grizzly's classes that detect with > Grizzly version is installed and will make DWR works with all GlassFish > version (9.1, 9.1 ur1, Sailfin, OpenESB). I will add those classes to > GlassFish v3, but previous version are 'closed' for commit so I can't > add them. If you think this is a bad idea, we can always document it so > people knows how to enable dwr in GlassFish. > > Thanks! > > --Jeanfrancois > > [1] > http://weblogs.java.net/blog/jfarcand/archive/2006/07/the_grizzly_com.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > <mailto:dev-unsubscribe@...> > For additional commands, e-mail: dev-help@... > <mailto:dev-help@...> > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWRJoe Walker wrote: > > > On Nov 22, 2007 3:37 AM, Jeanfrancois Arcand > <Jeanfrancois.Arcand@... <mailto:Jeanfrancois.Arcand@...>> wrote: > > http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar > <http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar> Hum looks like the repo in not in sync (hopefully that's because Thanksgiving in the US)...I've temporary placed the jar here: http://weblogs.java.net/blog/jfarcand/archive/continuation-1.6-SNAPSHOT.jar Hopefully that one doesn't gives 404 :-). BTW I forgot to said I've tested with the examples that comes with the dwr.war. Also, to try in glassfish you need to do: % install glassfish % vi ${glassfish.home}/domains/domain1/config/domain.xml % Search for: <property name="proxiedProtocols" ...> replace it with <property name="cometSupport" value="true"/> Restart and deploy :-) Thanks! -- Jeanfrancois > > > I got a 404 for this. Did I look too early? > > Joe. > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWRDWR needs to be configured with a special load monitor when we are using a fancy container. e.g. from ContainerUtil: if (servletConfig.getServletContext().getServerInfo().startsWith("jetty-6")) { container.addParameter(ServerLoadMonitor.class.getName(), ThreadDroppingServerLoadMonitor.class.getName()); } else { container.addParameter(ServerLoadMonitor.class.getName (), DefaultServerLoadMonitor.class.getName()); } What's the best way of detecting Grizzy? Thanks, Joe. On Nov 22, 2007 5:30 PM, Jeanfrancois Arcand <Jeanfrancois.Arcand@...> wrote:
|
|
|
Re: [PATCH} Adding Grizzly Comet 'native' support to DWRSalut,
Joe Walker wrote: > > DWR needs to be configured with a special load monitor when we are using > a fancy container. e.g. from ContainerUtil: > > if > (servletConfig.getServletContext().getServerInfo().startsWith("jetty-6")) > { > container.addParameter(ServerLoadMonitor.class.getName(), > ThreadDroppingServerLoadMonitor.class.getName()); > } > else > { > container.addParameter(ServerLoadMonitor.class.getName (), > DefaultServerLoadMonitor.class.getName()); > } > > What's the best way of detecting Grizzy? The getServerInfo() returns for GlassFish|SailFin|OpenEsb: Sun Java System Application Server <<version>> (Hopefully Sun's marketing doesn't come with another ugly name ;-)) For Grizzly standalone, it only return 'grizzly'. Thanks! -- Jeanfrancois > Thanks, > > Joe. > > On Nov 22, 2007 5:30 PM, Jeanfrancois Arcand < > Jeanfrancois.Arcand@... <mailto:Jeanfrancois.Arcand@...>> wrote: > > > > Joe Walker wrote: > > > > > > On Nov 22, 2007 3:37 AM, Jeanfrancois Arcand > > <Jeanfrancois.Arcand@... <mailto:Jeanfrancois.Arcand@...> > <mailto: Jeanfrancois.Arcand@... > <mailto:Jeanfrancois.Arcand@...>>> wrote: > > > > > http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar > <http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar> > > > <http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar > <http://download.java.net/maven/2/com/sun/grizzly/continuation/1.6-SNAPSHOT/continuation-1.6-SNAPSHOT.jar>> > > Hum looks like the repo in not in sync (hopefully that's because > Thanksgiving in the US)...I've temporary placed the jar here: > > http://weblogs.java.net/blog/jfarcand/archive/continuation-1.6-SNAPSHOT.jar > > Hopefully that one doesn't gives 404 :-). > > BTW I forgot to said I've tested with the examples that comes with the > dwr.war . Also, to try in glassfish you need to do: > > % install glassfish > % vi ${glassfish.home}/domains/domain1/config/domain.xml > % Search for: > > <property name="proxiedProtocols" ...> > > replace it with > > <property name="cometSupport" value="true"/> > > Restart and deploy :-) > > Thanks! > > -- Jeanfrancois > > > > > > > > > > I got a 404 for this. Did I look too early? > > > > Joe. > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@... > <mailto:dev-unsubscribe@...> > For additional commands, e-mail: dev-help@... > <mailto:dev-help@...> > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@... For additional commands, e-mail: dev-help@... |
| Free Forum Powered by Nabble | Forum Help |