001    package railo.runtime.type.scope;
002    
003    import java.util.Map;
004    
005    import railo.runtime.PageContext;
006    import railo.runtime.engine.ThreadLocalPageContext;
007    import railo.runtime.functions.system.GetApplicationSettings;
008    import railo.runtime.listener.ApplicationContext;
009    import railo.runtime.type.Collection;
010    import railo.runtime.type.KeyImpl;
011    
012    
013    
014    /**
015     * Session Scope
016     */
017    public final class ApplicationImpl extends ScopeSupport implements Application,SharedScope {
018    
019            private static final long serialVersionUID = 700830188207594563L;
020            
021            private static final Collection.Key APPLICATION_NAME = KeyImpl.intern("applicationname");
022            private long lastAccess;
023            private long timeSpan;
024            private long created;
025            
026            /**
027             * default constructor of the session scope
028             */
029            public ApplicationImpl() {
030                    super(true,"application",SCOPE_APPLICATION);
031                    created = System.currentTimeMillis();
032            }
033    
034            @Override
035            public long getLastAccess() { 
036                    return lastAccess;
037            }
038    
039            @Override
040            public long getTimeSpan() { 
041                return timeSpan;
042            }
043    
044            @Override
045            public void touchBeforeRequest(PageContext pc){
046                ApplicationContext appContext = pc.getApplicationContext();
047                setEL(APPLICATION_NAME,appContext.getName());
048                timeSpan=appContext.getApplicationTimeout().getMillis();
049                    lastAccess=System.currentTimeMillis();
050            }
051    
052            public void touchAfterRequest(PageContext pc) {
053                    // do nothing
054            }
055    
056        @Override
057        public boolean isExpired() {
058            return (lastAccess+timeSpan)<System.currentTimeMillis();
059        }
060    
061            /**
062             * @param lastAccess the lastAccess to set
063             */
064            public void setLastAccess(long lastAccess) {
065                    this.lastAccess = lastAccess;
066            }
067    
068            @Override
069            public void touch() {
070                    lastAccess=System.currentTimeMillis();
071            }
072            
073            /**
074             * undocumented Feature in ACF
075             * @return
076             */
077            public Map getApplicationSettings(){
078                    return GetApplicationSettings.call(ThreadLocalPageContext.get());
079            }
080    
081            @Override
082            public long getCreated() {
083                    return created;
084            }
085    }