001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.type.scope.storage; 020 021import java.io.Serializable; 022 023import lucee.commons.lang.ExceptionUtil; 024import lucee.runtime.CFMLFactoryImpl; 025import lucee.runtime.exp.ExceptionHandler; 026import lucee.runtime.listener.AppListenerSupport; 027import lucee.runtime.listener.ApplicationListener; 028import lucee.runtime.op.Caster; 029 030public class SessionEndListener implements StorageScopeListener,Serializable { 031 032 private static final long serialVersionUID = -3868545140988347285L; 033 034 @Override 035 public void doEnd(StorageScopeEngine engine,StorageScopeCleaner cleaner,String appName, String cfid) { 036 CFMLFactoryImpl factory = engine.getFactory(); 037 ApplicationListener listener = factory.getConfig().getApplicationListener(); 038 try { 039 cleaner.info("call onSessionEnd for "+appName+"/"+cfid); 040 listener.onSessionEnd(factory, appName, cfid); 041 } 042 catch (Throwable t) { 043 ExceptionUtil.rethrowIfNecessary(t); 044 ExceptionHandler.log(factory.getConfig(),Caster.toPageException(t)); 045 } 046 } 047 048 @Override 049 public boolean hasDoEnd(StorageScopeEngine engine,StorageScopeCleaner cleaner,String appName) { 050 CFMLFactoryImpl factory = engine.getFactory(); 051 ApplicationListener listener = factory.getConfig().getApplicationListener(); 052 if((listener instanceof AppListenerSupport)) 053 return false; // FUTURE move the method used to the loader and this contion is no longer needed 054 AppListenerSupport als=(AppListenerSupport)listener; 055 056 try { 057 return als.hasOnSessionEnd(appName); 058 } 059 catch (Throwable t) { 060 ExceptionUtil.rethrowIfNecessary(t); 061 ExceptionHandler.log(factory.getConfig(),Caster.toPageException(t)); 062 return false; 063 } 064 } 065 066}