Skip to content

Commit

Permalink
Fix for #240 JBoss7 initialization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 27, 2012
1 parent da8b00e commit 52f8de2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public Action service(AtmosphereRequest request, AtmosphereResponse response)
/**
* Suspend the connection by invoking {@link AtmosphereRequest#startAsync()}
*
* @param action The {@link AtmosphereServlet.Action}
* @param action The {@link org.atmosphere.cpr.AtmosphereFramework.Action}
* @param req the {@link AtmosphereRequest}
* @param res the {@link AtmosphereResponse}
* @throws java.io.IOException
Expand All @@ -139,7 +139,7 @@ private void suspend(Action action, AtmosphereRequest req, AtmosphereResponse re

if (!req.isAsyncStarted()) {
AsyncContext asyncContext = req.startAsync();
asyncContext.addListener(new CometListener());
asyncContext.addListener(new CometListener(this));
// Do nothing except setting the times out
if (action.timeout != -1) {
asyncContext.setTimeout(action.timeout);
Expand Down Expand Up @@ -188,7 +188,18 @@ public void action(AtmosphereResourceImpl actionEvent) {
/**
* Servlet 3.0 async listener support.
*/
private class CometListener implements AsyncListener {
private final static class CometListener implements AsyncListener {

private final AsynchronousProcessor p;

public CometListener(){
p = null;
}

// For JBoss 7 https://github.com/Atmosphere/atmosphere/issues/240
public CometListener(AsynchronousProcessor processor){
this.p = processor;
}

public void onComplete(AsyncEvent event) throws IOException {
logger.debug("Resumed (completed): event: {}", event.getAsyncContext().getRequest());
Expand All @@ -198,7 +209,7 @@ public void onTimeout(AsyncEvent event) throws IOException {
logger.debug("onTimeout(): event: {}", event.getAsyncContext().getRequest());

try {
timedout((AtmosphereRequest) event.getAsyncContext().getRequest(),
p.timedout((AtmosphereRequest) event.getAsyncContext().getRequest(),
(AtmosphereResponse) event.getAsyncContext().getResponse());
} catch (ServletException ex) {
logger.debug("onTimeout(): failed timing out comet response: " + event.getAsyncContext().getResponse(), ex);
Expand All @@ -209,7 +220,7 @@ public void onError(AsyncEvent event) {
logger.debug("onError(): event: {}", event.getAsyncContext().getResponse());

try {
cancelled((AtmosphereRequest) event.getAsyncContext().getRequest(),
p.cancelled((AtmosphereRequest) event.getAsyncContext().getRequest(),
(AtmosphereResponse) event.getAsyncContext().getResponse());
} catch (Throwable ex) {
logger.debug("failed cancelling comet response: " + event.getAsyncContext().getResponse(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ public Action doCometSupport(AtmosphereRequest req, AtmosphereResponse res) thro
return cometSupport.service(req, res);
}
} catch (IllegalStateException ex) {
if (ex.getMessage() != null && ex.getMessage().startsWith("Tomcat failed")) {
if (ex.getMessage() != null && (ex.getMessage().startsWith("Tomcat failed") || ex.getMessage().startsWith("JBoss failed") )) {
if (!isFilter) {
logger.warn("Failed using comet support: {}, error: {} Is the Nio or Apr Connector enabled?", cometSupport.getClass().getName(),
ex.getMessage());
Expand Down

0 comments on commit 52f8de2

Please sign in to comment.