3 * Copyright © 2014 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk.jmx;
20 import java.util.EnumMap;
24 * JMX management bean for progress reporting.
26 * @author Ing. František Kučera (frantovo.cz)
28 public class ConnectionManagement implements ConnectionManagementMBean {
30 private final String databaseName;
31 private final Map<COUNTER, Integer> counters = new EnumMap(COUNTER.class);
33 public ConnectionManagement(String databaseName) {
34 this.databaseName = databaseName;
35 for (COUNTER c : COUNTER.values()) {
47 public void incrementCounter(COUNTER counter) {
48 synchronized (counters) {
49 int old = counters.get(counter);
50 counters.put(counter, old + 1);
54 public void resetCounter(COUNTER counter) {
55 synchronized (counters) {
56 counters.put(counter, 0);
60 public static void incrementCounter(ConnectionManagement mbean, COUNTER counter) {
62 mbean.incrementCounter(counter);
66 public static void resetCounter(ConnectionManagement mbean, COUNTER counter) {
68 mbean.resetCounter(counter);
73 public String getDatabaseName() {
78 public int getCommandCount() {
79 synchronized (counters) {
80 return counters.get(COUNTER.COMMAND);
85 public int getCurrentRecordCount() {
86 synchronized (counters) {
87 return counters.get(COUNTER.RECORD_CURRENT);
92 public int getTotalRecordCount() {
93 synchronized (counters) {
94 return counters.get(COUNTER.RECORD_TOTAL);