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     */
017    package org.apache.commons.monitoring.reporting.web.plugin.jta;
018    
019    import org.apache.commons.monitoring.Role;
020    import org.apache.commons.monitoring.counters.Unit;
021    import org.apache.commons.monitoring.reporting.web.handler.api.Regex;
022    import org.apache.commons.monitoring.reporting.web.handler.api.Template;
023    import org.apache.commons.monitoring.reporting.web.plugin.json.Jsons;
024    import org.apache.commons.monitoring.repositories.Repository;
025    
026    public class JTAEndpoints {
027        // copied to avoid classloading issue depending on the deployment, see org.apache.commons.monitoring.jta.JTAGauges
028        private static final Role COMMITED = new Role("jta-commited", Unit.UNARY);
029        private static final Role ROLLBACKED = new Role("jta-rollbacked", Unit.UNARY);
030        private static final Role ACTIVE = new Role("jta-active", Unit.UNARY);
031    
032        @Regex
033        public Template home() {
034            return new Template("jta/jta.vm");
035        }
036    
037        @Regex("/Commits/([0-9]*)/([0-9]*)")
038        public String commit(final long start, final long end) {
039            return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, COMMITED)) + ", \"label\": \"Commits\", \"color\": \"#317eac\" }";
040        }
041    
042        @Regex("/Rollbacks/([0-9]*)/([0-9]*)")
043        public String rollback(final long start, final long end) {
044            return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ROLLBACKED)) + ", \"label\": \"Rollback\", \"color\": \"#317eac\" }";
045        }
046    
047        @Regex("/Actives/([0-9]*)/([0-9]*)")
048        public String active(final long start, final long end) {
049            return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ACTIVE)) + ", \"label\": \"Active\", \"color\": \"#317eac\" }";
050        }
051    }