~mark-matthews-a/connectorj/trunk

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/jmx/LoadBalanceConnectionGroupManager.java

  • Committer: mark.matthews at oracle
  • Date: 2010-05-12 15:38:46 UTC
  • mfrom: (847.1.94 branch_5_1-local)
  • Revision ID: mark.matthews@oracle.com-20100512153846-bdyw3aezw5o1szmu
Merged from 5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 
 
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.
 
8
 
 
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
 
12
  License.
 
13
 
 
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.
 
18
 
 
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
 
22
  02110-1301 USA
 
23
 
 
24
 */
 
25
package com.mysql.jdbc.jmx;
 
26
 
 
27
import java.lang.management.ManagementFactory;
 
28
import java.sql.SQLException;
 
29
 
 
30
import javax.management.MBeanServer;
 
31
import javax.management.ObjectName;
 
32
 
 
33
import com.mysql.jdbc.ConnectionGroupManager;
 
34
import com.mysql.jdbc.SQLError;
 
35
 
 
36
public class LoadBalanceConnectionGroupManager implements
 
37
                LoadBalanceConnectionGroupManagerMBean {
 
38
        
 
39
        private boolean isJmxRegistered = false;
 
40
        
 
41
        public LoadBalanceConnectionGroupManager(){
 
42
 
 
43
        }
 
44
        
 
45
        public synchronized void registerJmx() throws SQLException {
 
46
                if(this.isJmxRegistered){
 
47
                        return;
 
48
                }
 
49
                MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
 
50
                  try {
 
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);
 
56
                } 
 
57
                
 
58
        }
 
59
 
 
60
        public void addHost(String group, String host, boolean forExisting) {
 
61
                try {
 
62
                ConnectionGroupManager.addHost(group, host, forExisting);
 
63
                } catch (Exception e){
 
64
                        e.printStackTrace();
 
65
                }
 
66
        }
 
67
 
 
68
        public int getActiveHostCount(String group) {
 
69
                return ConnectionGroupManager.getActiveHostCount(group);
 
70
        }
 
71
 
 
72
        public long getActiveLogicalConnectionCount(String group) {
 
73
                return ConnectionGroupManager.getActiveLogicalConnectionCount(group);
 
74
        }
 
75
 
 
76
        public long getActivePhysicalConnectionCount(String group) {
 
77
                return ConnectionGroupManager.getActivePhysicalConnectionCount(group);
 
78
        }
 
79
 
 
80
        public int getTotalHostCount(String group) {
 
81
                return ConnectionGroupManager.getTotalHostCount(group);
 
82
 
 
83
        }
 
84
 
 
85
        public long getTotalLogicalConnectionCount(String group) {
 
86
                return ConnectionGroupManager.getTotalLogicalConnectionCount(group);
 
87
 
 
88
        }
 
89
 
 
90
        public long getTotalPhysicalConnectionCount(String group) {
 
91
                return ConnectionGroupManager.getTotalPhysicalConnectionCount(group);
 
92
 
 
93
        }
 
94
 
 
95
        public long getTotalTransactionCount(String group) {
 
96
                return ConnectionGroupManager.getTotalTransactionCount(group);
 
97
 
 
98
        }
 
99
 
 
100
        public void removeHost(String group, String host) throws SQLException {
 
101
                ConnectionGroupManager.removeHost(group, host);
 
102
 
 
103
        }
 
104
 
 
105
        public String getActiveHostsList(String group) {
 
106
                return ConnectionGroupManager.getActiveHostLists(group);
 
107
        }
 
108
 
 
109
        public String getRegisteredConnectionGroups() {
 
110
                return ConnectionGroupManager.getRegisteredConnectionGroups();
 
111
        }
 
112
 
 
113
        public void stopNewConnectionsToHost(String group, String host)
 
114
                        throws SQLException {
 
115
                ConnectionGroupManager.removeHost(group, host);
 
116
                
 
117
        }
 
118
        
 
119
        
 
120
 
 
121
}