Search in sources :

Example 1 with CometEventImpl

use of org.apache.catalina.connector.CometEventImpl in project tomcat70 by apache.

the class CometConnectionManagerValve method lifecycleEvent.

@Override
public void lifecycleEvent(LifecycleEvent event) {
    if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType())) {
        // The container is getting stopped, close all current connections
        Iterator<Request> iterator = cometRequests.iterator();
        while (iterator.hasNext()) {
            Request request = iterator.next();
            // Remove the session tracking attribute as it isn't
            // serializable or required.
            HttpSession session = request.getSession(false);
            if (session != null) {
                session.removeAttribute(cometRequestsAttribute);
            }
            // Close the comet connection
            CometEventImpl cometEvent = request.getEvent();
            try {
                cometEvent.setEventType(CometEvent.EventType.END);
                cometEvent.setEventSubType(CometEvent.EventSubType.WEBAPP_RELOAD);
                getNext().event(request, request.getResponse(), cometEvent);
            } catch (Exception e) {
                container.getLogger().warn(sm.getString("cometConnectionManagerValve.event"), e);
            } finally {
                try {
                    cometEvent.close();
                } catch (IOException e) {
                    container.getLogger().warn(sm.getString("cometConnectionManagerValve.event"), e);
                }
            }
        }
        cometRequests.clear();
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) CometEventImpl(org.apache.catalina.connector.CometEventImpl) Request(org.apache.catalina.connector.Request) IOException(java.io.IOException) LifecycleException(org.apache.catalina.LifecycleException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with CometEventImpl

use of org.apache.catalina.connector.CometEventImpl in project tomcat70 by apache.

the class CometConnectionManagerValve method sessionDestroyed.

@Override
public void sessionDestroyed(HttpSessionEvent se) {
    // Close all Comet connections associated with this session
    Request[] reqs = (Request[]) se.getSession().getAttribute(cometRequestsAttribute);
    if (reqs != null) {
        for (int i = 0; i < reqs.length; i++) {
            Request req = reqs[i];
            try {
                CometEventImpl event = req.getEvent();
                event.setEventType(CometEvent.EventType.END);
                event.setEventSubType(CometEvent.EventSubType.SESSION_END);
                ((CometProcessor) req.getWrapper().getServlet()).event(event);
                event.close();
            } catch (Exception e) {
                req.getWrapper().getParent().getLogger().warn(sm.getString("cometConnectionManagerValve.listenerEvent"), e);
            }
        }
    }
}
Also used : CometProcessor(org.apache.catalina.comet.CometProcessor) CometEventImpl(org.apache.catalina.connector.CometEventImpl) Request(org.apache.catalina.connector.Request) LifecycleException(org.apache.catalina.LifecycleException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 LifecycleException (org.apache.catalina.LifecycleException)2 CometEventImpl (org.apache.catalina.connector.CometEventImpl)2 Request (org.apache.catalina.connector.Request)2 HttpSession (javax.servlet.http.HttpSession)1 CometProcessor (org.apache.catalina.comet.CometProcessor)1