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;
020
021import java.util.Map;
022
023import lucee.runtime.PageContext;
024import lucee.runtime.engine.ThreadLocalPageContext;
025import lucee.runtime.functions.system.GetApplicationSettings;
026import lucee.runtime.listener.ApplicationContext;
027import lucee.runtime.type.Collection;
028import lucee.runtime.type.KeyImpl;
029
030
031
032/**
033 * Session Scope
034 */
035public final class ApplicationImpl extends ScopeSupport implements Application,SharedScope {
036
037        private static final long serialVersionUID = 700830188207594563L;
038        
039        private static final Collection.Key APPLICATION_NAME = KeyImpl.intern("applicationname");
040        private long lastAccess;
041        private long timeSpan;
042        private long created;
043        
044        /**
045         * default constructor of the session scope
046         */
047        public ApplicationImpl() {
048                super(true,"application",SCOPE_APPLICATION);
049                created = System.currentTimeMillis();
050        }
051
052        @Override
053        public long getLastAccess() { 
054                return lastAccess;
055        }
056
057        @Override
058        public long getTimeSpan() { 
059            return timeSpan;
060        }
061
062        @Override
063        public void touchBeforeRequest(PageContext pc){
064            ApplicationContext appContext = pc.getApplicationContext();
065            setEL(APPLICATION_NAME,appContext.getName());
066            timeSpan=appContext.getApplicationTimeout().getMillis();
067                lastAccess=System.currentTimeMillis();
068        }
069
070        public void touchAfterRequest(PageContext pc) {
071                // do nothing
072        }
073
074    @Override
075    public boolean isExpired() {
076        return (lastAccess+timeSpan)<System.currentTimeMillis();
077    }
078
079        /**
080         * @param lastAccess the lastAccess to set
081         */
082        public void setLastAccess(long lastAccess) {
083                this.lastAccess = lastAccess;
084        }
085
086        @Override
087        public void touch() {
088                lastAccess=System.currentTimeMillis();
089        }
090        
091        /**
092         * undocumented Feature in ACF
093         * @return
094         */
095        public Map getApplicationSettings(){
096                return GetApplicationSettings.call(ThreadLocalPageContext.get());
097        }
098
099        @Override
100        public long getCreated() {
101                return created;
102        }
103}