Search in sources :

Example 1 with OnBroadcast

use of org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter.OnBroadcast in project atmosphere by Atmosphere.

the class AtmosphereResourceLifecycleInterceptor method postInspect.

@Override
public void postInspect(final AtmosphereResource r) {
    if (Utils.pollableTransport(r.transport()) || r.transport().equals(UNDEFINED) || Utils.webSocketMessage(r))
        return;
    AtmosphereResourceImpl impl = AtmosphereResourceImpl.class.cast(r);
    if ((force || impl.getRequest(false).getMethod().equalsIgnoreCase(method)) && !impl.action().equals(Action.CANCELLED) && impl.isInScope()) {
        logger.trace("Marking AtmosphereResource {} for suspend operation", r.uuid());
        switch(r.transport()) {
            case JSONP:
            case AJAX:
            case LONG_POLLING:
                break;
            default:
                r.addEventListener(new OnBroadcast() {

                    @Override
                    public void onBroadcast(AtmosphereResourceEvent event) {
                        try {
                            r.getResponse().flushBuffer();
                        } catch (IOException e) {
                            logger.trace("", e);
                        }
                    }
                });
        }
        r.suspend(timeoutInMilli);
    }
}
Also used : OnBroadcast(org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter.OnBroadcast) AtmosphereResourceEvent(org.atmosphere.cpr.AtmosphereResourceEvent) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 AtmosphereResourceEvent (org.atmosphere.cpr.AtmosphereResourceEvent)1 OnBroadcast (org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter.OnBroadcast)1 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)1