Skip to content

Commit

Permalink
Fix for #185 Add support for the Netty Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Feb 15, 2012
1 parent ddf817b commit 998046c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2012 Jeanfrancois Arcand
*
* 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.atmosphere.container;

import org.apache.catalina.CometEvent;
import org.atmosphere.cpr.ApplicationConfig;
import org.atmosphere.cpr.AsynchronousProcessor;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereResourceImpl;
import org.atmosphere.cpr.AtmosphereServlet;
import org.jboss.servlet.http.HttpEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
* Netty's Framework {@link org.atmosphere.cpr.CometSupport}
*/
public class NettyCometSupport extends AsynchronousProcessor {

public final static String SUSPEND = NettyCometSupport.class.getName() + ".suspend";
public final static String RESUME = NettyCometSupport.class.getName() + ".resume";

private static final Logger logger = LoggerFactory.getLogger(BlockingIOCometSupport.class);

public NettyCometSupport(AtmosphereConfig config) {
super(config);
}

/**
* {@inheritDoc}
*/
public AtmosphereServlet.Action service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {

AtmosphereServlet.Action action = null;
action = suspended(req, res);
if (action.type == AtmosphereServlet.Action.TYPE.SUSPEND) {
logger.debug("Suspending response: {}", res);
req.setAttribute(SUSPEND, new Boolean(true));
} else if (action.type == AtmosphereServlet.Action.TYPE.RESUME) {
logger.debug("Resuming response: {}", res);

AtmosphereServlet.Action nextAction = resumed(req, res);
if (nextAction.type == AtmosphereServlet.Action.TYPE.SUSPEND) {
logger.debug("Suspending after resuming response: {}", res);
req.setAttribute(SUSPEND, new Boolean(true));
}
}

return action;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.atmosphere.container.Jetty7CometSupport;
import org.atmosphere.container.JettyCometSupport;
import org.atmosphere.container.JettyCometSupportWithWebSocket;
import org.atmosphere.container.NettyCometSupport;
import org.atmosphere.container.Servlet30CometSupport;
import org.atmosphere.container.Servlet30CometSupportWithWebSocket;
import org.atmosphere.container.Tomcat7CometSupport;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class DefaultCometSupportResolver implements CometSupportResolver {
public final static String WEBLOGIC = "weblogic.servlet.http.FutureResponseModel";
public final static String JBOSSWEB = "org.apache.catalina.connector.HttpEventImpl";
public final static String GRIZZLY_WEBSOCKET = "com.sun.grizzly.websockets.WebSocketEngine";
public final static String NETTY = "org.jboss.netty.channel.Channel";

private final AtmosphereConfig config;

Expand Down Expand Up @@ -110,6 +112,9 @@ protected boolean testClassExists(final String testClass) {
public List<Class<? extends CometSupport>> detectContainersPresent() {
return new LinkedList<Class<? extends CometSupport>>() {
{
if (testClassExists(NETTY))
add(NettyCometSupport.class);

if (testClassExists(GLASSFISH_V2))
add(GlassFishv2CometSupport.class);

Expand Down Expand Up @@ -228,7 +233,7 @@ public CometSupport resolve(boolean useNativeIfPossible, boolean defaultToBlocki
} else {
l = detectWebSocketPresent();
if (l.isEmpty()) {
return resolve(useNativeIfPossible,defaultToBlocking);
return resolve(useNativeIfPossible, defaultToBlocking);
}
cs = resolveWebSocket(l);
}
Expand Down

0 comments on commit 998046c

Please sign in to comment.