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.exp.PageException;
027import lucee.runtime.op.Caster;
028import lucee.runtime.type.Query;
029
030public class IntervallMonitorWrap extends MonitorWrap implements IntervallMonitor {
031        private static final Object[] PARAMS_LOG = new Object[0];
032
033        private Method log;
034        private Method getData;
035
036        public IntervallMonitorWrap(Object monitor) {
037                super(monitor,TYPE_INTERVALL);
038        }
039
040        @Override
041        public void log() throws IOException {
042
043                try {
044                        if(log==null) {
045                                log=monitor.getClass().getMethod("log", new Class[0]);
046                        }
047                        log.invoke(monitor, PARAMS_LOG);
048                } catch (Exception e) {e.printStackTrace();
049                        throw ExceptionUtil.toIOException(e);
050                } 
051        }
052
053        public Query getData(Map<String,Object> arguments) throws PageException{
054                try {
055                        if(getData==null) {
056                                getData=monitor.getClass().getMethod("getData", new Class[]{Map.class});
057                        }
058                        return (Query) getData.invoke(monitor, new Object[]{arguments});
059                } catch (Exception e) {
060                        throw Caster.toPageException(e);
061                } 
062        }
063
064        /*public Query getData(long minAge, long maxAge, int maxrows) throws IOException{
065                try {
066                        if(getData==null) {
067                                getData=monitor.getClass().getMethod("getData", new Class[]{long.class,long.class,int.class});
068                        }
069                        return (Query) getData.invoke(monitor, new Object[]{new Long(minAge),new Long(maxAge),new Integer(maxrows)});
070                } catch (Exception e) {
071                        throw ExceptionUtil.toIOException(e);
072                } 
073        }*/
074
075}