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.engine; 020 021import lucee.commons.lang.ExceptionUtil; 022import lucee.commons.lang.types.RefBoolean; 023import lucee.runtime.config.ConfigServer; 024import lucee.runtime.config.ConfigServerImpl; 025 026/** 027 * own thread how check the main thread and his data 028 */ 029public final class Monitor extends Thread { 030 031 032 private static final long INTERVALL = 5000; 033 private final RefBoolean run; 034 private final ConfigServerImpl configServer; 035 036 /** 037 * @param contextes 038 * @param interval 039 * @param run 040 */ 041 public Monitor(ConfigServer configServer,RefBoolean run) { 042 043 this.run=run; 044 this.configServer=(ConfigServerImpl) configServer; 045 046 } 047 048 @Override 049 public void run() { 050 short tries=0; 051 while(run.toBooleanValue()) { 052 try { 053 sleep(INTERVALL); 054 } 055 catch (InterruptedException e) { 056 e.printStackTrace(); 057 } 058 059 if(!configServer.isMonitoringEnabled()) return; 060 lucee.runtime.monitor.IntervallMonitor[] monitors = configServer.getIntervallMonitors(); 061 062 int logCount=0; 063 if(monitors!=null)for(int i=0;i<monitors.length;i++){ 064 if(monitors[i].isLogEnabled()) { 065 logCount++; 066 try { 067 monitors[i].log(); 068 } 069 catch (Throwable e) { 070 ExceptionUtil.rethrowIfNecessary(e); 071 e.printStackTrace(); 072 } 073 } 074 } 075 076 if(logCount==0) { 077 tries++; 078 if(tries>=10)return; 079 } 080 } 081 } 082 083}