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, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package info.globalcode.sql.dk.jmx;
19 import java.util.EnumMap;
23 * JMX management bean for progress reporting.
25 * @author Ing. František Kučera (frantovo.cz)
27 public class ConnectionManagement implements ConnectionManagementMBean {
29 private final String databaseName;
30 private final Map<COUNTER, Integer> counters = new EnumMap(COUNTER.class);
32 public ConnectionManagement(String databaseName) {
33 this.databaseName = databaseName;
34 for (COUNTER c : COUNTER.values()) {
46 public void incrementCounter(COUNTER counter) {
47 synchronized (counters) {
48 int old = counters.get(counter);
49 counters.put(counter, old + 1);
53 public void resetCounter(COUNTER counter) {
54 synchronized (counters) {
55 counters.put(counter, 0);
59 public static void incrementCounter(ConnectionManagement mbean, COUNTER counter) {
61 mbean.incrementCounter(counter);
65 public static void resetCounter(ConnectionManagement mbean, COUNTER counter) {
67 mbean.resetCounter(counter);
72 public String getDatabaseName() {
77 public int getCommandCount() {
78 synchronized (counters) {
79 return counters.get(COUNTER.COMMAND);
84 public int getCurrentRecordCount() {
85 synchronized (counters) {
86 return counters.get(COUNTER.RECORD_CURRENT);
91 public int getTotalRecordCount() {
92 synchronized (counters) {
93 return counters.get(COUNTER.RECORD_TOTAL);