Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast set 'true', atmosphere don't broadcast. #974

Closed
soranakk opened this issue Mar 21, 2013 · 5 comments
Labels

Comments

@soranakk
Copy link

Hi
We are using Atmosphere (1.0.12) on tomcat 7.0.35 server.

In our application, if org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast set 'true', however atmosphere resource had been suspended, atmosphere don't broadcast.
Also Atmosphere (1.0.11) not work.

But in Atmosphere Websockets(1.0.10), if org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast set 'true', atmosphere work fine.

I think that something has been degraded.

Our web.xml and atmosphere.xml is below.

web.xml :

    <servlet>
        <servlet-name>Atmosphere</servlet-name>
        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/Atmosphere-servlet.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Atmosphere</servlet-name>
        <url-pattern>/socket/*</url-pattern>
    </servlet-mapping>

atmosphere.xml :

<?xml version="1.0" encoding="UTF-8"?>
<atmosphere-handlers>
    <atmosphere-handler support-session="true"
        context-root="/*" class-name="org.atmosphere.handler.ReflectorServletProcessor"
        broadcasterCache="org.atmosphere.cache.UUIDBroadcasterCache">

        <property name="servletClassName" value="org.springframework.web.servlet.DispatcherServlet" />

        <applicationConfig>
            <param-name>org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast</param-name>
            <param-value>true</param-value>
        </applicationConfig>
    </atmosphere-handler>
</atmosphere-handlers>

Our code is below.

@Controller
@RequestMapping(value = { "/service" })
public class AtmosphereSample {

    @RequestMapping(value = { "/" }, method = RequestMethod.GET)
    @ResponseBody
    public void suspend(AtmosphereRequest request) {
        String userBroadcasterId = "/users/1";
        AtmosphereResource resource = (AtmosphereResource) request.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
        if (BroadcasterFactory.getDefault().lookup(userBroadcasterId) == null) {
            AtmosphereUtils.suspend(resource, userBroadcasterId);
        } else {
            AtmosphereUtils.suspend(resource);
        }
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    @ResponseBody
    public void webSocketMessage(AtmosphereRequest atmReq,
            AtmosphereResponse atmRes) {
        MetaBroadcaster.getDefault().broadcastTo("/", "{\"message\":\"open\"}");
    }
}

class AtmosphereUtils {

    public static void suspend(final AtmosphereResource resource) {
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        resource.addEventListener(new AtmosphereResourceEventListenerAdapter() {
            @Override
            public void onSuspend(AtmosphereResourceEvent event) {
                countDownLatch.countDown();
                resource.removeEventListener(this);
            }
        });

        if (TRANSPORT.LONG_POLLING.equals(resource.transport())) {
            resource.resumeOnBroadcast(true).suspend(-1, TimeUnit.MILLISECONDS);
        } else {
            resource.suspend(-1);
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
        }
    }

    public static void suspend(final AtmosphereResource resource, String broadcasterID) {

        final CountDownLatch countDownLatch = new CountDownLatch(1);
        resource.addEventListener(new AtmosphereResourceEventListenerAdapter() {
            @Override
            public void onSuspend(AtmosphereResourceEvent event) {
                countDownLatch.countDown();
                resource.removeEventListener(this);
            }
        });

        Broadcaster b = BroadcasterFactory.getDefault().lookup(broadcasterID, true);
        b.addAtmosphereResource(resource);

        if (TRANSPORT.LONG_POLLING.equals(resource.transport())) {
            resource.resumeOnBroadcast(true).suspend(-1, false);
        } else {
            resource.suspend(-1);
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
        }
    }
}
@jfarcand
Copy link
Member

Looking

jfarcand added a commit that referenced this issue Mar 25, 2013
jfarcand added a commit that referenced this issue Mar 25, 2013
jfarcand added a commit that referenced this issue Mar 25, 2013
jfarcand added a commit that referenced this issue Mar 25, 2013
@tmescic
Copy link

tmescic commented May 20, 2013

This works now in Atmosphere 1.0.13, but it doesn't work in Atmosphere 1.1.0.RC2. Will this fix be in the next release (1.1 final)?

@jfarcand
Copy link
Member

Can you try 1.1.0-SNAPSHOT? Read this

@tmescic
Copy link

tmescic commented May 23, 2013

Hello. I tried the snapshot version but it doesn't work with the param enabled (nothing is broadcasted). I've used the jquery atmosphere plugin from version 1.1.RC2 (since i don't know how to use the new one that doesn't use jquery) - but i don't think that matters in this case.

@jfarcand
Copy link
Member

Ok properly ported the fix to /issues/1029 to 1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants