001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jmx.export.metadata;
018
019import org.springframework.jmx.support.MetricType;
020import org.springframework.lang.Nullable;
021import org.springframework.util.Assert;
022
023/**
024 * Metadata that indicates to expose a given bean property as a JMX attribute,
025 * with additional descriptor properties that indicate that the attribute is a
026 * metric. Only valid when used on a JavaBean getter.
027 *
028 * @author Jennifer Hickey
029 * @since 3.0
030 * @see org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler
031 */
032public class ManagedMetric extends AbstractJmxAttribute {
033
034        @Nullable
035        private String category;
036
037        @Nullable
038        private String displayName;
039
040        private MetricType metricType = MetricType.GAUGE;
041
042        private int persistPeriod = -1;
043
044        @Nullable
045        private String persistPolicy;
046
047        @Nullable
048        private String unit;
049
050
051        /**
052         * The category of this metric (ex. throughput, performance, utilization).
053         */
054        public void setCategory(@Nullable String category) {
055                this.category = category;
056        }
057
058        /**
059         * The category of this metric (ex. throughput, performance, utilization).
060         */
061        @Nullable
062        public String getCategory() {
063                return this.category;
064        }
065
066        /**
067         * A display name for this metric.
068         */
069        public void setDisplayName(@Nullable String displayName) {
070                this.displayName = displayName;
071        }
072
073        /**
074         * A display name for this metric.
075         */
076        @Nullable
077        public String getDisplayName() {
078                return this.displayName;
079        }
080
081        /**
082         * A description of how this metric's values change over time.
083         */
084        public void setMetricType(MetricType metricType) {
085                Assert.notNull(metricType, "MetricType must not be null");
086                this.metricType = metricType;
087        }
088
089        /**
090         * A description of how this metric's values change over time.
091         */
092        public MetricType getMetricType() {
093                return this.metricType;
094        }
095
096        /**
097         * The persist period for this metric.
098         */
099        public void setPersistPeriod(int persistPeriod) {
100                this.persistPeriod = persistPeriod;
101        }
102
103        /**
104         * The persist period for this metric.
105         */
106        public int getPersistPeriod() {
107                return this.persistPeriod;
108        }
109
110        /**
111         * The persist policy for this metric.
112         */
113        public void setPersistPolicy(@Nullable String persistPolicy) {
114                this.persistPolicy = persistPolicy;
115        }
116
117        /**
118         * The persist policy for this metric.
119         */
120        @Nullable
121        public String getPersistPolicy() {
122                return this.persistPolicy;
123        }
124
125        /**
126         * The expected unit of measurement values.
127         */
128        public void setUnit(@Nullable String unit) {
129                this.unit = unit;
130        }
131
132        /**
133         * The expected unit of measurement values.
134         */
135        @Nullable
136        public String getUnit() {
137                return this.unit;
138        }
139
140}