public AtmosphereCoordinator route(AtmosphereRequest request, AtmosphereResponse response) throws IOException { final VertxAsyncIOWriter w = VertxAsyncIOWriter.class.cast(response.getAsyncIOWriter()); try { Action a = framework.doCometSupport(request, response); final AtmosphereResourceImpl impl = (AtmosphereResourceImpl) request.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE); String transport = (String) request.getAttribute(FrameworkConfig.TRANSPORT_IN_USE); if (transport == null) { transport = request.getHeader(X_ATMOSPHERE_TRANSPORT); } logger.debug("Transport {} action {}", transport, a); final Action action = (Action) request.getAttribute(NettyCometSupport.SUSPEND); if (action != null && action.type() == Action.TYPE.SUSPEND && action.timeout() != -1) { final AtomicReference<Future<?>> f = new AtomicReference<>(); f.set(suspendTimer.scheduleAtFixedRate(new Runnable() { @Override public void run() { if (!w.isClosed() && (System.currentTimeMillis() - w.lastTick()) > action.timeout()) { asynchronousProcessor.endRequest(impl, false); f.get().cancel(true); } } }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS)); } } catch (Throwable e) { logger.error("Unable to process request", e); } return this; }
/** * {@inheritDoc} */ public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException { Action action = suspended(req, res); if (action.type() == Action.TYPE.SUSPEND) { logger.debug("Suspending response: {}", res); } else if (action.type() == Action.TYPE.RESUME) { logger.debug("Resuming response: {}", res); Action nextAction = resumed(req, res); if (nextAction.type() == Action.TYPE.SUSPEND) { logger.debug("Suspending after resuming response: {}", res); } } return action; }
@Override public void run() { if (!w.get().isClosed() && (System.currentTimeMillis() - w.get().lastTick()) > action.timeout()) { AtmosphereResourceImpl impl = state.resource(); if (impl != null) { asynchronousProcessor.endRequest(impl, false); f.get().cancel(true); } } } }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); Object o = ctx.attr(ATTACHMENT).get(); if (o == null) return; if (WebSocket.class.isAssignableFrom(o.getClass())) { NettyWebSocket webSocket = NettyWebSocket.class.cast(o); logger.trace("Closing {}", webSocket.uuid()); try { if (webSocket.closeFuture() != null) { webSocket.closeFuture().cancel(true); } webSocketProcessor.close(webSocket, 1005); } catch (Exception ex) { logger.error("{}", webSocket, ex); } } else if (State.class.isAssignableFrom(o.getClass())) { logger.trace("State {}", o); State s = State.class.cast(o); if (s.action.type() == Action.TYPE.SUSPEND) { asynchronousProcessor.endRequest(s.resource(), true); } } else { logger.warn("Invalid state {} and Channel {}", o, ctx.channel()); } }
@Override public void run() { if (!w.isClosed() && (System.currentTimeMillis() - w.lastTick()) > action.timeout()) { asynchronousProcessor.endRequest(impl, false); f.get().cancel(true); } } }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
if (a.type() == Action.TYPE.SUSPEND) { if (transport.equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT) || transport.equalsIgnoreCase(HeaderConfig.JSONP_TRANSPORT)) { resumeOnBroadcast = true; if (action != null && action.type() == Action.TYPE.SUSPEND && action.timeout() != -1) { final AtomicReference<Future<?>> f = new AtomicReference<Future<?>>(); f.set(suspendTimer.scheduleAtFixedRate(new Runnable() { }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS)); } else if (action != null && action.type() == Action.TYPE.RESUME) { resumeOnBroadcast = false;
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); Object o = ctx.attr(ATTACHMENT).get(); if (o == null) return; if (WebSocket.class.isAssignableFrom(o.getClass())) { NettyWebSocket webSocket = NettyWebSocket.class.cast(o); logger.trace("Closing {}", webSocket.uuid()); try { if (webSocket.closeFuture() != null) { webSocket.closeFuture().cancel(true); } webSocketProcessor.close(webSocket, 1005); } catch (Exception ex) { logger.error("{}", webSocket, ex); } } else if (State.class.isAssignableFrom(o.getClass())) { logger.trace("State {}", o); State s = State.class.cast(o); if (s.action.type() == Action.TYPE.SUSPEND) { asynchronousProcessor.endRequest(s.resource(), true); } } else { logger.warn("Invalid state {} and Channel {}", o, ctx.channel()); } }
@Override public void run() { if (!w.isClosed() && (System.currentTimeMillis() - w.lastTick()) > action.timeout()) { asynchronousProcessor.endRequest(impl, false); f.get().cancel(true); } } }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
/** * Weblogic specific comet based implementation. * * @param rrk * @return true if suspended * @throws java.io.IOException * @throws javax.servlet.ServletException */ protected boolean doRequest(RequestResponseKey rrk) throws IOException, ServletException { try { rrk.getRequest().getSession().setAttribute(WebLogicCometSupport.RRK, rrk); Action action = framework.doCometSupport(AtmosphereRequestImpl.wrap(rrk.getRequest()), AtmosphereResponseImpl.wrap(rrk.getResponse())); if (action.type() == Action.TYPE.SUSPEND) { if (action.timeout() == -1) { rrk.setTimeout(Integer.MAX_VALUE); } else { rrk.setTimeout((int) action.timeout()); } } return action.type() == Action.TYPE.SUSPEND; } catch (IllegalStateException ex) { logger.error("AtmosphereServlet.doRequest exception", ex); throw ex; } }
/** * {@inheritDoc} */ @Override public void action(AtmosphereResourceImpl actionEvent) { super.action(actionEvent); if (actionEvent.isInScope() && actionEvent.action().type() == Action.TYPE.RESUME) { try { RequestResponseKey rrk = (RequestResponseKey) actionEvent.getRequest().getSession().getAttribute(RRK); AbstractAsyncServlet.notify(rrk, null); } catch (IOException ex) { logger.debug("action failed", ex); } } }
@Override public void run() { if (!w.get().isClosed() && (System.currentTimeMillis() - w.get().lastTick()) > action.timeout()) { AtmosphereResourceImpl impl = state.resource(); if (impl != null) { asynchronousProcessor.endRequest(impl, false); f.get().cancel(true); } } } }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
a.type(Action.TYPE.SUSPEND); if (a.type() == Action.TYPE.SUSPEND) { if (transport != null && (transport.equalsIgnoreCase(HeaderConfig.STREAMING_TRANSPORT) || transport.equalsIgnoreCase(SSE_TRANSPORT))) { if (action != null && action.type() == Action.TYPE.SUSPEND) { if (action.timeout() != -1) { final AtomicReference<ChannelWriter> w = new AtomicReference<ChannelWriter>(asyncWriter); final AtomicReference<Future<?>> f = new AtomicReference<Future<?>>(); }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS)); } else if (action != null && action.type() == Action.TYPE.RESUME) { resumeOnBroadcast = false; if (request != null && a != null && a.type() != Action.TYPE.SUSPEND) { request.destroy(); response.destroy();
if (action.type() == Action.TYPE.SUSPEND) { ar.destroyable(false); response.destroyable(false);
a.type(Action.TYPE.SUSPEND); if (a.type() == Action.TYPE.SUSPEND) { if (transport != null && (transport.equalsIgnoreCase(HeaderConfig.STREAMING_TRANSPORT) || transport.equalsIgnoreCase(SSE_TRANSPORT))) { if (action != null && action.type() == Action.TYPE.SUSPEND) { if (action.timeout() != -1) { final AtomicReference<ChannelWriter> w = new AtomicReference<ChannelWriter>(asyncWriter); final AtomicReference<Future<?>> f = new AtomicReference<Future<?>>(); }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS)); } else if (action != null && action.type() == Action.TYPE.RESUME) { resumeOnBroadcast = false; if (request != null && a != null && a.type() != Action.TYPE.SUSPEND) { request.destroy(); response.destroy();
if (action.type() == Action.TYPE.SUSPEND) { ar.destroyable(false); response.destroyable(false);
if (action.type() == Action.TYPE.SUSPEND) { ar.destroyable(false); response.destroyable(false);