2
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4
The MySQL Connector/J is licensed under the terms of the GPL,
5
like most MySQL Connectors. There are special exceptions to the
6
terms and conditions of the GPL as it is applied to this software,
7
see the FLOSS License Exception available on mysql.com.
9
This program is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License as
11
published by the Free Software Foundation; version 2 of the
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25
package com.mysql.jdbc.jmx;
27
import java.lang.management.ManagementFactory;
28
import java.sql.SQLException;
30
import javax.management.MBeanServer;
31
import javax.management.ObjectName;
33
import com.mysql.jdbc.ConnectionGroupManager;
34
import com.mysql.jdbc.SQLError;
36
public class LoadBalanceConnectionGroupManager implements
37
LoadBalanceConnectionGroupManagerMBean {
39
private boolean isJmxRegistered = false;
41
public LoadBalanceConnectionGroupManager(){
45
public synchronized void registerJmx() throws SQLException {
46
if(this.isJmxRegistered){
49
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
51
ObjectName name = new ObjectName("com.mysql.jdbc.jmx:type=LoadBalanceConnectionGroupManager");
52
mbs.registerMBean(this, name);
53
this.isJmxRegistered = true;
54
} catch (Exception e) {
55
throw SQLError.createSQLException("Uable to register load-balance management bean with JMX", null, e, null);
60
public void addHost(String group, String host, boolean forExisting) {
62
ConnectionGroupManager.addHost(group, host, forExisting);
63
} catch (Exception e){
68
public int getActiveHostCount(String group) {
69
return ConnectionGroupManager.getActiveHostCount(group);
72
public long getActiveLogicalConnectionCount(String group) {
73
return ConnectionGroupManager.getActiveLogicalConnectionCount(group);
76
public long getActivePhysicalConnectionCount(String group) {
77
return ConnectionGroupManager.getActivePhysicalConnectionCount(group);
80
public int getTotalHostCount(String group) {
81
return ConnectionGroupManager.getTotalHostCount(group);
85
public long getTotalLogicalConnectionCount(String group) {
86
return ConnectionGroupManager.getTotalLogicalConnectionCount(group);
90
public long getTotalPhysicalConnectionCount(String group) {
91
return ConnectionGroupManager.getTotalPhysicalConnectionCount(group);
95
public long getTotalTransactionCount(String group) {
96
return ConnectionGroupManager.getTotalTransactionCount(group);
100
public void removeHost(String group, String host) throws SQLException {
101
ConnectionGroupManager.removeHost(group, host);
105
public String getActiveHostsList(String group) {
106
return ConnectionGroupManager.getActiveHostLists(group);
109
public String getRegisteredConnectionGroups() {
110
return ConnectionGroupManager.getRegisteredConnectionGroups();
113
public void stopNewConnectionsToHost(String group, String host)
114
throws SQLException {
115
ConnectionGroupManager.removeHost(group, host);