View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.monitoring.reporting.web.plugin.jta;
18  
19  import org.apache.commons.monitoring.Role;
20  import org.apache.commons.monitoring.counters.Unit;
21  import org.apache.commons.monitoring.reporting.web.handler.api.Regex;
22  import org.apache.commons.monitoring.reporting.web.handler.api.Template;
23  import org.apache.commons.monitoring.reporting.web.plugin.json.Jsons;
24  import org.apache.commons.monitoring.repositories.Repository;
25  
26  public class JTAEndpoints {
27      // copied to avoid classloading issue depending on the deployment, see org.apache.commons.monitoring.jta.JTAGauges
28      private static final Role COMMITED = new Role("jta-commited", Unit.UNARY);
29      private static final Role ROLLBACKED = new Role("jta-rollbacked", Unit.UNARY);
30      private static final Role ACTIVE = new Role("jta-active", Unit.UNARY);
31  
32      @Regex
33      public Template home() {
34          return new Template("jta/jta.vm");
35      }
36  
37      @Regex("/Commits/([0-9]*)/([0-9]*)")
38      public String commit(final long start, final long end) {
39          return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, COMMITED)) + ", \"label\": \"Commits\", \"color\": \"#317eac\" }";
40      }
41  
42      @Regex("/Rollbacks/([0-9]*)/([0-9]*)")
43      public String rollback(final long start, final long end) {
44          return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ROLLBACKED)) + ", \"label\": \"Rollback\", \"color\": \"#317eac\" }";
45      }
46  
47      @Regex("/Actives/([0-9]*)/([0-9]*)")
48      public String active(final long start, final long end) {
49          return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ACTIVE)) + ", \"label\": \"Active\", \"color\": \"#317eac\" }";
50      }
51  }