001package org.javasimon.jmx;
002
003import java.beans.ConstructorProperties;
004
005/**
006 * Value object for retrieving Simon name and type info via Simon MXBean ({@link SimonManagerMXBean}).
007 * This value object make possible to retrieve list of all instantiated Simons together with
008 * their types, so no multiple roundtrips are needed.
009 * <p/>
010 * Example: Following example shows usage of SimonInfo object to find out Simon type through jmx.
011 * <pre>
012 * System.out.println("List of stopwatch Simons:");
013 * for (SimonInfo si : simon.getSimonInfos()) {
014 * if (si.getType().equals(SimonInfo.STOPWATCH)) {
015 * System.out.println("  " + si.getName());
016 * }
017 * }</pre>
018 *
019 * @author Radovan Sninsky
020 * @author <a href="mailto:virgo47@gmail.com">Richard "Virgo" Richter</a>
021 * @see SimonManagerMXBean#getSimonInfos
022 * @since 2.0
023 */
024public final class SimonInfo {
025
026        /** Type identifier for unknown Simon. */
027        public static final String UNKNOWN = "Unknown";
028
029        /** Type identifier for Stopwatch. */
030        public static final String STOPWATCH = "Stopwatch";
031
032        /** Type identifier for Counter. */
033        public static final String COUNTER = "Counter";
034
035        private String name;
036        private String type;
037
038        /**
039         * Class constructor due to JMX requirements.
040         *
041         * @param name Simon name
042         * @param type Simon type ({@code 'stopwatch'} or {@code 'counter'})
043         */
044        @ConstructorProperties({"name", "type"})
045        public SimonInfo(String name, String type) {
046                this.name = name;
047                this.type = type;
048        }
049
050        /**
051         * Returns fully hierarchical name of Simon.
052         *
053         * @return Simon name
054         */
055        public String getName() {
056                return name;
057        }
058
059        /**
060         * Returns Simon type, either {@code 'stopwatch'} or {@code 'counter'} strings.
061         *
062         * @return Simon type
063         * @see org.javasimon.jmx.SimonInfo#UNKNOWN
064         * @see org.javasimon.jmx.SimonInfo#STOPWATCH
065         * @see org.javasimon.jmx.SimonInfo#COUNTER
066         */
067        public String getType() {
068                return type;
069        }
070}