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;
022
023import lucee.commons.io.SystemUtil;
024import lucee.commons.lang.ExceptionUtil;
025import lucee.runtime.config.ConfigServer;
026import lucee.runtime.config.ConfigWebFactory;
027import lucee.runtime.config.ConfigWebFactory.MonitorTemp;
028
029public class ActionMonitorFatory {
030        public static ActionMonitorCollector getActionMonitorCollector() {
031                if(SystemUtil.getLoaderVersion()>4) return new ActionMonitorCollectorImpl();
032                return new ActionMonitorCollectorRefImpl();
033        }
034
035        public static ActionMonitorCollector getActionMonitorCollector(ConfigServer cs, ConfigWebFactory.MonitorTemp[] temps) throws IOException {
036                // try to load with interface
037                try{
038                        ActionMonitorCollector collector = new ActionMonitorCollectorImpl();
039                        addMonitors(collector,cs,temps);
040                        return collector;
041                }
042                catch(Throwable t){
043                        ExceptionUtil.rethrowIfNecessary(t);
044                        t.printStackTrace();
045                        ActionMonitorCollector collector = new ActionMonitorCollectorRefImpl();
046                        addMonitors(collector,cs,temps);
047                        return collector;
048                }
049        }
050
051        private static void addMonitors(ActionMonitorCollector collector, ConfigServer cs, MonitorTemp[] temps) throws IOException {
052                MonitorTemp temp;
053                for(int i=0;i<temps.length;i++){
054                        temp=temps[i];
055                        collector.addMonitor(cs, temp.obj, temp.name, temp.log);
056                }
057        }
058}