/** * All proprietary Comet based {@link Servlet} must invoke the suspended * method when the first request comes in. The returned value, of type * {@link Atmosphere#Action}, tells the proprietary Comet {@link Servlet} * to suspended or not the current {@link HttpServletResponse}. * * @param req the {@link HttpServletRequest} * @param res the {@link HttpServletResponse} * @return action the Action operation. */ public Action suspended(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ if (logger.isLoggable(Level.FINE)){ logger.fine("(suspend) invoked:\n HttpServletRequest: " + req + "\n HttpServletResponse: " + res); } return action(req, res); }
@Override public void handle(Throwable event) { try { logger.debug("exceptionHandler", event); AsynchronousProcessor.class.cast(framework.getAsyncSupport()) .cancelled(r, res); } catch (IOException e) { logger.debug("", e); } catch (ServletException e) { logger.debug("", e); } } });
/** * Return "javax.servlet". * @return "javax.servlet" */ @Override public String getContainerName() { return super.getContainerName() + " using javax.servlet/3.0"; }
@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));
/** * Weblogic specific comet based implementation. * * @param rrk * @return * @throws java.io.IOException * @throws javax.servlet.ServletException */ protected void doTimeout(RequestResponseKey rrk) throws IOException, ServletException { ((AsynchronousProcessor)cometSupport).timedout(rrk.getRequest(), rrk.getResponse()); }
/** * All proprietary Comet based {@link Servlet} must invoke the timedout * method when the underlying WebServer time out the {@link HttpServletResponse}. * The returned value, of type * {@link Atmosphere#Action}, tells the proprietary Comet {@link Servlet} * to resume (again), suspended or do nothing with the current {@link HttpServletResponse}. * * @param req the {@link HttpServletRequest} * @param res the {@link HttpServletResponse} * @return action the Action operation. */ public Action timedout(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ HttpSession session = req.getSession(false); AtmosphereHandlerWrapper aw = map(req.getServletPath()); AtmosphereEventImpl event = null; if (session != null) { event = (AtmosphereEventImpl) session.getAttribute(EVENT); event.isResumedOnTimeout = true; } if (event != null){ if (!event.getResponse().equals(res)){ logger.warning("Invalid response: " + res); } else { aw.atmosphereHandler.onMessage(event); } } return timedoutAction; }
/** * Init Grizzly's {@link CometContext} that will be used to suspend and * resume the response. * @param sc the {@link ServletContext} * @throws javax.servlet.ServletException */ @Override public void init(ServletConfig sc) throws ServletException{ super.init(sc); atmosphereCtx = sc.getServletContext().getContextPath() + ATMOSPHERE; CometEngine cometEngine = CometEngine.getEngine(); CometContext context = cometEngine.register(atmosphereCtx); context.setExpirationDelay(-1); if (logger.isLoggable(Level.FINE)){ logger.fine("Created CometContext for " + atmosphereCtx); } }
@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 * @throws java.io.IOException * @throws javax.servlet.ServletException */ protected void doTimeout(RequestResponseKey rrk) throws IOException, ServletException { ((AsynchronousProcessor) framework.getAsyncSupport()).timedout(AtmosphereRequestImpl.wrap(rrk.getRequest()), AtmosphereResponseImpl.wrap(rrk.getResponse())); }
/** * Invoke the {@link AtmosphereHandler#onEvent} method. * @param req the {@link HttpServletRequest} * @param res the {@link HttpServletResponse} * @return action the Action operation. */ Action action(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException{ HttpSession session = req.getSession(true); AtmosphereHandlerWrapper g = map(req.getServletPath()); AtmosphereEventImpl event = new AtmosphereEventImpl(config, g.broadcaster,req, res,this); Action a = ((AtmosphereEventImpl)g.atmosphereHandler.onEvent(event)).action; if (event.isSuspended()){ session.setAttribute(EVENT,event); } return a; }
/** * Init Grizzly's {@link CometContext} that will be used to suspend and * resume the response. * @param sc the {@link ServletContext} * @throws javax.servlet.ServletException */ @Override public void init(ServletConfig sc) throws ServletException{ super.init(sc); atmosphereCtx = sc.getServletContext().getContextPath() + ATMOSPHERE; CometEngine cometEngine = CometEngine.getEngine(); CometContext context = cometEngine.register(atmosphereCtx); context.setExpirationDelay(-1); if (logger.isLoggable(Level.FINE)){ logger.fine("Created CometContext for " + atmosphereCtx); } }
@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));
/** * All proprietary Comet based {@link Servlet} must invoke the resume * method when the Atmosphere's application decide to resume the {@link HttpServletResponse}. * The returned value, of type * {@link Atmosphere#Action}, tells the proprietary Comet {@link Servlet} * to resume (again), suspended or do nothing with the current {@link HttpServletResponse}. * * @param req the {@link HttpServletRequest} * @param res the {@link HttpServletResponse} * @return action the Action operation. */ public Action resumed(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{ if (logger.isLoggable(Level.FINE)){ logger.fine("(resumed) invoked:\n HttpServletRequest: " + req + "\n HttpServletResponse: " + res); } return action(req, res); }
AtmosphereHandlerWrapper aw = map(req.getServletPath()); AtmosphereEventImpl event = null; if (session != null) {
@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));
/** * {@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); } } }
private void _close(AtmosphereRequest request) { AtmosphereResourceImpl r = AtmosphereResourceImpl.class.cast(request.resource()); if (request != null && r != null) { AsynchronousProcessor.class.cast(r.getAtmosphereConfig().framework().getAsyncSupport()).endRequest(r, true); } }
@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 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()); } }