Commit 88493d655a1c39a464ae2f88d926e57b8ef6e055
1 parent
0fab1f17
Exists in
master
Ajuste na estrutura de pacotes
Showing
18 changed files
with
940 additions
and
942 deletions
Show diff stats
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/configuration/JMXConfig.java
@@ -1,142 +0,0 @@ | @@ -1,142 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.configuration; | ||
38 | - | ||
39 | -import javax.management.NotificationBroadcaster; | ||
40 | - | ||
41 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
42 | -import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
43 | -import br.gov.frameworkdemoiselle.stereotype.ManagementController; | ||
44 | - | ||
45 | -/** | ||
46 | - * | ||
47 | - * Contains configuration parameters to control how {@link Managed} classes are exposed to the MBean server. | ||
48 | - * | ||
49 | - * To use this class, inject it into your code using the {@link Inject} annotation. | ||
50 | - * | ||
51 | - * ex:<pre><code> | ||
52 | - * | ||
53 | - * public class BusinessClass(){ | ||
54 | - * | ||
55 | - * //... | ||
56 | - * | ||
57 | - * &at;Inject | ||
58 | - * private JMXConfig jmxConfiguration; | ||
59 | - * | ||
60 | - * //... | ||
61 | - * | ||
62 | - * } | ||
63 | - * </code></pre> | ||
64 | - * | ||
65 | - * @author serpro | ||
66 | - * | ||
67 | - */ | ||
68 | -@Configuration(prefix = "frameworkdemoiselle.management.jmx.") | ||
69 | -public class JMXConfig { | ||
70 | - | ||
71 | - @Name("mbean.domain") | ||
72 | - private String mbeanDomain; | ||
73 | - | ||
74 | - @Name("notification.domain") | ||
75 | - private String notificationDomain = "br.gov.frameworkdemoiselle.jmx"; | ||
76 | - | ||
77 | - @Name("notification.name") | ||
78 | - private String notificationMBeanName = "NotificationBroadcaster"; | ||
79 | - | ||
80 | - /** | ||
81 | - * </p>The domain to register all {@link ManagementController} classes found during boot.</p> | ||
82 | - * | ||
83 | - * <p>The full name of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
84 | - * parameter is the "domain" portion of the full name.</p> | ||
85 | - * | ||
86 | - * <p>The default is <code>null</code> and when is set to <code>null</code>, all {@link Managed} classes will use it's own package as the domain.</p> | ||
87 | - * | ||
88 | - */ | ||
89 | - public String getMbeanDomain() { | ||
90 | - return mbeanDomain; | ||
91 | - } | ||
92 | - | ||
93 | - /** | ||
94 | - * @see #getMbeanDomain() | ||
95 | - */ | ||
96 | - public void setMbeanDomain(String mbeanDomain) { | ||
97 | - this.mbeanDomain = mbeanDomain; | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | - * <p>The name the {@link NotificationBroadcaster} MBean will be registered to. The full name | ||
102 | - * of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
103 | - * parameter is the ":name=MBeanName" portion without the ":name=".</p> | ||
104 | - * | ||
105 | - * <p>The default is the value returned by {@link Class#getSimpleName()} when called from the {@link NotificationBroadcaster} class.</p> | ||
106 | - * | ||
107 | - * @see #getMbeanDomain() | ||
108 | - */ | ||
109 | - public String getNotificationMBeanName() { | ||
110 | - return notificationMBeanName; | ||
111 | - } | ||
112 | - | ||
113 | - /** | ||
114 | - * @see #getNotificationMBeanName() | ||
115 | - */ | ||
116 | - public void setNotificationMBeanName(String notificationMBeanName) { | ||
117 | - this.notificationMBeanName = notificationMBeanName; | ||
118 | - } | ||
119 | - | ||
120 | - /** | ||
121 | - * </p>The domain to register the {@link NotificationBroadcaster} MBean.</p> | ||
122 | - * | ||
123 | - * <p>The full name of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
124 | - * parameter is the "domain" portion of the full name.</p> | ||
125 | - * | ||
126 | - * <p>The default is <code>br.gov.frameworkdemoiselle.jmx</code>.</p> | ||
127 | - * | ||
128 | - */ | ||
129 | - public String getNotificationDomain() { | ||
130 | - return notificationDomain; | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * @see #getNotificationDomain() | ||
135 | - */ | ||
136 | - public void setNotificationDomain(String notificationDomain) { | ||
137 | - this.notificationDomain = notificationDomain; | ||
138 | - } | ||
139 | - | ||
140 | - | ||
141 | - | ||
142 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
@@ -1,300 +0,0 @@ | @@ -1,300 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.util.ArrayList; | ||
40 | -import java.util.Locale; | ||
41 | -import java.util.Map.Entry; | ||
42 | - | ||
43 | -import javax.management.Attribute; | ||
44 | -import javax.management.AttributeList; | ||
45 | -import javax.management.AttributeNotFoundException; | ||
46 | -import javax.management.DynamicMBean; | ||
47 | -import javax.management.InvalidAttributeValueException; | ||
48 | -import javax.management.MBeanAttributeInfo; | ||
49 | -import javax.management.MBeanException; | ||
50 | -import javax.management.MBeanInfo; | ||
51 | -import javax.management.MBeanOperationInfo; | ||
52 | -import javax.management.MBeanParameterInfo; | ||
53 | -import javax.management.ReflectionException; | ||
54 | - | ||
55 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
56 | -import br.gov.frameworkdemoiselle.internal.management.ManagedType; | ||
57 | -import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail; | ||
58 | -import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; | ||
59 | -import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail; | ||
60 | -import br.gov.frameworkdemoiselle.internal.management.Management; | ||
61 | -import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; | ||
62 | -import br.gov.frameworkdemoiselle.management.ManagedInvokationException; | ||
63 | -import br.gov.frameworkdemoiselle.stereotype.ManagementController; | ||
64 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
65 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
66 | - | ||
67 | -/** | ||
68 | - * <p> | ||
69 | - * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the | ||
70 | - * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client | ||
71 | - * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate | ||
72 | - * method and pass the result to the MBean client. | ||
73 | - * </p> | ||
74 | - * | ||
75 | - * @author SERPRO | ||
76 | - */ | ||
77 | -public class DynamicMBeanProxy implements DynamicMBean { | ||
78 | - | ||
79 | - private MBeanInfo delegateInfo; | ||
80 | - | ||
81 | - private ManagedType managedType; | ||
82 | - | ||
83 | - private ResourceBundle bundle; | ||
84 | - | ||
85 | - public DynamicMBeanProxy(ManagedType type) { | ||
86 | - if (type == null) { | ||
87 | - throw new NullPointerException(getBundle().getString("mbean-null-type-defined")); | ||
88 | - } | ||
89 | - managedType = type; | ||
90 | - } | ||
91 | - | ||
92 | - @Override | ||
93 | - public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { | ||
94 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
95 | - if (delegateInfo == null) { | ||
96 | - initializeMBeanInfo(); | ||
97 | - } | ||
98 | - | ||
99 | - Management manager = Beans.getReference(Management.class); | ||
100 | - | ||
101 | - try{ | ||
102 | - return manager.getProperty(managedType, attribute); | ||
103 | - } | ||
104 | - catch(DemoiselleException de){ | ||
105 | - if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
106 | - throw new AttributeNotFoundException(de.getMessage()); | ||
107 | - } | ||
108 | - else if (ManagedInvokationException.class.isInstance(de)){ | ||
109 | - throw new MBeanException(new Exception(de.getMessage())); | ||
110 | - } | ||
111 | - else{ | ||
112 | - throw de; | ||
113 | - } | ||
114 | - } | ||
115 | - } | ||
116 | - | ||
117 | - @Override | ||
118 | - public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, | ||
119 | - MBeanException, ReflectionException { | ||
120 | - | ||
121 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
122 | - if (delegateInfo == null) { | ||
123 | - initializeMBeanInfo(); | ||
124 | - } | ||
125 | - | ||
126 | - Management manager = Beans.getReference(Management.class); | ||
127 | - | ||
128 | - try{ | ||
129 | - manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | ||
130 | - } | ||
131 | - catch(DemoiselleException de){ | ||
132 | - if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
133 | - throw new AttributeNotFoundException(de.getMessage()); | ||
134 | - } | ||
135 | - else if (ManagedInvokationException.class.isInstance(de)){ | ||
136 | - throw new MBeanException(new Exception(de.getMessage())); | ||
137 | - } | ||
138 | - else{ | ||
139 | - throw de; | ||
140 | - } | ||
141 | - } | ||
142 | - } | ||
143 | - | ||
144 | - @Override | ||
145 | - public AttributeList getAttributes(String[] attributes) { | ||
146 | - if (attributes != null) { | ||
147 | - AttributeList list = new AttributeList(); | ||
148 | - for (String attribute : attributes) { | ||
149 | - try { | ||
150 | - Object value = getAttribute(attribute); | ||
151 | - list.add(new Attribute(attribute, value)); | ||
152 | - } catch (Throwable t) { | ||
153 | - } | ||
154 | - } | ||
155 | - | ||
156 | - return list; | ||
157 | - } | ||
158 | - | ||
159 | - return null; | ||
160 | - } | ||
161 | - | ||
162 | - @Override | ||
163 | - public AttributeList setAttributes(AttributeList attributes) { | ||
164 | - AttributeList settedAttributes = new AttributeList(); | ||
165 | - if (attributes != null) { | ||
166 | - for (Attribute attribute : attributes.asList()) { | ||
167 | - try { | ||
168 | - setAttribute(attribute); | ||
169 | - | ||
170 | - // A razão para separarmos a criação do atributo de sua adição na lista é que | ||
171 | - // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será | ||
172 | - // adicionado na lista de atributos que foram afetados. | ||
173 | - Attribute attributeWithNewValue = new Attribute(attribute.getName(), | ||
174 | - getAttribute(attribute.getName())); | ||
175 | - settedAttributes.add(attributeWithNewValue); | ||
176 | - } catch (Throwable t) { | ||
177 | - } | ||
178 | - } | ||
179 | - } | ||
180 | - | ||
181 | - return settedAttributes; | ||
182 | - } | ||
183 | - | ||
184 | - @Override | ||
185 | - public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, | ||
186 | - ReflectionException { | ||
187 | - | ||
188 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
189 | - if (this.delegateInfo == null) { | ||
190 | - initializeMBeanInfo(); | ||
191 | - } | ||
192 | - | ||
193 | - Management manager = Beans.getReference(Management.class); | ||
194 | - | ||
195 | - try{ | ||
196 | - return manager.invoke(managedType, actionName, params); | ||
197 | - } | ||
198 | - catch(DemoiselleException de){ | ||
199 | - throw new MBeanException(new Exception(de.getMessage())); | ||
200 | - } | ||
201 | - } | ||
202 | - | ||
203 | - /** | ||
204 | - * Initialize the Managed information for this instance of Managed | ||
205 | - */ | ||
206 | - private void initializeMBeanInfo() { | ||
207 | - // Aqui vamos armazenar nossos atributos | ||
208 | - ArrayList<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(); | ||
209 | - | ||
210 | - // Aqui vamos armazenar nossas operações | ||
211 | - ArrayList<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(); | ||
212 | - | ||
213 | - // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente | ||
214 | - for (Entry<String, FieldDetail> fieldEntry : managedType.getFields().entrySet()) { | ||
215 | - | ||
216 | - try { | ||
217 | - | ||
218 | - MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue() | ||
219 | - .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue() | ||
220 | - .getSetterMethod()); | ||
221 | - attributes.add(attributeInfo); | ||
222 | - | ||
223 | - } catch (javax.management.IntrospectionException e) { | ||
224 | - throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType() | ||
225 | - .getSimpleName())); | ||
226 | - } | ||
227 | - } | ||
228 | - | ||
229 | - // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente | ||
230 | - for (Entry<String, MethodDetail> methodEntry : managedType.getOperationMethods().entrySet()) { | ||
231 | - | ||
232 | - MethodDetail methodDetail = methodEntry.getValue(); | ||
233 | - | ||
234 | - ParameterDetail[] parameterTypes = methodDetail.getParameterTypers(); | ||
235 | - | ||
236 | - MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length] | ||
237 | - : null; | ||
238 | - | ||
239 | - if (parameters != null) { | ||
240 | - | ||
241 | - for (int i = 0; i < parameterTypes.length; i++) { | ||
242 | - | ||
243 | - parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i] | ||
244 | - .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription()); | ||
245 | - } | ||
246 | - } | ||
247 | - | ||
248 | - // Com todas as informações, criamos nossa instância de MBeanOperationInfo e | ||
249 | - // acrescentamos na lista de todas as operações. | ||
250 | - int operationType = 0; | ||
251 | - switch(methodDetail.getType()){ | ||
252 | - case ACTION: | ||
253 | - operationType = MBeanOperationInfo.ACTION; | ||
254 | - break; | ||
255 | - | ||
256 | - case INFO: | ||
257 | - operationType = MBeanOperationInfo.INFO; | ||
258 | - break; | ||
259 | - | ||
260 | - case ACTION_INFO: | ||
261 | - operationType = MBeanOperationInfo.ACTION_INFO; | ||
262 | - break; | ||
263 | - | ||
264 | - default: | ||
265 | - operationType = MBeanOperationInfo.UNKNOWN; | ||
266 | - } | ||
267 | - | ||
268 | - MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(), | ||
269 | - methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(), | ||
270 | - operationType); | ||
271 | - | ||
272 | - operations.add(operation); | ||
273 | - | ||
274 | - } | ||
275 | - | ||
276 | - // Por fim criamos nosso bean info. | ||
277 | - delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(), | ||
278 | - attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]), | ||
279 | - null); | ||
280 | - | ||
281 | - } | ||
282 | - | ||
283 | - @Override | ||
284 | - public MBeanInfo getMBeanInfo() { | ||
285 | - if (delegateInfo == null) { | ||
286 | - initializeMBeanInfo(); | ||
287 | - } | ||
288 | - | ||
289 | - return delegateInfo; | ||
290 | - } | ||
291 | - | ||
292 | - public ResourceBundle getBundle(){ | ||
293 | - if (bundle==null){ | ||
294 | - bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | ||
295 | - } | ||
296 | - | ||
297 | - return bundle; | ||
298 | - } | ||
299 | - | ||
300 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java
@@ -1,104 +0,0 @@ | @@ -1,104 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.util.List; | ||
40 | - | ||
41 | -import javax.management.ObjectInstance; | ||
42 | - | ||
43 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
44 | -import br.gov.frameworkdemoiselle.configuration.JMXConfig; | ||
45 | -import br.gov.frameworkdemoiselle.internal.management.ManagedType; | ||
46 | -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | ||
47 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
48 | - | ||
49 | -public class JMXManagementExtension implements ManagementExtension { | ||
50 | - | ||
51 | - public void registerNotificationMBean(){ | ||
52 | - MBeanManager mbeanManager = Beans.getReference(MBeanManager.class); | ||
53 | - JMXConfig configuration = Beans.getReference(JMXConfig.class); | ||
54 | - | ||
55 | - StringBuffer notificationMBeanName = new StringBuffer() | ||
56 | - .append( configuration.getNotificationDomain()!=null ? configuration.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | ||
57 | - .append(":name=") | ||
58 | - .append(configuration.getNotificationMBeanName()); | ||
59 | - | ||
60 | - if (mbeanManager.findMBeanInstance(notificationMBeanName.toString()) == null){ | ||
61 | - NotificationEventListener listener = Beans.getReference(NotificationEventListener.class); | ||
62 | - | ||
63 | - ObjectInstance instance = MBeanHelper.register(listener.createNotificationBroadcaster(), notificationMBeanName.toString()); | ||
64 | - mbeanManager.storeRegisteredMBean(instance); | ||
65 | - } | ||
66 | - } | ||
67 | - | ||
68 | - @Override | ||
69 | - public void initialize(List<ManagedType> managedTypes) { | ||
70 | - MBeanManager manager = Beans.getReference(MBeanManager.class); | ||
71 | - JMXConfig configuration = Beans.getReference(JMXConfig.class); | ||
72 | - | ||
73 | - for (ManagedType type : managedTypes) { | ||
74 | - DynamicMBeanProxy beanProxy = new DynamicMBeanProxy(type); | ||
75 | - | ||
76 | - Name nameAnnotation = type.getType().getAnnotation(Name.class); | ||
77 | - String mbeanName = nameAnnotation != null ? nameAnnotation.value() : type.getType().getSimpleName(); | ||
78 | - | ||
79 | - StringBuffer name = new StringBuffer() | ||
80 | - .append( configuration.getMbeanDomain()!=null ? configuration.getMbeanDomain() : type.getType().getPackage().getName() ) | ||
81 | - .append(":name=") | ||
82 | - .append( mbeanName ); | ||
83 | - | ||
84 | - | ||
85 | - if (manager.findMBeanInstance(name.toString()) == null){ | ||
86 | - ObjectInstance instance = MBeanHelper.register(beanProxy, name.toString()); | ||
87 | - manager.storeRegisteredMBean(instance); | ||
88 | - } | ||
89 | - } | ||
90 | - | ||
91 | - registerNotificationMBean(); | ||
92 | - } | ||
93 | - | ||
94 | - @Override | ||
95 | - public void shutdown(List<ManagedType> managedTypes) { | ||
96 | - MBeanManager manager = Beans.getReference(MBeanManager.class); | ||
97 | - for (ObjectInstance instance : manager.listRegisteredMBeans()){ | ||
98 | - MBeanHelper.unregister(instance.getObjectName()); | ||
99 | - } | ||
100 | - | ||
101 | - manager.cleanRegisteredMBeans(); | ||
102 | - } | ||
103 | - | ||
104 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanHelper.java
@@ -1,116 +0,0 @@ | @@ -1,116 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.lang.management.ManagementFactory; | ||
40 | -import java.util.Locale; | ||
41 | - | ||
42 | -import javax.management.MBeanServer; | ||
43 | -import javax.management.ObjectInstance; | ||
44 | -import javax.management.ObjectName; | ||
45 | - | ||
46 | -import org.slf4j.Logger; | ||
47 | - | ||
48 | -import br.gov.frameworkdemoiselle.DemoiselleException; | ||
49 | -import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | ||
50 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
51 | - | ||
52 | -/** | ||
53 | - * Class with common tools for registering MBeans into an Managed server | ||
54 | - * | ||
55 | - * @author SERPRO | ||
56 | - */ | ||
57 | -public class MBeanHelper { | ||
58 | - | ||
59 | - private static final Logger logger = LoggerProducer.create(MBeanHelper.class); | ||
60 | - | ||
61 | - private static ResourceBundle bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | ||
62 | - | ||
63 | - private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | ||
64 | - | ||
65 | - /** | ||
66 | - * Return the MBean Server instance. | ||
67 | - * | ||
68 | - * @return MBeanServer | ||
69 | - */ | ||
70 | - public static final MBeanServer getMBeanServer() { | ||
71 | - return server; | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * Register a given managed bean (MBean) with the specified name. | ||
76 | - * | ||
77 | - * @param mbean | ||
78 | - * the managed bean to register | ||
79 | - * @param name | ||
80 | - * the name under which to register the bean | ||
81 | - * @return the object name of the mbean, for later deregistration | ||
82 | - */ | ||
83 | - public static ObjectInstance register(final Object mbean, final String name) { | ||
84 | - | ||
85 | - logger.info(bundle.getString("mbean-registration",name)); | ||
86 | - | ||
87 | - ObjectInstance instance = null; | ||
88 | - try { | ||
89 | - ObjectName objectName = new ObjectName(name); | ||
90 | - instance = server.registerMBean(mbean, objectName); | ||
91 | - } catch (Exception e) { | ||
92 | - logger.error(bundle.getString("mbean-registration-error",name),e); | ||
93 | - throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e); | ||
94 | - } | ||
95 | - | ||
96 | - return instance; | ||
97 | - } | ||
98 | - | ||
99 | - /** | ||
100 | - * Remove the registration of a mbean. | ||
101 | - * | ||
102 | - * @param objectName | ||
103 | - * the name of the bean to unregister | ||
104 | - */ | ||
105 | - public static void unregister(final ObjectName objectName) { | ||
106 | - | ||
107 | - logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName())); | ||
108 | - | ||
109 | - try { | ||
110 | - server.unregisterMBean(objectName); | ||
111 | - } catch (Exception e) { | ||
112 | - logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e); | ||
113 | - throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e); | ||
114 | - } | ||
115 | - } | ||
116 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanManager.java
@@ -1,67 +0,0 @@ | @@ -1,67 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.util.Collection; | ||
40 | -import java.util.HashMap; | ||
41 | - | ||
42 | -import javax.enterprise.context.ApplicationScoped; | ||
43 | -import javax.management.ObjectInstance; | ||
44 | - | ||
45 | -@ApplicationScoped | ||
46 | -public class MBeanManager { | ||
47 | - | ||
48 | - private HashMap<String,ObjectInstance> registeredMBeans = new HashMap<String,ObjectInstance>(); | ||
49 | - | ||
50 | - public void storeRegisteredMBean(ObjectInstance instance){ | ||
51 | - registeredMBeans.put(instance.getObjectName().getCanonicalName(),instance); | ||
52 | - } | ||
53 | - | ||
54 | - public Collection<ObjectInstance> listRegisteredMBeans(){ | ||
55 | - return registeredMBeans.values(); | ||
56 | - } | ||
57 | - | ||
58 | - public ObjectInstance findMBeanInstance(String name){ | ||
59 | - ObjectInstance instance = registeredMBeans.get(name); | ||
60 | - return instance; | ||
61 | - } | ||
62 | - | ||
63 | - public void cleanRegisteredMBeans(){ | ||
64 | - registeredMBeans.clear(); | ||
65 | - } | ||
66 | - | ||
67 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcaster.java
@@ -1,82 +0,0 @@ | @@ -1,82 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.io.Serializable; | ||
40 | - | ||
41 | -import javax.management.AttributeChangeNotification; | ||
42 | -import javax.management.Notification; | ||
43 | -import javax.management.NotificationBroadcasterSupport; | ||
44 | - | ||
45 | -import br.gov.frameworkdemoiselle.configuration.JMXConfig; | ||
46 | -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
47 | -import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
48 | - | ||
49 | -/** | ||
50 | - * Implementation of the {@link NotificationBroadcaster} MBean. | ||
51 | - * When the {@link NotificationManager} sends an event, a {@link NotificationEventListener} captures the notification and uses | ||
52 | - * this MBean to send it as a JMX notification. | ||
53 | - * | ||
54 | - * @author serpro | ||
55 | - * | ||
56 | - */ | ||
57 | -public final class NotificationBroadcaster extends NotificationBroadcasterSupport implements NotificationBroadcasterMBean,Serializable { | ||
58 | - | ||
59 | - private static final long serialVersionUID = 1L; | ||
60 | - | ||
61 | - private int sequenceNumber = 1; | ||
62 | - | ||
63 | - private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; | ||
64 | - | ||
65 | - protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { | ||
66 | - br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); | ||
67 | - Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); | ||
68 | - sendNotification(n); | ||
69 | - } | ||
70 | - | ||
71 | - protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) { | ||
72 | - br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification(); | ||
73 | - | ||
74 | - AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++ | ||
75 | - , System.currentTimeMillis(), demoiselleNotification.getMessage().toString() | ||
76 | - , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName() | ||
77 | - , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue()); | ||
78 | - | ||
79 | - sendNotification(n); | ||
80 | - } | ||
81 | - | ||
82 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcasterMBean.java
@@ -1,48 +0,0 @@ | @@ -1,48 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | - | ||
40 | - | ||
41 | -/** | ||
42 | - * MBean interface responsible for sending MBean notifications to remote clients. | ||
43 | - * | ||
44 | - * @author serpro | ||
45 | - * | ||
46 | - */ | ||
47 | -public interface NotificationBroadcasterMBean { | ||
48 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationEventListener.java
@@ -1,80 +0,0 @@ | @@ -1,80 +0,0 @@ | ||
1 | -/* | ||
2 | - * Demoiselle Framework | ||
3 | - * Copyright (C) 2010 SERPRO | ||
4 | - * ---------------------------------------------------------------------------- | ||
5 | - * This file is part of Demoiselle Framework. | ||
6 | - * | ||
7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | - * as published by the Free Software Foundation. | ||
10 | - * | ||
11 | - * This program is distributed in the hope that it will be useful, | ||
12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | - * GNU General Public License for more details. | ||
15 | - * | ||
16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | - * ---------------------------------------------------------------------------- | ||
21 | - * Este arquivo é parte do Framework Demoiselle. | ||
22 | - * | ||
23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | - * do Software Livre (FSF). | ||
26 | - * | ||
27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | - * para maiores detalhes. | ||
31 | - * | ||
32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | - */ | ||
37 | -package br.gov.frameworkdemoiselle.internal; | ||
38 | - | ||
39 | -import java.io.Serializable; | ||
40 | - | ||
41 | -import javax.enterprise.context.ApplicationScoped; | ||
42 | -import javax.enterprise.event.Observes; | ||
43 | - | ||
44 | -import br.gov.frameworkdemoiselle.configuration.JMXConfig; | ||
45 | -import br.gov.frameworkdemoiselle.internal.management.qualifier.AttributeChange; | ||
46 | -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | ||
47 | -import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
48 | -import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
49 | - | ||
50 | -/** | ||
51 | - * Listens to {@link NotificationManager} notification events and proxies them | ||
52 | - * to a {@link NotificationBroadcaster} MBean. This MBean will send the notification to | ||
53 | - * any JMX clients connected and listening. | ||
54 | - * | ||
55 | - * @author serpro | ||
56 | - * | ||
57 | - */ | ||
58 | -@ApplicationScoped | ||
59 | -@SuppressWarnings("serial") | ||
60 | -public class NotificationEventListener implements Serializable { | ||
61 | - | ||
62 | - private NotificationBroadcaster notificationBroadcaster; | ||
63 | - | ||
64 | - public void sendNotification( @Observes @Generic ManagementNotificationEvent event , JMXConfig config ) { | ||
65 | - createNotificationBroadcaster().sendNotification(event,config); | ||
66 | - } | ||
67 | - | ||
68 | - public void sendAttributeChangedMessage( @Observes @AttributeChange ManagementNotificationEvent event , JMXConfig config ) { | ||
69 | - createNotificationBroadcaster().sendAttributeChangedMessage(event, config); | ||
70 | - } | ||
71 | - | ||
72 | - public NotificationBroadcaster createNotificationBroadcaster(){ | ||
73 | - if (notificationBroadcaster==null){ | ||
74 | - notificationBroadcaster = new NotificationBroadcaster(); | ||
75 | - } | ||
76 | - | ||
77 | - return notificationBroadcaster; | ||
78 | - } | ||
79 | - | ||
80 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JMXConfig.java
0 → 100644
@@ -0,0 +1,142 @@ | @@ -0,0 +1,142 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.configuration; | ||
38 | + | ||
39 | +import javax.management.NotificationBroadcaster; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
42 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
43 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | ||
44 | + | ||
45 | +/** | ||
46 | + * | ||
47 | + * Contains configuration parameters to control how {@link Managed} classes are exposed to the MBean server. | ||
48 | + * | ||
49 | + * To use this class, inject it into your code using the {@link Inject} annotation. | ||
50 | + * | ||
51 | + * ex:<pre><code> | ||
52 | + * | ||
53 | + * public class BusinessClass(){ | ||
54 | + * | ||
55 | + * //... | ||
56 | + * | ||
57 | + * &at;Inject | ||
58 | + * private JMXConfig jmxConfiguration; | ||
59 | + * | ||
60 | + * //... | ||
61 | + * | ||
62 | + * } | ||
63 | + * </code></pre> | ||
64 | + * | ||
65 | + * @author serpro | ||
66 | + * | ||
67 | + */ | ||
68 | +@Configuration(prefix = "frameworkdemoiselle.management.jmx") | ||
69 | +public class JMXConfig { | ||
70 | + | ||
71 | + @Name("mbean.domain") | ||
72 | + private String mbeanDomain; | ||
73 | + | ||
74 | + @Name("notification.domain") | ||
75 | + private String notificationDomain = "br.gov.frameworkdemoiselle.jmx"; | ||
76 | + | ||
77 | + @Name("notification.name") | ||
78 | + private String notificationMBeanName = "NotificationBroadcaster"; | ||
79 | + | ||
80 | + /** | ||
81 | + * </p>The domain to register all {@link ManagementController} classes found during boot.</p> | ||
82 | + * | ||
83 | + * <p>The full name of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
84 | + * parameter is the "domain" portion of the full name.</p> | ||
85 | + * | ||
86 | + * <p>The default is <code>null</code> and when is set to <code>null</code>, all {@link Managed} classes will use it's own package as the domain.</p> | ||
87 | + * | ||
88 | + */ | ||
89 | + public String getMbeanDomain() { | ||
90 | + return mbeanDomain; | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * @see #getMbeanDomain() | ||
95 | + */ | ||
96 | + public void setMbeanDomain(String mbeanDomain) { | ||
97 | + this.mbeanDomain = mbeanDomain; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * <p>The name the {@link NotificationBroadcaster} MBean will be registered to. The full name | ||
102 | + * of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
103 | + * parameter is the ":name=MBeanName" portion without the ":name=".</p> | ||
104 | + * | ||
105 | + * <p>The default is the value returned by {@link Class#getSimpleName()} when called from the {@link NotificationBroadcaster} class.</p> | ||
106 | + * | ||
107 | + * @see #getMbeanDomain() | ||
108 | + */ | ||
109 | + public String getNotificationMBeanName() { | ||
110 | + return notificationMBeanName; | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * @see #getNotificationMBeanName() | ||
115 | + */ | ||
116 | + public void setNotificationMBeanName(String notificationMBeanName) { | ||
117 | + this.notificationMBeanName = notificationMBeanName; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * </p>The domain to register the {@link NotificationBroadcaster} MBean.</p> | ||
122 | + * | ||
123 | + * <p>The full name of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | ||
124 | + * parameter is the "domain" portion of the full name.</p> | ||
125 | + * | ||
126 | + * <p>The default is <code>br.gov.frameworkdemoiselle.jmx</code>.</p> | ||
127 | + * | ||
128 | + */ | ||
129 | + public String getNotificationDomain() { | ||
130 | + return notificationDomain; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * @see #getNotificationDomain() | ||
135 | + */ | ||
136 | + public void setNotificationDomain(String notificationDomain) { | ||
137 | + this.notificationDomain = notificationDomain; | ||
138 | + } | ||
139 | + | ||
140 | + | ||
141 | + | ||
142 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/JMXManagementExtension.java
0 → 100644
@@ -0,0 +1,104 @@ | @@ -0,0 +1,104 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import java.util.List; | ||
40 | + | ||
41 | +import javax.management.ObjectInstance; | ||
42 | + | ||
43 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
44 | +import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; | ||
45 | +import br.gov.frameworkdemoiselle.internal.proxy.DynamicMBeanProxy; | ||
46 | +import br.gov.frameworkdemoiselle.management.ManagementExtension; | ||
47 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
48 | + | ||
49 | +public class JMXManagementExtension implements ManagementExtension { | ||
50 | + | ||
51 | + public void registerNotificationMBean(){ | ||
52 | + MBeanManager mbeanManager = Beans.getReference(MBeanManager.class); | ||
53 | + JMXConfig configuration = Beans.getReference(JMXConfig.class); | ||
54 | + | ||
55 | + StringBuffer notificationMBeanName = new StringBuffer() | ||
56 | + .append( configuration.getNotificationDomain()!=null ? configuration.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | ||
57 | + .append(":name=") | ||
58 | + .append(configuration.getNotificationMBeanName()); | ||
59 | + | ||
60 | + if (mbeanManager.findMBeanInstance(notificationMBeanName.toString()) == null){ | ||
61 | + NotificationEventListener listener = Beans.getReference(NotificationEventListener.class); | ||
62 | + | ||
63 | + ObjectInstance instance = MBeanHelper.register(listener.createNotificationBroadcaster(), notificationMBeanName.toString()); | ||
64 | + mbeanManager.storeRegisteredMBean(instance); | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public void initialize(List<ManagedType> managedTypes) { | ||
70 | + MBeanManager manager = Beans.getReference(MBeanManager.class); | ||
71 | + JMXConfig configuration = Beans.getReference(JMXConfig.class); | ||
72 | + | ||
73 | + for (ManagedType type : managedTypes) { | ||
74 | + DynamicMBeanProxy beanProxy = new DynamicMBeanProxy(type); | ||
75 | + | ||
76 | + Name nameAnnotation = type.getType().getAnnotation(Name.class); | ||
77 | + String mbeanName = nameAnnotation != null ? nameAnnotation.value() : type.getType().getSimpleName(); | ||
78 | + | ||
79 | + StringBuffer name = new StringBuffer() | ||
80 | + .append( configuration.getMbeanDomain()!=null ? configuration.getMbeanDomain() : type.getType().getPackage().getName() ) | ||
81 | + .append(":name=") | ||
82 | + .append( mbeanName ); | ||
83 | + | ||
84 | + | ||
85 | + if (manager.findMBeanInstance(name.toString()) == null){ | ||
86 | + ObjectInstance instance = MBeanHelper.register(beanProxy, name.toString()); | ||
87 | + manager.storeRegisteredMBean(instance); | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + registerNotificationMBean(); | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void shutdown(List<ManagedType> managedTypes) { | ||
96 | + MBeanManager manager = Beans.getReference(MBeanManager.class); | ||
97 | + for (ObjectInstance instance : manager.listRegisteredMBeans()){ | ||
98 | + MBeanHelper.unregister(instance.getObjectName()); | ||
99 | + } | ||
100 | + | ||
101 | + manager.cleanRegisteredMBeans(); | ||
102 | + } | ||
103 | + | ||
104 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanHelper.java
0 → 100644
@@ -0,0 +1,116 @@ | @@ -0,0 +1,116 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import java.lang.management.ManagementFactory; | ||
40 | +import java.util.Locale; | ||
41 | + | ||
42 | +import javax.management.MBeanServer; | ||
43 | +import javax.management.ObjectInstance; | ||
44 | +import javax.management.ObjectName; | ||
45 | + | ||
46 | +import org.slf4j.Logger; | ||
47 | + | ||
48 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
49 | +import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | ||
50 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
51 | + | ||
52 | +/** | ||
53 | + * Class with common tools for registering MBeans into an Managed server | ||
54 | + * | ||
55 | + * @author SERPRO | ||
56 | + */ | ||
57 | +public class MBeanHelper { | ||
58 | + | ||
59 | + private static final Logger logger = LoggerProducer.create(MBeanHelper.class); | ||
60 | + | ||
61 | + private static ResourceBundle bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | ||
62 | + | ||
63 | + private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | ||
64 | + | ||
65 | + /** | ||
66 | + * Return the MBean Server instance. | ||
67 | + * | ||
68 | + * @return MBeanServer | ||
69 | + */ | ||
70 | + public static final MBeanServer getMBeanServer() { | ||
71 | + return server; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Register a given managed bean (MBean) with the specified name. | ||
76 | + * | ||
77 | + * @param mbean | ||
78 | + * the managed bean to register | ||
79 | + * @param name | ||
80 | + * the name under which to register the bean | ||
81 | + * @return the object name of the mbean, for later deregistration | ||
82 | + */ | ||
83 | + public static ObjectInstance register(final Object mbean, final String name) { | ||
84 | + | ||
85 | + logger.info(bundle.getString("mbean-registration",name)); | ||
86 | + | ||
87 | + ObjectInstance instance = null; | ||
88 | + try { | ||
89 | + ObjectName objectName = new ObjectName(name); | ||
90 | + instance = server.registerMBean(mbean, objectName); | ||
91 | + } catch (Exception e) { | ||
92 | + logger.error(bundle.getString("mbean-registration-error",name),e); | ||
93 | + throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e); | ||
94 | + } | ||
95 | + | ||
96 | + return instance; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Remove the registration of a mbean. | ||
101 | + * | ||
102 | + * @param objectName | ||
103 | + * the name of the bean to unregister | ||
104 | + */ | ||
105 | + public static void unregister(final ObjectName objectName) { | ||
106 | + | ||
107 | + logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName())); | ||
108 | + | ||
109 | + try { | ||
110 | + server.unregisterMBean(objectName); | ||
111 | + } catch (Exception e) { | ||
112 | + logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e); | ||
113 | + throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e); | ||
114 | + } | ||
115 | + } | ||
116 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MBeanManager.java
0 → 100644
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import java.util.Collection; | ||
40 | +import java.util.HashMap; | ||
41 | + | ||
42 | +import javax.enterprise.context.ApplicationScoped; | ||
43 | +import javax.management.ObjectInstance; | ||
44 | + | ||
45 | +@ApplicationScoped | ||
46 | +public class MBeanManager { | ||
47 | + | ||
48 | + private HashMap<String,ObjectInstance> registeredMBeans = new HashMap<String,ObjectInstance>(); | ||
49 | + | ||
50 | + public void storeRegisteredMBean(ObjectInstance instance){ | ||
51 | + registeredMBeans.put(instance.getObjectName().getCanonicalName(),instance); | ||
52 | + } | ||
53 | + | ||
54 | + public Collection<ObjectInstance> listRegisteredMBeans(){ | ||
55 | + return registeredMBeans.values(); | ||
56 | + } | ||
57 | + | ||
58 | + public ObjectInstance findMBeanInstance(String name){ | ||
59 | + ObjectInstance instance = registeredMBeans.get(name); | ||
60 | + return instance; | ||
61 | + } | ||
62 | + | ||
63 | + public void cleanRegisteredMBeans(){ | ||
64 | + registeredMBeans.clear(); | ||
65 | + } | ||
66 | + | ||
67 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcaster.java
0 → 100644
@@ -0,0 +1,82 @@ | @@ -0,0 +1,82 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import java.io.Serializable; | ||
40 | + | ||
41 | +import javax.management.AttributeChangeNotification; | ||
42 | +import javax.management.Notification; | ||
43 | +import javax.management.NotificationBroadcasterSupport; | ||
44 | + | ||
45 | +import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; | ||
46 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
47 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
48 | + | ||
49 | +/** | ||
50 | + * Implementation of the {@link NotificationBroadcaster} MBean. | ||
51 | + * When the {@link NotificationManager} sends an event, a {@link NotificationEventListener} captures the notification and uses | ||
52 | + * this MBean to send it as a JMX notification. | ||
53 | + * | ||
54 | + * @author serpro | ||
55 | + * | ||
56 | + */ | ||
57 | +public final class NotificationBroadcaster extends NotificationBroadcasterSupport implements NotificationBroadcasterMBean,Serializable { | ||
58 | + | ||
59 | + private static final long serialVersionUID = 1L; | ||
60 | + | ||
61 | + private int sequenceNumber = 1; | ||
62 | + | ||
63 | + private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; | ||
64 | + | ||
65 | + protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { | ||
66 | + br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); | ||
67 | + Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); | ||
68 | + sendNotification(n); | ||
69 | + } | ||
70 | + | ||
71 | + protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) { | ||
72 | + br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification(); | ||
73 | + | ||
74 | + AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++ | ||
75 | + , System.currentTimeMillis(), demoiselleNotification.getMessage().toString() | ||
76 | + , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName() | ||
77 | + , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue()); | ||
78 | + | ||
79 | + sendNotification(n); | ||
80 | + } | ||
81 | + | ||
82 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationBroadcasterMBean.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | +/** | ||
42 | + * MBean interface responsible for sending MBean notifications to remote clients. | ||
43 | + * | ||
44 | + * @author serpro | ||
45 | + * | ||
46 | + */ | ||
47 | +public interface NotificationBroadcasterMBean { | ||
48 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/NotificationEventListener.java
0 → 100644
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import java.io.Serializable; | ||
40 | + | ||
41 | +import javax.enterprise.context.ApplicationScoped; | ||
42 | +import javax.enterprise.event.Observes; | ||
43 | + | ||
44 | +import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; | ||
45 | +import br.gov.frameworkdemoiselle.management.ManagementNotificationEvent; | ||
46 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | ||
47 | + | ||
48 | +/** | ||
49 | + * Listens to {@link NotificationManager} notification events and proxies them | ||
50 | + * to a {@link NotificationBroadcaster} MBean. This MBean will send the notification to | ||
51 | + * any JMX clients connected and listening. | ||
52 | + * | ||
53 | + * @author serpro | ||
54 | + * | ||
55 | + */ | ||
56 | +@ApplicationScoped | ||
57 | +@SuppressWarnings("serial") | ||
58 | +public class NotificationEventListener implements Serializable { | ||
59 | + | ||
60 | + private NotificationBroadcaster notificationBroadcaster; | ||
61 | + | ||
62 | + public void sendNotification( @Observes @Generic ManagementNotificationEvent event , JMXConfig config ) { | ||
63 | + createNotificationBroadcaster().sendNotification(event,config); | ||
64 | + } | ||
65 | + | ||
66 | + public void sendAttributeChangedMessage( @Observes @AttributeChange ManagementNotificationEvent event , JMXConfig config ) { | ||
67 | + createNotificationBroadcaster().sendAttributeChangedMessage(event, config); | ||
68 | + } | ||
69 | + | ||
70 | + public NotificationBroadcaster createNotificationBroadcaster(){ | ||
71 | + if (notificationBroadcaster==null){ | ||
72 | + notificationBroadcaster = new NotificationBroadcaster(); | ||
73 | + } | ||
74 | + | ||
75 | + return notificationBroadcaster; | ||
76 | + } | ||
77 | + | ||
78 | +} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/DynamicMBeanProxy.java
0 → 100644
@@ -0,0 +1,300 @@ | @@ -0,0 +1,300 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.internal.proxy; | ||
38 | + | ||
39 | +import java.util.ArrayList; | ||
40 | +import java.util.Locale; | ||
41 | +import java.util.Map.Entry; | ||
42 | + | ||
43 | +import javax.management.Attribute; | ||
44 | +import javax.management.AttributeList; | ||
45 | +import javax.management.AttributeNotFoundException; | ||
46 | +import javax.management.DynamicMBean; | ||
47 | +import javax.management.InvalidAttributeValueException; | ||
48 | +import javax.management.MBeanAttributeInfo; | ||
49 | +import javax.management.MBeanException; | ||
50 | +import javax.management.MBeanInfo; | ||
51 | +import javax.management.MBeanOperationInfo; | ||
52 | +import javax.management.MBeanParameterInfo; | ||
53 | +import javax.management.ReflectionException; | ||
54 | + | ||
55 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
56 | +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType; | ||
57 | +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.FieldDetail; | ||
58 | +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.MethodDetail; | ||
59 | +import br.gov.frameworkdemoiselle.internal.implementation.ManagedType.ParameterDetail; | ||
60 | +import br.gov.frameworkdemoiselle.internal.implementation.Management; | ||
61 | +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException; | ||
62 | +import br.gov.frameworkdemoiselle.management.ManagedInvokationException; | ||
63 | +import br.gov.frameworkdemoiselle.stereotype.ManagementController; | ||
64 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
65 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
66 | + | ||
67 | +/** | ||
68 | + * <p> | ||
69 | + * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the | ||
70 | + * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client | ||
71 | + * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate | ||
72 | + * method and pass the result to the MBean client. | ||
73 | + * </p> | ||
74 | + * | ||
75 | + * @author SERPRO | ||
76 | + */ | ||
77 | +public class DynamicMBeanProxy implements DynamicMBean { | ||
78 | + | ||
79 | + private MBeanInfo delegateInfo; | ||
80 | + | ||
81 | + private ManagedType managedType; | ||
82 | + | ||
83 | + private ResourceBundle bundle; | ||
84 | + | ||
85 | + public DynamicMBeanProxy(ManagedType type) { | ||
86 | + if (type == null) { | ||
87 | + throw new NullPointerException(getBundle().getString("mbean-null-type-defined")); | ||
88 | + } | ||
89 | + managedType = type; | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { | ||
94 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
95 | + if (delegateInfo == null) { | ||
96 | + initializeMBeanInfo(); | ||
97 | + } | ||
98 | + | ||
99 | + Management manager = Beans.getReference(Management.class); | ||
100 | + | ||
101 | + try{ | ||
102 | + return manager.getProperty(managedType, attribute); | ||
103 | + } | ||
104 | + catch(DemoiselleException de){ | ||
105 | + if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
106 | + throw new AttributeNotFoundException(de.getMessage()); | ||
107 | + } | ||
108 | + else if (ManagedInvokationException.class.isInstance(de)){ | ||
109 | + throw new MBeanException(new Exception(de.getMessage())); | ||
110 | + } | ||
111 | + else{ | ||
112 | + throw de; | ||
113 | + } | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + @Override | ||
118 | + public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, | ||
119 | + MBeanException, ReflectionException { | ||
120 | + | ||
121 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
122 | + if (delegateInfo == null) { | ||
123 | + initializeMBeanInfo(); | ||
124 | + } | ||
125 | + | ||
126 | + Management manager = Beans.getReference(Management.class); | ||
127 | + | ||
128 | + try{ | ||
129 | + manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | ||
130 | + } | ||
131 | + catch(DemoiselleException de){ | ||
132 | + if (ManagedAttributeNotFoundException.class.isInstance(de)){ | ||
133 | + throw new AttributeNotFoundException(de.getMessage()); | ||
134 | + } | ||
135 | + else if (ManagedInvokationException.class.isInstance(de)){ | ||
136 | + throw new MBeanException(new Exception(de.getMessage())); | ||
137 | + } | ||
138 | + else{ | ||
139 | + throw de; | ||
140 | + } | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + @Override | ||
145 | + public AttributeList getAttributes(String[] attributes) { | ||
146 | + if (attributes != null) { | ||
147 | + AttributeList list = new AttributeList(); | ||
148 | + for (String attribute : attributes) { | ||
149 | + try { | ||
150 | + Object value = getAttribute(attribute); | ||
151 | + list.add(new Attribute(attribute, value)); | ||
152 | + } catch (Throwable t) { | ||
153 | + } | ||
154 | + } | ||
155 | + | ||
156 | + return list; | ||
157 | + } | ||
158 | + | ||
159 | + return null; | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public AttributeList setAttributes(AttributeList attributes) { | ||
164 | + AttributeList settedAttributes = new AttributeList(); | ||
165 | + if (attributes != null) { | ||
166 | + for (Attribute attribute : attributes.asList()) { | ||
167 | + try { | ||
168 | + setAttribute(attribute); | ||
169 | + | ||
170 | + // A razão para separarmos a criação do atributo de sua adição na lista é que | ||
171 | + // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será | ||
172 | + // adicionado na lista de atributos que foram afetados. | ||
173 | + Attribute attributeWithNewValue = new Attribute(attribute.getName(), | ||
174 | + getAttribute(attribute.getName())); | ||
175 | + settedAttributes.add(attributeWithNewValue); | ||
176 | + } catch (Throwable t) { | ||
177 | + } | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + return settedAttributes; | ||
182 | + } | ||
183 | + | ||
184 | + @Override | ||
185 | + public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, | ||
186 | + ReflectionException { | ||
187 | + | ||
188 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | ||
189 | + if (this.delegateInfo == null) { | ||
190 | + initializeMBeanInfo(); | ||
191 | + } | ||
192 | + | ||
193 | + Management manager = Beans.getReference(Management.class); | ||
194 | + | ||
195 | + try{ | ||
196 | + return manager.invoke(managedType, actionName, params); | ||
197 | + } | ||
198 | + catch(DemoiselleException de){ | ||
199 | + throw new MBeanException(new Exception(de.getMessage())); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Initialize the Managed information for this instance of Managed | ||
205 | + */ | ||
206 | + private void initializeMBeanInfo() { | ||
207 | + // Aqui vamos armazenar nossos atributos | ||
208 | + ArrayList<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(); | ||
209 | + | ||
210 | + // Aqui vamos armazenar nossas operações | ||
211 | + ArrayList<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(); | ||
212 | + | ||
213 | + // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente | ||
214 | + for (Entry<String, FieldDetail> fieldEntry : managedType.getFields().entrySet()) { | ||
215 | + | ||
216 | + try { | ||
217 | + | ||
218 | + MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue() | ||
219 | + .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue() | ||
220 | + .getSetterMethod()); | ||
221 | + attributes.add(attributeInfo); | ||
222 | + | ||
223 | + } catch (javax.management.IntrospectionException e) { | ||
224 | + throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType() | ||
225 | + .getSimpleName())); | ||
226 | + } | ||
227 | + } | ||
228 | + | ||
229 | + // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente | ||
230 | + for (Entry<String, MethodDetail> methodEntry : managedType.getOperationMethods().entrySet()) { | ||
231 | + | ||
232 | + MethodDetail methodDetail = methodEntry.getValue(); | ||
233 | + | ||
234 | + ParameterDetail[] parameterTypes = methodDetail.getParameterTypers(); | ||
235 | + | ||
236 | + MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length] | ||
237 | + : null; | ||
238 | + | ||
239 | + if (parameters != null) { | ||
240 | + | ||
241 | + for (int i = 0; i < parameterTypes.length; i++) { | ||
242 | + | ||
243 | + parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i] | ||
244 | + .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription()); | ||
245 | + } | ||
246 | + } | ||
247 | + | ||
248 | + // Com todas as informações, criamos nossa instância de MBeanOperationInfo e | ||
249 | + // acrescentamos na lista de todas as operações. | ||
250 | + int operationType = 0; | ||
251 | + switch(methodDetail.getType()){ | ||
252 | + case ACTION: | ||
253 | + operationType = MBeanOperationInfo.ACTION; | ||
254 | + break; | ||
255 | + | ||
256 | + case INFO: | ||
257 | + operationType = MBeanOperationInfo.INFO; | ||
258 | + break; | ||
259 | + | ||
260 | + case ACTION_INFO: | ||
261 | + operationType = MBeanOperationInfo.ACTION_INFO; | ||
262 | + break; | ||
263 | + | ||
264 | + default: | ||
265 | + operationType = MBeanOperationInfo.UNKNOWN; | ||
266 | + } | ||
267 | + | ||
268 | + MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(), | ||
269 | + methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(), | ||
270 | + operationType); | ||
271 | + | ||
272 | + operations.add(operation); | ||
273 | + | ||
274 | + } | ||
275 | + | ||
276 | + // Por fim criamos nosso bean info. | ||
277 | + delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(), | ||
278 | + attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]), | ||
279 | + null); | ||
280 | + | ||
281 | + } | ||
282 | + | ||
283 | + @Override | ||
284 | + public MBeanInfo getMBeanInfo() { | ||
285 | + if (delegateInfo == null) { | ||
286 | + initializeMBeanInfo(); | ||
287 | + } | ||
288 | + | ||
289 | + return delegateInfo; | ||
290 | + } | ||
291 | + | ||
292 | + public ResourceBundle getBundle(){ | ||
293 | + if (bundle==null){ | ||
294 | + bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | ||
295 | + } | ||
296 | + | ||
297 | + return bundle; | ||
298 | + } | ||
299 | + | ||
300 | +} |
impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
@@ -55,7 +55,7 @@ import org.junit.BeforeClass; | @@ -55,7 +55,7 @@ import org.junit.BeforeClass; | ||
55 | import org.junit.Test; | 55 | import org.junit.Test; |
56 | import org.junit.runner.RunWith; | 56 | import org.junit.runner.RunWith; |
57 | 57 | ||
58 | -import br.gov.frameworkdemoiselle.internal.MBeanManager; | 58 | +import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager; |
59 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 59 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
60 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | 60 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
61 | import br.gov.frameworkdemoiselle.util.Beans; | 61 | import br.gov.frameworkdemoiselle.util.Beans; |
impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
@@ -57,8 +57,8 @@ import org.junit.BeforeClass; | @@ -57,8 +57,8 @@ import org.junit.BeforeClass; | ||
57 | import org.junit.Test; | 57 | import org.junit.Test; |
58 | import org.junit.runner.RunWith; | 58 | import org.junit.runner.RunWith; |
59 | 59 | ||
60 | -import br.gov.frameworkdemoiselle.configuration.JMXConfig; | ||
61 | -import br.gov.frameworkdemoiselle.internal.MBeanManager; | 60 | +import br.gov.frameworkdemoiselle.internal.configuration.JMXConfig; |
61 | +import br.gov.frameworkdemoiselle.internal.implementation.MBeanManager; | ||
62 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | 62 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
63 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | 63 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
64 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | 64 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |