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.monitor;
020
021import java.io.IOException;
022import java.lang.reflect.Method;
023import java.util.Map;
024
025import lucee.commons.lang.ExceptionUtil;
026import lucee.runtime.PageContext;
027import lucee.runtime.config.ConfigWeb;
028import lucee.runtime.exp.PageException;
029import lucee.runtime.op.Caster;
030import lucee.runtime.type.Query;
031
032public class RequestMonitorWrap extends MonitorWrap implements RequestMonitor {
033        private static final Class[] PARAMS_LOG = new Class[]{PageContext.class,boolean.class};
034
035        private Method log;
036        private Method getData;
037
038        private Method getDataRaw;
039
040
041
042        public RequestMonitorWrap(Object monitor) {
043                super(monitor,TYPE_REQUEST);
044        }
045
046        @Override
047        public void log(PageContext pc, boolean error) throws IOException {
048
049                try {
050                        if(log==null) {
051                                log=monitor.getClass().getMethod("log", PARAMS_LOG);
052                        }
053                        log.invoke(monitor, new Object[]{pc,Caster.toBoolean(error)});
054                } catch (Exception e) {
055                        throw ExceptionUtil.toIOException(e);
056                } 
057        }
058
059        public Query getData(ConfigWeb config,Map<String,Object> arguments) throws PageException{
060                try {
061                        if(getData==null) {
062                                getData=monitor.getClass().getMethod("getData", new Class[]{ConfigWeb.class,Map.class});
063                        }
064                        return (Query) getData.invoke(monitor, new Object[]{config,arguments});
065                } catch (Exception e) {
066                        throw Caster.toPageException(e);
067                } 
068        }
069
070        
071        /*
072        public Query getData(ConfigWeb config,long minAge, long maxAge, int maxrows) throws IOException{
073                try {
074                        if(getData==null) {
075                                getData=monitor.getClass().getMethod("getData", new Class[]{long.class,long.class,int.class});
076                        }
077                        return (Query) getData.invoke(monitor, new Object[]{new Long(minAge),new Long(maxAge),new Integer(maxrows)});
078                } catch (Exception e) {
079                        throw ExceptionUtil.toIOException(e);
080                } 
081        }
082        
083        public Query getDataRaw(ConfigWeb config, long minAge, long maxAge) throws IOException {
084                try {
085                        if(getDataRaw==null) {
086                                getDataRaw=monitor.getClass().getMethod("getDataRaw", new Class[]{ConfigWeb.class,long.class,long.class});
087                        }
088                        return (Query) getDataRaw.invoke(monitor, new Object[]{config,new Long(minAge),new Long(maxAge)});
089                } catch (Exception e) {e.printStackTrace();
090                        throw ExceptionUtil.toIOException(e);
091                } 
092        }*/
093}