KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javax > management > support > StandardMBeanSupport


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package test.javax.management.support;
10
11 import javax.management.MBeanAttributeInfo JavaDoc;
12 import javax.management.MBeanConstructorInfo JavaDoc;
13 import javax.management.MBeanInfo JavaDoc;
14 import javax.management.MBeanOperationInfo JavaDoc;
15 import javax.management.MBeanParameterInfo JavaDoc;
16 import javax.management.NotCompliantMBeanException JavaDoc;
17 import javax.management.StandardMBean JavaDoc;
18
19 import test.MutableInteger;
20
21 /**
22  * @version $Revision: 1.5 $
23  */

24 public class StandardMBeanSupport
25 {
26    /**
27     * No management interface and it is not a standard MBean
28     */

29    public static class SubclassNotCompliant extends StandardMBean JavaDoc
30    {
31       public SubclassNotCompliant() throws NotCompliantMBeanException JavaDoc
32       {
33          super(null);
34       }
35    }
36
37    /**
38     * Valid StandardMBean with a standard MBean as implementation
39     */

40    public static class SubclassWithNoManagement extends StandardMBean JavaDoc implements SubclassWithNoManagementMBean
41    {
42       public SubclassWithNoManagement() throws NotCompliantMBeanException JavaDoc
43       {
44          super(null);
45       }
46
47       public Object JavaDoc test()
48       {
49          return new Object JavaDoc();
50       }
51    }
52
53    public interface SubclassWithNoManagementMBean
54    {
55       public Object JavaDoc test();
56    }
57
58    public static class SubclassWithManagement extends StandardMBean JavaDoc implements Management
59    {
60       public SubclassWithManagement() throws NotCompliantMBeanException JavaDoc
61       {
62          super(Management.class);
63       }
64
65       public void cannotCall()
66       {
67       }
68
69       public Object JavaDoc test()
70       {
71          return new Object JavaDoc();
72       }
73    }
74
75    public interface Management
76    {
77       public Object JavaDoc test();
78    }
79
80    public static class ImplementationWithNoManagement implements ImplementationWithNoManagementMBean
81    {
82       public Object JavaDoc test()
83       {
84          return new Object JavaDoc();
85       }
86    }
87
88    public interface ImplementationWithNoManagementMBean
89    {
90       public Object JavaDoc test();
91    }
92
93    public static class ImplementationWithManagement implements Management
94    {
95       public Object JavaDoc test()
96       {
97          return new Object JavaDoc();
98       }
99    }
100
101    public interface FullManagement
102    {
103       public void setAttrib(int i);
104
105       public void operation(int i);
106    }
107
108    public interface PublicInterfaceMBean
109    {
110       public Object JavaDoc test();
111    }
112
113    private static class PublicInterface implements PublicInterfaceMBean
114    {
115       public PublicInterface()
116       {
117       }
118
119       public Object JavaDoc test()
120       {
121          return new Object JavaDoc();
122       }
123    }
124
125    public static PublicInterfaceMBean createPublicInterfaceMBean()
126    {
127       return new PublicInterface();
128    }
129
130
131    public static class CallbackCounter extends StandardMBean JavaDoc implements FullManagement
132    {
133       private MutableInteger count;
134
135       public CallbackCounter(int dummy) throws NotCompliantMBeanException JavaDoc
136       {
137          // Variable dummy only serves to enable the callback on the constructor parameter
138
super(FullManagement.class);
139       }
140
141       public void setAttrib(int i)
142       {
143       }
144
145       public void operation(int i)
146       {
147       }
148
149       public int getCount()
150       {
151          return count.get();
152       }
153
154       protected String JavaDoc getClassName(MBeanInfo JavaDoc info)
155       {
156          increment();
157          return super.getClassName(info);
158       }
159
160       protected String JavaDoc getDescription(MBeanInfo JavaDoc info)
161       {
162          increment();
163          return super.getDescription(info);
164       }
165
166       protected String JavaDoc getDescription(MBeanAttributeInfo JavaDoc info)
167       {
168          increment();
169          return super.getDescription(info);
170       }
171
172       protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc info)
173       {
174          increment();
175          return super.getDescription(info);
176       }
177
178       protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc info)
179       {
180          increment();
181          return super.getDescription(info);
182       }
183
184       protected String JavaDoc getDescription(MBeanConstructorInfo JavaDoc constructor, MBeanParameterInfo JavaDoc param, int sequence)
185       {
186          increment();
187          return super.getDescription(constructor, param, sequence);
188       }
189
190       protected String JavaDoc getDescription(MBeanOperationInfo JavaDoc operation, MBeanParameterInfo JavaDoc param, int sequence)
191       {
192          increment();
193          return super.getDescription(operation, param, sequence);
194       }
195
196       protected String JavaDoc getParameterName(MBeanConstructorInfo JavaDoc constructor, MBeanParameterInfo JavaDoc param, int sequence)
197       {
198          increment();
199          return super.getParameterName(constructor, param, sequence);
200       }
201
202       protected String JavaDoc getParameterName(MBeanOperationInfo JavaDoc operation, MBeanParameterInfo JavaDoc param, int sequence)
203       {
204          increment();
205          return super.getParameterName(operation, param, sequence);
206       }
207
208       protected int getImpact(MBeanOperationInfo JavaDoc info)
209       {
210          increment();
211          return super.getImpact(info);
212       }
213
214       private void increment()
215       {
216          if (count == null) count = new MutableInteger(0);
217          count.set(count.get() + 1);
218       }
219
220    }
221
222 }
223
Popular Tags