001 package org.apache.fulcrum.yaafi.interceptor.jamon; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import com.jamonapi.Monitor; 023 import com.jamonapi.MonitorFactory; 024 import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl; 025 026 import java.lang.reflect.Method; 027 028 /** 029 * Ecapsulating the JAMon 1.x related API calls 030 * 031 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 032 */ 033 034 public class Jamon1PerformanceMonitorImpl implements JamonPerformanceMonitor 035 { 036 /** is monitoring enabled */ 037 private boolean isActive; 038 039 /** the method currenty monitored */ 040 private Method method; 041 042 /** the global JAMON monitor */ 043 private Monitor monitor; 044 045 /** 046 * Constructor. 047 * 048 * @param serviceName the service name of the service being monitored 049 * @param method the method to be monitored 050 * @param isActive is this an active monitor 051 */ 052 public Jamon1PerformanceMonitorImpl(String serviceName, Method method, Boolean isActive) { 053 this.method = method; 054 this.isActive = isActive.booleanValue(); 055 } 056 057 /** 058 * Start the monitor. 059 */ 060 public void start() 061 { 062 if(this.isActive) 063 { 064 MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0); 065 String methodSignature = methodToStringBuilder.toString(); 066 this.monitor = MonitorFactory.start(methodSignature); 067 } 068 } 069 070 /** 071 * Start the monitor. 072 */ 073 public void stop() 074 { 075 if(this.isActive) 076 { 077 this.monitor.stop(); 078 } 079 } 080 081 /** 082 * Stop the monitor based on an Throwable. 083 */ 084 public void stop(Throwable throwable) 085 { 086 this.stop(); 087 } 088 089 /** 090 * Create a performance report 091 */ 092 public String createReport() throws Exception 093 { 094 return MonitorFactory.getRootMonitor().getReport(); 095 } 096 }