List of usage examples for javax.servlet.http HttpSessionListener sessionDestroyed
default public void sessionDestroyed(HttpSessionEvent se)
From source file:org.apache.catalina.cluster.session.DeltaSession.java
public void expire(boolean notify, boolean notifyCluster) { // Mark this session as "being expired" if needed if (expiring) return;// ww w .j a v a 2 s. co m String expiredId = getId(); synchronized (this) { if (manager == null) return; expiring = true; // Notify interested application event listeners // FIXME - Assumes we call listeners in reverse order Context context = (Context) manager.getContainer(); Object listeners[] = context.getApplicationLifecycleListeners(); if (notify && (listeners != null)) { HttpSessionEvent event = new HttpSessionEvent(getSession()); for (int i = 0; i < listeners.length; i++) { int j = (listeners.length - 1) - i; if (!(listeners[j] instanceof HttpSessionListener)) continue; HttpSessionListener listener = (HttpSessionListener) listeners[j]; try { fireContainerEvent(context, "beforeSessionDestroyed", listener); listener.sessionDestroyed(event); fireContainerEvent(context, "afterSessionDestroyed", listener); } catch (Throwable t) { try { fireContainerEvent(context, "afterSessionDestroyed", listener); } catch (Exception e) { ; } // FIXME - should we do anything besides log these? log.error(sm.getString("standardSession.sessionEvent"), t); } } } setValid(false); // Remove this session from our manager's active sessions if (manager != null) manager.remove(this); // Unbind any objects associated with this session String keys[] = keys(); for (int i = 0; i < keys.length; i++) removeAttribute(keys[i], notify); // Notify interested session event listeners if (notify) { fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null); } // We have completed expire of this session expiring = false; if (notifyCluster) { log.debug("Notifying cluster of expiration primary=" + isPrimarySession() + " id=" + expiredId); ((DeltaManager) manager).sessionExpired(expiredId); } } }
From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java
/** * ?Session Destroyed//from w ww . j a va 2s . com */ private void publishSessionDestroyed() { ArrayList<HttpSessionListener> listeners = _manager.getListeners(); if (listeners != null) { HttpSessionEvent event = new HttpSessionEvent(this); for (int i = listeners.size() - 1; i >= 0; i--) { HttpSessionListener listener; listener = (HttpSessionListener) listeners.get(i); listener.sessionDestroyed(event); } } }
From source file:org.kchine.r.server.impl.RServantImpl.java
public void startHttpServer(final int port) throws RemoteException { if (_virtualizationServer != null) { throw new RemoteException("Server Already Running"); } else if (ServerManager.isPortInUse("127.0.0.1", port)) { throw new RemoteException("Port already in use"); } else {//w ww . ja va 2 s . c om try { log.info("!! Request to run virtualization server on port " + port); RKit rkit = new RKit() { RServices _r = (RServices) UnicastRemoteObject.toStub(RServantImpl.this); ReentrantLock _lock = new ExtendedReentrantLock() { public void rawLock() { super.lock(); } public void rawUnlock() { super.unlock(); } }; public RServices getR() { return _r; } public ReentrantLock getRLock() { return _lock; } }; _virtualizationServer = new Server(port); _virtualizationServer.setStopAtShutdown(true); Context root = new Context(_virtualizationServer, "/rvirtual", Context.SESSIONS | Context.NO_SECURITY); final HttpSessionListener sessionListener = new FreeResourcesListener(); root.getSessionHandler().setSessionManager(new HashSessionManager() { @Override protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session, boolean arg1) { super.addSession(session, arg1); sessionListener.sessionCreated(new HttpSessionEvent(session.getSession())); } @Override protected void addSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session) { super.addSession(session); } @Override public void removeSession(HttpSession session, boolean invalidate) { super.removeSession(session, invalidate); sessionListener.sessionDestroyed(new HttpSessionEvent(session)); } @Override public void removeSession(org.mortbay.jetty.servlet.AbstractSessionManager.Session session, boolean arg1) { super.removeSession(session, arg1); sessionListener.sessionDestroyed(new HttpSessionEvent(session)); } @Override protected void removeSession(String clusterId) { super.removeSession(clusterId); } }); root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.GraphicsServlet(rkit)), "/graphics/*"); root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.RESTServlet(rkit)), "/rest/*"); root.addServlet( new ServletHolder(new org.kchine.r.server.http.frontend.CommandServlet(rkit, false)), "/cmd/*"); root.addServlet(new ServletHolder(new org.kchine.r.server.http.local.LocalHelpServlet(rkit)), "/helpme/*"); root.addServlet(new ServletHolder( new org.kchine.r.server.http.frontend.WWWDirectoryServlet(new DiretoryProvider() { public String getDirectory() throws Exception { return DirectJNI.getInstance().getRServices().getWorkingDirectory(); } }, "/wd")), "/wd/*"); root.addServlet(new ServletHolder( new org.kchine.r.server.http.frontend.WWWDirectoryServlet(ServerManager.WWW_DIR, "/www")), "/www/*"); root.addServlet(new ServletHolder(new org.kchine.r.server.http.frontend.WWWDirectoryServlet( ServerManager.WWW_DIR, "/appletlibs")), "/appletlibs/*"); System.out.println("+ going to start virtualization http server port : " + port); _virtualizationServer.start(); log.info("HTTP R URL :" + "http://" + PoolUtils.getHostIp() + ":" + port + "/rvirtual/cmd"); } catch (Exception e) { log.info(PoolUtils.getStackTraceAsString(e)); e.printStackTrace(); } } }
From source file:org.ops4j.pax.web.service.internal.EventListenerTest.java
@Test public void listenerIsCalled() throws IOException, NamespaceException, ServletException, InterruptedException { HttpSessionListener listener = createMock(HttpSessionListener.class); listener.sessionCreated((HttpSessionEvent) notNull()); listener.sessionDestroyed((HttpSessionEvent) notNull()); replay(listener);/*from w w w .j a va 2s. c o m*/ HttpContext context = m_httpService.createDefaultHttpContext(); m_httpService.registerServlet("/test", new TestServlet(), null, context); m_httpService.registerEventListener(listener, context); HttpMethod method = new GetMethod("http://localhost:8080/test"); m_client.executeMethod(method); System.out.println("Waiting the session to expire for two minutes..."); method.releaseConnection(); Thread.sleep(2 * 60 * 1000); verify(listener); ((StoppableHttpService) m_httpService).stop(); }