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.debug;
020
021import java.util.Iterator;
022import java.util.LinkedList;
023
024import lucee.commons.io.res.Resource;
025import lucee.runtime.PageContext;
026import lucee.runtime.config.ConfigWebImpl;
027import lucee.runtime.exp.PageException;
028import lucee.runtime.net.http.ReqRspUtil;
029import lucee.runtime.op.Duplicator;
030import lucee.runtime.type.Array;
031import lucee.runtime.type.ArrayImpl;
032import lucee.runtime.type.Struct;
033
034public class DebuggerPool {
035
036        //private Resource storage;
037        private LinkedList<Struct> queue=new LinkedList<Struct>();
038        //private List<Debugger> list=new ArrayList<Debugger>();
039        
040        public DebuggerPool(Resource storage) {
041                //this.storage=storage;
042        }
043        
044        public synchronized void store(PageContext pc,Debugger debugger) {
045                if(ReqRspUtil.getScriptName(pc,pc.getHttpServletRequest()).indexOf("/lucee/")==0)return;
046                try {
047                        queue.add((Struct) Duplicator.duplicate(debugger.getDebuggingData(pc, true),true));
048                } catch (PageException e) {}
049                
050                while(queue.size()>((ConfigWebImpl)pc.getConfig()).getDebugMaxRecordsLogged())
051                        queue.poll();
052        }
053
054        public Array getData(PageContext pc) {
055                
056                Iterator<Struct> it = queue.iterator();
057                Array arr=new ArrayImpl();
058                while(it.hasNext()){
059                        arr.appendEL(it.next());
060                }
061                return arr;
062        }
063
064}