001    package railo.runtime.debug;
002    
003    import java.util.Iterator;
004    import java.util.LinkedList;
005    
006    import railo.commons.io.res.Resource;
007    import railo.runtime.PageContext;
008    import railo.runtime.config.ConfigWebImpl;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.net.http.ReqRspUtil;
011    import railo.runtime.op.Duplicator;
012    import railo.runtime.type.Array;
013    import railo.runtime.type.ArrayImpl;
014    import railo.runtime.type.Struct;
015    
016    public class DebuggerPool {
017    
018            //private Resource storage;
019            private LinkedList<Struct> queue=new LinkedList<Struct>();
020            //private List<Debugger> list=new ArrayList<Debugger>();
021            
022            public DebuggerPool(Resource storage) {
023                    //this.storage=storage;
024            }
025            
026            public synchronized void store(PageContext pc,Debugger debugger) {
027                    if(ReqRspUtil.getScriptName(pc.getHttpServletRequest()).indexOf("/railo-context/")==0)return;
028                    try {
029                            queue.add((Struct) Duplicator.duplicate(debugger.getDebuggingData(pc, true),true));
030                    } catch (PageException e) {}
031                    
032                    while(queue.size()>((ConfigWebImpl)pc.getConfig()).getDebugMaxRecordsLogged())
033                            queue.poll();
034                    
035                    /*
036                     store to file
037                     
038                    OutputStream os = null;
039                    try {
040                            String str = pc.serialize(debugger.getDebuggingData(pc,true));
041                            Resource res = storage.getRealResource(IDGenerator.stringId()+".cfs");
042                            IOUtil.write(res, str.getBytes("UTF-8"));
043                            }
044                    catch (Exception e) {
045                                    e.printStackTrace();
046                            }
047                    finally {
048                            IOUtil.closeEL(os);
049                    }*/
050            }
051    
052            public Array getData(PageContext pc) {
053                    
054                    Iterator<Struct> it = queue.iterator();
055                    Array arr=new ArrayImpl();
056                    while(it.hasNext()){
057                            arr.appendEL(it.next());
058                    }
059                    return arr;
060                    
061            /*Resource[] children = storage.listResources(new ExtensionResourceFilter(".cfs"));
062            Array arr=new ArrayImpl();
063            String str;
064                    for(int i=0;i<children.length && i<10;i++){print.o(children[i].toString());
065                    try {
066                                    str=IOUtil.toString(children[i], "UTF-8");
067                                    arr.appendEL(pc.evaluate(str));
068                            } 
069                    catch (Exception e) {
070                                    print.e(e);
071                            }
072            }
073            return arr;*/
074            }
075    
076    }