001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.metrics;
018
019import com.codahale.metrics.MetricRegistry;
020import com.codahale.metrics.jmx.JmxReporter;
021
022/**
023 * Settings to configure wicket metrics
024 * 
025 * @author Tobias Soloschenko
026 *
027 */
028public class WicketMetricsSettings
029{
030
031        private boolean enabled = true;
032
033        private String prefix = "application/";
034
035        /**
036         * If the metrics should be enabled
037         * 
038         * @param enabled
039         *            if the metrics should be enabled
040         */
041        public void setEnabled(boolean enabled)
042        {
043                this.enabled = enabled;
044        }
045
046        /**
047         * If the wicket metrics are enabled
048         * 
049         * @return if the wicket metrics are enabled
050         */
051        public boolean isEnabled()
052        {
053                return enabled;
054        }
055
056        /**
057         * Gets the prefix.
058         * 
059         * @return the prefix
060         */
061        public String getPrefix()
062        {
063                return prefix;
064        }
065
066        /**
067         * Sets the prefix to be used for the statistics
068         * 
069         * @param prefix
070         *            the prefix to be used
071         */
072        public void setPrefix(String prefix)
073        {
074                if (!prefix.endsWith("/"))
075                {
076                        prefix = prefix + "/";
077                }
078                this.prefix = prefix;
079        }
080
081        /**
082         * Starts the jmx reporter
083         */
084        public void startJmxReporter()
085        {
086                MetricRegistry metricRegistry = WicketMetrics.getMetricRegistry();
087                JmxReporter.forRegistry(metricRegistry).build().start();
088        }
089
090        /**
091         * Stops the jmx reporter
092         */
093        public void stopJmxReporter()
094        {
095                MetricRegistry metricRegistry = WicketMetrics.getMetricRegistry();
096                JmxReporter.forRegistry(metricRegistry).build().stop();
097        }
098}