001    package railo.runtime.type.scope.storage.clean;
002    
003    import railo.commons.lang.ExceptionUtil;
004    import railo.runtime.interpreter.VariableInterpreter;
005    import railo.runtime.type.scope.storage.StorageScopeCleaner;
006    import railo.runtime.type.scope.storage.StorageScopeEngine;
007    import railo.runtime.type.scope.storage.StorageScopeListener;
008    
009    public abstract class StorageScopeCleanerSupport implements StorageScopeCleaner {
010            
011    
012            protected static final int INTERVALL_MINUTE = 60*1000; 
013            protected static final int INTERVALL_HOUR = 60*60*1000; 
014            protected static final int INTERVALL_DAY = 24*60*60*1000; 
015            
016            protected StorageScopeEngine engine;
017            protected int type;
018            protected StorageScopeListener listener;
019            private String application;
020            protected String strType;
021            private final int intervall;
022            private long lastClean;
023            
024            public StorageScopeCleanerSupport(int type, StorageScopeListener listener, int intervall) {
025                    this.type=type;
026                    this.listener=listener;
027                    this.strType=VariableInterpreter.scopeInt2String(type);
028                    application=strType+" storage";
029                    this.intervall=intervall;
030                    
031            }
032    
033            /**
034             * @see railo.runtime.type.scope.storage.StorageScopeCleaner#init(railo.runtime.type.scope.storage.StorageScopeEngine)
035             */
036            public void init(StorageScopeEngine engine){
037                    this.engine=engine;
038            }
039            
040            public final void clean() {
041                    if(lastClean+intervall<System.currentTimeMillis()) {
042                            //info("cleaning "+application);
043                            _clean();
044                            lastClean=System.currentTimeMillis();
045                            //info("next cleaning intervall in "+(intervall/1000)+" seconds");
046                    }
047            }
048            
049            protected abstract void _clean();
050            
051            /**
052             * @return the log
053             */
054            public void info(String msg) {
055                     engine.getFactory().getScopeContext().info(msg);
056            }
057            public void error(String msg) {
058                    engine.getFactory().getScopeContext().error(msg);
059                    engine._getLog().error(application, msg);
060            }
061            
062            public void error(Throwable t) {
063                    engine.getFactory().getScopeContext().error(t);
064                    engine._getLog().error(application,ExceptionUtil.getStacktrace(t, true));
065            }
066    }