1 | /* |
2 | Copyright (C) 2004 MySQL AB |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License version 2 as |
6 | published by the Free Software Foundation. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 | |
17 | */ |
18 | package com.mysql.management.jmx.jboss; |
19 | |
20 | import javax.management.MBeanOperationInfo; |
21 | import javax.management.ReflectionException; |
22 | |
23 | import com.mysql.management.MysqldResourceI; |
24 | import com.mysql.management.jmx.SimpleMysqldDynamicMBean; |
25 | import com.mysql.management.util.Exceptions; |
26 | |
27 | public final class JBossMysqldDynamicMBean extends SimpleMysqldDynamicMBean { |
28 | static final String CREATE_METHOD = "create"; |
29 | |
30 | static final String DESTROY_METHOD = "destroy"; |
31 | |
32 | private MBeanOperationInfo createMethod; |
33 | |
34 | private MBeanOperationInfo destroyMethod; |
35 | |
36 | public JBossMysqldDynamicMBean() { |
37 | super(); |
38 | initOps(); |
39 | } |
40 | |
41 | JBossMysqldDynamicMBean(MysqldResourceI mysqldResource) { |
42 | super(mysqldResource); |
43 | initOps(); |
44 | } |
45 | |
46 | private void initOps() { |
47 | createMethod = newVoidMBeanOperation(CREATE_METHOD, |
48 | "Create MySQL MBean"); |
49 | destroyMethod = newVoidMBeanOperation(DESTROY_METHOD, |
50 | "Destroy MySQL MBean"); |
51 | getMBeanOperationInfoList().add(createMethod); |
52 | getMBeanOperationInfoList().add(destroyMethod); |
53 | } |
54 | |
55 | public synchronized Object invoke(String methodName, Object args[], |
56 | String types[]) throws ReflectionException { |
57 | |
58 | clearMBeanInfo(); |
59 | |
60 | if (methodName.equals(CREATE_METHOD)) { |
61 | create(); |
62 | return null; |
63 | } |
64 | |
65 | if (methodName.equals(DESTROY_METHOD)) { |
66 | destroy(); |
67 | return null; |
68 | } |
69 | |
70 | return super.invoke(methodName, args, types); |
71 | } |
72 | |
73 | public void create() { |
74 | Exceptions.VoidBlock block = new Exceptions.VoidBlock() { |
75 | public void inner() throws Exception { |
76 | String autoStart = "" + getAttribute(AUTOSTART_ATTR); |
77 | autoStart = autoStart.toLowerCase(); |
78 | if (autoStart.equals(Boolean.TRUE.toString())) { |
79 | invoke(START_METHOD, null, null); |
80 | } |
81 | } |
82 | }; |
83 | block.exec(); |
84 | } |
85 | |
86 | public void destroy() { |
87 | Exceptions.VoidBlock block = new Exceptions.VoidBlock() { |
88 | public void inner() throws ReflectionException { |
89 | invoke(STOP_METHOD, null, null); |
90 | } |
91 | }; |
92 | block.exec(); |
93 | } |
94 | } |