Commit fc362946338ac2f66488cbeed3a81f7789e84de5
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
36 changed files
with
1484 additions
and
1076 deletions
Show diff stats
impl/extension/jdbc/pom.xml
... | ... | @@ -34,8 +34,7 @@ |
34 | 34 | ou escreva para a Fundação do Software Livre (FSF) Inc., |
35 | 35 | 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
36 | 36 | --> |
37 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
38 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
37 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
39 | 38 | |
40 | 39 | <modelVersion>4.0.0</modelVersion> |
41 | 40 | |
... | ... | @@ -89,78 +88,23 @@ |
89 | 88 | <artifactId>shrinkwrap-resolver-impl-maven</artifactId> |
90 | 89 | <scope>test</scope> |
91 | 90 | </dependency> |
91 | + <dependency> | |
92 | + <groupId>org.jboss.arquillian.container</groupId> | |
93 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | |
94 | + <scope>test</scope> | |
95 | + </dependency> | |
96 | + <dependency> | |
97 | + <groupId>org.glassfish.main.extras</groupId> | |
98 | + <artifactId>glassfish-embedded-all</artifactId> | |
99 | + <scope>test</scope> | |
100 | + </dependency> | |
101 | + <dependency> | |
102 | + <groupId>hsqldb</groupId> | |
103 | + <artifactId>hsqldb</artifactId> | |
104 | + <scope>test</scope> | |
105 | + </dependency> | |
92 | 106 | </dependencies> |
93 | 107 | |
94 | - <build> | |
95 | - <testResources> | |
96 | - <testResource> | |
97 | - <directory>src/test/resources</directory> | |
98 | - <filtering>true</filtering> | |
99 | - </testResource> | |
100 | - </testResources> | |
101 | - <plugins> | |
102 | - <plugin> | |
103 | - <artifactId>maven-dependency-plugin</artifactId> | |
104 | - <executions> | |
105 | - <execution> | |
106 | - <id>unpack</id> | |
107 | - <phase>process-test-classes</phase> | |
108 | - <goals> | |
109 | - <goal>unpack</goal> | |
110 | - </goals> | |
111 | - <configuration> | |
112 | - <artifactItems> | |
113 | - <artifactItem> | |
114 | - <groupId>org.jboss.as</groupId> | |
115 | - <artifactId>jboss-as-dist</artifactId> | |
116 | - <version>${jbossas.version}</version> | |
117 | - <type>zip</type> | |
118 | - <overWrite>false</overWrite> | |
119 | - <outputDirectory>target</outputDirectory> | |
120 | - </artifactItem> | |
121 | - </artifactItems> | |
122 | - </configuration> | |
123 | - </execution> | |
124 | - </executions> | |
125 | - </plugin> | |
126 | - | |
127 | - <plugin> | |
128 | - <groupId>org.apache.maven.plugins</groupId> | |
129 | - <artifactId>maven-surefire-plugin</artifactId> | |
130 | - <version>2.16</version> | |
131 | - </plugin> | |
132 | - </plugins> | |
133 | - <pluginManagement> | |
134 | - <plugins> | |
135 | - <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> | |
136 | - <plugin> | |
137 | - <groupId>org.eclipse.m2e</groupId> | |
138 | - <artifactId>lifecycle-mapping</artifactId> | |
139 | - <version>1.0.0</version> | |
140 | - <configuration> | |
141 | - <lifecycleMappingMetadata> | |
142 | - <pluginExecutions> | |
143 | - <pluginExecution> | |
144 | - <pluginExecutionFilter> | |
145 | - <groupId>org.apache.maven.plugins</groupId> | |
146 | - <artifactId>maven-dependency-plugin</artifactId> | |
147 | - <versionRange>[2.1,)</versionRange> | |
148 | - <goals> | |
149 | - <goal>unpack</goal> | |
150 | - </goals> | |
151 | - </pluginExecutionFilter> | |
152 | - <action> | |
153 | - <ignore></ignore> | |
154 | - </action> | |
155 | - </pluginExecution> | |
156 | - </pluginExecutions> | |
157 | - </lifecycleMappingMetadata> | |
158 | - </configuration> | |
159 | - </plugin> | |
160 | - </plugins> | |
161 | - </pluginManagement> | |
162 | - </build> | |
163 | - | |
164 | 108 | <repositories> |
165 | 109 | <repository> |
166 | 110 | <id>sonatype-nexus-snapshots</id> |
... | ... | @@ -185,11 +129,10 @@ |
185 | 129 | </releases> |
186 | 130 | </repository> |
187 | 131 | </repositories> |
188 | - | |
132 | + | |
189 | 133 | <profiles> |
190 | 134 | <profile> |
191 | 135 | <id>arquillian-test</id> |
192 | - | |
193 | 136 | <dependencies> |
194 | 137 | <dependency> |
195 | 138 | <groupId>br.gov.frameworkdemoiselle</groupId> |
... | ... | @@ -207,24 +150,13 @@ |
207 | 150 | <groupId>org.slf4j</groupId> |
208 | 151 | <artifactId>slf4j-api</artifactId> |
209 | 152 | </exclusion> |
210 | - <!-- | |
211 | - --> | |
212 | 153 | <exclusion> |
213 | 154 | <groupId>org.javassist</groupId> |
214 | 155 | <artifactId>javassist</artifactId> |
215 | 156 | </exclusion> |
216 | 157 | </exclusions> |
217 | 158 | </dependency> |
218 | - <dependency> | |
219 | - <groupId>org.eclipse.persistence</groupId> | |
220 | - <artifactId>javax.persistence</artifactId> | |
221 | - <scope>provided</scope> | |
222 | - </dependency> | |
223 | 159 | </dependencies> |
224 | 160 | </profile> |
225 | 161 | </profiles> |
226 | - | |
227 | - <properties> | |
228 | - <jbossas.version>7.1.1.Final</jbossas.version> | |
229 | - </properties> | |
230 | 162 | </project> | ... | ... |
impl/extension/jdbc/src/test/java/test/Tests.java
... | ... | @@ -65,7 +65,7 @@ public final class Tests { |
65 | 65 | return createDeployment().addPackages(true, baseClass.getPackage()); |
66 | 66 | } |
67 | 67 | |
68 | - public static WebArchive createDeployment() { | |
68 | + private static WebArchive createDeployment() { | |
69 | 69 | File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test") |
70 | 70 | .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile(); |
71 | 71 | |
... | ... | @@ -80,8 +80,7 @@ public final class Tests { |
80 | 80 | .addClass(JDBCTransaction.class) |
81 | 81 | .addAsResource(createFileAsset("src/main/resources/demoiselle-jdbc-bundle.properties"), |
82 | 82 | "demoiselle-jdbc-bundle.properties") |
83 | -// .addAsResource(createFileAsset("src/test/resources/logging.properties"), "logging.properties") | |
84 | - .addAsWebInfResource(createFileAsset("src/test/resources/META-INF/beans.xml"), "beans.xml") | |
83 | + .addAsWebInfResource(createFileAsset("src/test/resources/test/beans.xml"), "beans.xml") | |
85 | 84 | .addAsLibraries(libs); |
86 | 85 | } |
87 | 86 | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +package xxx; | |
2 | + | |
3 | +import static junit.framework.Assert.assertNotNull; | |
4 | + | |
5 | +import java.sql.Connection; | |
6 | + | |
7 | +import javax.inject.Inject; | |
8 | + | |
9 | +import org.jboss.arquillian.container.test.api.Deployment; | |
10 | +import org.jboss.arquillian.junit.Arquillian; | |
11 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
12 | +import org.junit.Test; | |
13 | +import org.junit.runner.RunWith; | |
14 | + | |
15 | +import test.Tests; | |
16 | + | |
17 | +@RunWith(Arquillian.class) | |
18 | +public class XTest { | |
19 | + | |
20 | + private static final String PATH = "src/test/resources/xxx"; | |
21 | + | |
22 | + @Inject | |
23 | + private Connection conn; | |
24 | + | |
25 | + @Deployment | |
26 | + public static WebArchive createDeployment() { | |
27 | + WebArchive deployment = Tests.createDeployment(XTest.class); | |
28 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), | |
29 | + "demoiselle.properties"); | |
30 | + | |
31 | + return deployment; | |
32 | + } | |
33 | + | |
34 | + @Test | |
35 | + public void x() { | |
36 | + assertNotNull(conn); | |
37 | + } | |
38 | +} | ... | ... |
impl/extension/jdbc/src/test/resources/META-INF/beans.xml
... | ... | @@ -1,40 +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 | -<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
38 | - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
39 | - | |
40 | -</beans> | |
41 | 0 | \ No newline at end of file |
impl/extension/jdbc/src/test/resources/arquillian.xml
... | ... | @@ -43,58 +43,11 @@ |
43 | 43 | <property name="deploymentExportPath">target/deployments</property> |
44 | 44 | </engine> |
45 | 45 | |
46 | - <container qualifier="jbossas-managed" default="true"> | |
47 | - <protocol type="Servlet 3.0" /> | |
48 | - | |
49 | - <configuration> | |
50 | - <property name="jbossHome">target/jboss-as-7.1.1.Final</property> | |
51 | - <property name="javaHome">/usr/lib/jvm/java-6-sun/</property> | |
52 | - <!-- | |
53 | - <property name="serverConfig">../../../../src/test/resources/standalone.xml</property> | |
54 | - --> | |
55 | - </configuration> | |
56 | - </container> | |
57 | - <!-- | |
58 | - <container qualifier="jbossas-managed" default="true"> | |
59 | - <configuration> | |
60 | - <property name="jbossHome">target/jboss-as-${jbossas.version}</property> | |
61 | - <property name="javaVmArguments">-Djboss.socket.binding.port-offset=10000 -Xmx512m -XX:MaxPermSize=128m</property> | |
62 | - </configuration> | |
63 | - </container> | |
64 | - --> | |
65 | - <!-- | |
66 | - <container qualifier="jbossas-managed" default="true"> | |
67 | - <configuration> | |
68 | - <property name="javaHome">/usr/lib/jvm/java-6-serpro/</property> | |
69 | - <property name="jbossHome">/opt/demoiselle/server/jboss-7.1/</property> | |
70 | - </configuration> | |
71 | - </container> | |
72 | - --> | |
73 | - | |
74 | - <!-- | |
75 | 46 | <container qualifier="glassfish-embedded" default="true"> |
76 | 47 | <configuration> |
77 | 48 | <property name="resourcesXml">src/test/resources/glassfish-resources.xml</property> |
49 | +<!-- <property name="resourcesXml">${project.testResources}/glassfish-resources.xml</property> --> | |
78 | 50 | </configuration> |
79 | 51 | </container> |
80 | - --> | |
81 | - | |
82 | - <!-- | |
83 | - <container qualifier="tomee" default="true"> | |
84 | - <configuration> | |
85 | - <property name="httpPort">-1</property> | |
86 | - <property name="stopPort">-1</property> | |
87 | - </configuration> | |
88 | - </container> | |
89 | - --> | |
90 | - | |
91 | - <!-- | |
92 | - <container qualifier="jbossas-embedded" default="true"> | |
93 | - <configuration> | |
94 | - <property name="bindaddress">127.0.0.1</property> | |
95 | - <property name="httpport">8081</property> | |
96 | - </configuration> | |
97 | - </container> | |
98 | - --> | |
99 | 52 | |
100 | 53 | </arquillian> |
101 | 54 | \ No newline at end of file | ... | ... |
impl/extension/jdbc/src/test/resources/demoiselle.properties
impl/extension/jdbc/src/test/resources/glassfish-resources.xml
0 → 100644
... | ... | @@ -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 | +<!DOCTYPE resources PUBLIC | |
38 | + "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" | |
39 | + "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> | |
40 | +<resources> | |
41 | + <jdbc-resource pool-name="ArquillianEmbeddedDerbyPool" jndi-name="jdbc/arquillian" /> | |
42 | + | |
43 | + <jdbc-connection-pool name="ArquillianEmbeddedDerbyPool" res-type="javax.sql.DataSource" datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" | |
44 | + is-isolation-level-guaranteed="false"> | |
45 | + <property name="databaseName" value="target/databases/derby" /> | |
46 | + <property name="createDatabase" value="create" /> | |
47 | + </jdbc-connection-pool> | |
48 | +</resources> | |
0 | 49 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,46 @@ |
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 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
38 | + | |
39 | + <interceptors> | |
40 | + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | |
41 | + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | |
42 | + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | |
43 | + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | |
44 | + </interceptors> | |
45 | + | |
46 | +</beans> | ... | ... |
impl/extension/jdbc/src/test/resources/xxx/demoiselle.properties
0 → 100644
... | ... | @@ -0,0 +1,39 @@ |
1 | +# Demoiselle Framework | |
2 | +# Copyright (C) 2010 SERPRO | |
3 | +# ---------------------------------------------------------------------------- | |
4 | +# This file is part of Demoiselle Framework. | |
5 | +# | |
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
8 | +# as published by the Free Software Foundation. | |
9 | +# | |
10 | +# This program is distributed in the hope that it will be useful, | |
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | +# ---------------------------------------------------------------------------- | |
20 | +# Este arquivo é parte do Framework Demoiselle. | |
21 | +# | |
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
24 | +# do Software Livre (FSF). | |
25 | +# | |
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
29 | +# para maiores detalhes. | |
30 | +# | |
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
35 | + | |
36 | +frameworkdemoiselle.persistence.driver.class=org.hsqldb.jdbcDriver | |
37 | +frameworkdemoiselle.persistence.url=jdbc:hsqldb:mem:xxx | |
38 | +frameworkdemoiselle.persistence.username=sa | |
39 | +frameworkdemoiselle.persistence.password= | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/configuration/JMXConfig.java
0 → 100644
... | ... | @@ -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.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
0 → 100644
... | ... | @@ -0,0 +1,264 @@ |
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.stereotype.ManagementController; | |
62 | +import br.gov.frameworkdemoiselle.util.Beans; | |
63 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
64 | + | |
65 | +/** | |
66 | + * <p> | |
67 | + * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the | |
68 | + * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client | |
69 | + * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate | |
70 | + * method and pass the result to the MBean client. | |
71 | + * </p> | |
72 | + * | |
73 | + * @author SERPRO | |
74 | + */ | |
75 | +public class DynamicMBeanProxy implements DynamicMBean { | |
76 | + | |
77 | + private MBeanInfo delegateInfo; | |
78 | + | |
79 | + private ManagedType managedType; | |
80 | + | |
81 | + private ResourceBundle bundle; | |
82 | + | |
83 | + public DynamicMBeanProxy(ManagedType type) { | |
84 | + if (type == null) { | |
85 | + throw new NullPointerException(getBundle().getString("mbean-null-type-defined")); | |
86 | + } | |
87 | + managedType = type; | |
88 | + } | |
89 | + | |
90 | + @Override | |
91 | + public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { | |
92 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
93 | + if (delegateInfo == null) { | |
94 | + initializeMBeanInfo(); | |
95 | + } | |
96 | + | |
97 | + Management manager = Beans.getReference(Management.class); | |
98 | + return manager.getProperty(managedType, attribute); | |
99 | + } | |
100 | + | |
101 | + @Override | |
102 | + public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, | |
103 | + MBeanException, ReflectionException { | |
104 | + | |
105 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
106 | + if (delegateInfo == null) { | |
107 | + initializeMBeanInfo(); | |
108 | + } | |
109 | + | |
110 | + Management manager = Beans.getReference(Management.class); | |
111 | + manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | |
112 | + } | |
113 | + | |
114 | + @Override | |
115 | + public AttributeList getAttributes(String[] attributes) { | |
116 | + if (attributes != null) { | |
117 | + AttributeList list = new AttributeList(); | |
118 | + for (String attribute : attributes) { | |
119 | + try { | |
120 | + Object value = getAttribute(attribute); | |
121 | + list.add(new Attribute(attribute, value)); | |
122 | + } catch (Throwable t) { | |
123 | + } | |
124 | + } | |
125 | + | |
126 | + return list; | |
127 | + } | |
128 | + | |
129 | + return null; | |
130 | + } | |
131 | + | |
132 | + @Override | |
133 | + public AttributeList setAttributes(AttributeList attributes) { | |
134 | + AttributeList settedAttributes = new AttributeList(); | |
135 | + if (attributes != null) { | |
136 | + for (Attribute attribute : attributes.asList()) { | |
137 | + try { | |
138 | + setAttribute(attribute); | |
139 | + | |
140 | + // A razão para separarmos a criação do atributo de sua adição na lista é que | |
141 | + // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será | |
142 | + // adicionado na lista de atributos que foram afetados. | |
143 | + Attribute attributeWithNewValue = new Attribute(attribute.getName(), | |
144 | + getAttribute(attribute.getName())); | |
145 | + settedAttributes.add(attributeWithNewValue); | |
146 | + } catch (Throwable t) { | |
147 | + } | |
148 | + } | |
149 | + } | |
150 | + | |
151 | + return settedAttributes; | |
152 | + } | |
153 | + | |
154 | + @Override | |
155 | + public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, | |
156 | + ReflectionException { | |
157 | + | |
158 | + // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
159 | + if (this.delegateInfo == null) { | |
160 | + initializeMBeanInfo(); | |
161 | + } | |
162 | + | |
163 | + Management manager = Beans.getReference(Management.class); | |
164 | + return manager.invoke(managedType, actionName, params); | |
165 | + } | |
166 | + | |
167 | + /** | |
168 | + * Initialize the Managed information for this instance of Managed | |
169 | + */ | |
170 | + private void initializeMBeanInfo() { | |
171 | + // Aqui vamos armazenar nossos atributos | |
172 | + ArrayList<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(); | |
173 | + | |
174 | + // Aqui vamos armazenar nossas operações | |
175 | + ArrayList<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(); | |
176 | + | |
177 | + // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente | |
178 | + for (Entry<String, FieldDetail> fieldEntry : managedType.getFields().entrySet()) { | |
179 | + | |
180 | + try { | |
181 | + | |
182 | + MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue() | |
183 | + .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue() | |
184 | + .getSetterMethod()); | |
185 | + attributes.add(attributeInfo); | |
186 | + | |
187 | + } catch (javax.management.IntrospectionException e) { | |
188 | + throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType() | |
189 | + .getSimpleName())); | |
190 | + } | |
191 | + } | |
192 | + | |
193 | + // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente | |
194 | + for (Entry<String, MethodDetail> methodEntry : managedType.getOperationMethods().entrySet()) { | |
195 | + | |
196 | + MethodDetail methodDetail = methodEntry.getValue(); | |
197 | + | |
198 | + ParameterDetail[] parameterTypes = methodDetail.getParameterTypers(); | |
199 | + | |
200 | + MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length] | |
201 | + : null; | |
202 | + | |
203 | + if (parameters != null) { | |
204 | + | |
205 | + for (int i = 0; i < parameterTypes.length; i++) { | |
206 | + | |
207 | + parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i] | |
208 | + .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription()); | |
209 | + } | |
210 | + } | |
211 | + | |
212 | + // Com todas as informações, criamos nossa instância de MBeanOperationInfo e | |
213 | + // acrescentamos na lista de todas as operações. | |
214 | + int operationType = 0; | |
215 | + switch(methodDetail.getType()){ | |
216 | + case ACTION: | |
217 | + operationType = MBeanOperationInfo.ACTION; | |
218 | + break; | |
219 | + | |
220 | + case INFO: | |
221 | + operationType = MBeanOperationInfo.INFO; | |
222 | + break; | |
223 | + | |
224 | + case ACTION_INFO: | |
225 | + operationType = MBeanOperationInfo.ACTION_INFO; | |
226 | + break; | |
227 | + | |
228 | + default: | |
229 | + operationType = MBeanOperationInfo.UNKNOWN; | |
230 | + } | |
231 | + | |
232 | + MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(), | |
233 | + methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(), | |
234 | + operationType); | |
235 | + | |
236 | + operations.add(operation); | |
237 | + | |
238 | + } | |
239 | + | |
240 | + // Por fim criamos nosso bean info. | |
241 | + delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(), | |
242 | + attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]), | |
243 | + null); | |
244 | + | |
245 | + } | |
246 | + | |
247 | + @Override | |
248 | + public MBeanInfo getMBeanInfo() { | |
249 | + if (delegateInfo == null) { | |
250 | + initializeMBeanInfo(); | |
251 | + } | |
252 | + | |
253 | + return delegateInfo; | |
254 | + } | |
255 | + | |
256 | + public ResourceBundle getBundle(){ | |
257 | + if (bundle==null){ | |
258 | + bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | |
259 | + } | |
260 | + | |
261 | + return bundle; | |
262 | + } | |
263 | + | |
264 | +} | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/JMXManagementExtension.java
0 → 100644
... | ... | @@ -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; | |
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
0 → 100644
... | ... | @@ -0,0 +1,120 @@ |
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 | + // @Inject | |
66 | + // @Name("demoiselle-monitoring-bundle") | |
67 | + // private ResourceBundle bundle; | |
68 | + | |
69 | + /** | |
70 | + * Return the MBean Server instance. | |
71 | + * | |
72 | + * @return MBeanServer | |
73 | + */ | |
74 | + public static final MBeanServer getMBeanServer() { | |
75 | + return server; | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * Register a given managed bean (MBean) with the specified name. | |
80 | + * | |
81 | + * @param mbean | |
82 | + * the managed bean to register | |
83 | + * @param name | |
84 | + * the name under which to register the bean | |
85 | + * @return the object name of the mbean, for later deregistration | |
86 | + */ | |
87 | + public static ObjectInstance register(final Object mbean, final String name) { | |
88 | + | |
89 | + logger.info(bundle.getString("mbean-registration",name)); | |
90 | + | |
91 | + ObjectInstance instance = null; | |
92 | + try { | |
93 | + ObjectName objectName = new ObjectName(name); | |
94 | + instance = server.registerMBean(mbean, objectName); | |
95 | + } catch (Exception e) { | |
96 | + logger.error(bundle.getString("mbean-registration-error",name),e); | |
97 | + throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e); | |
98 | + } | |
99 | + | |
100 | + return instance; | |
101 | + } | |
102 | + | |
103 | + /** | |
104 | + * Remove the registration of a mbean. | |
105 | + * | |
106 | + * @param objectName | |
107 | + * the name of the bean to unregister | |
108 | + */ | |
109 | + public static void unregister(final ObjectName objectName) { | |
110 | + | |
111 | + logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName())); | |
112 | + | |
113 | + try { | |
114 | + server.unregisterMBean(objectName); | |
115 | + } catch (Exception e) { | |
116 | + logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e); | |
117 | + throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e); | |
118 | + } | |
119 | + } | |
120 | +} | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/MBeanManager.java
0 → 100644
... | ... | @@ -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; | |
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
0 → 100644
... | ... | @@ -0,0 +1,86 @@ |
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 | + /*public static final String NOTIFICATION_DEFAULT_MBEAN_NAME = NotificationBroadcaster.class.getPackage().getName() | |
64 | + +":name=" | |
65 | + +NotificationBroadcaster.class.getSimpleName();*/ | |
66 | + | |
67 | + private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; | |
68 | + | |
69 | + protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { | |
70 | + br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); | |
71 | + Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); | |
72 | + sendNotification(n); | |
73 | + } | |
74 | + | |
75 | + protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) { | |
76 | + br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification(); | |
77 | + | |
78 | + AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++ | |
79 | + , System.currentTimeMillis(), demoiselleNotification.getMessage().toString() | |
80 | + , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName() | |
81 | + , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue()); | |
82 | + | |
83 | + sendNotification(n); | |
84 | + } | |
85 | + | |
86 | +} | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/NotificationBroadcasterMBean.java
0 → 100644
... | ... | @@ -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; | |
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
0 → 100644
... | ... | @@ -0,0 +1,80 @@ |
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/jmx/bootstrap/JMXManagementExtension.java
... | ... | @@ -1,108 +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.jmx.bootstrap; | |
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.management.ManagedType; | |
45 | -import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | |
46 | -import br.gov.frameworkdemoiselle.jmx.internal.DynamicMBeanProxy; | |
47 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanHelper; | |
48 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
49 | -import br.gov.frameworkdemoiselle.jmx.internal.NotificationEventListener; | |
50 | -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | |
51 | -import br.gov.frameworkdemoiselle.util.Beans; | |
52 | - | |
53 | -public class JMXManagementExtension implements ManagementExtension { | |
54 | - | |
55 | - public void registerNotificationMBean(){ | |
56 | - MBeanManager mbeanManager = Beans.getReference(MBeanManager.class); | |
57 | - JMXConfig configuration = Beans.getReference(JMXConfig.class); | |
58 | - | |
59 | - StringBuffer notificationMBeanName = new StringBuffer() | |
60 | - .append( configuration.getNotificationDomain()!=null ? configuration.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | |
61 | - .append(":name=") | |
62 | - .append(configuration.getNotificationMBeanName()); | |
63 | - | |
64 | - if (mbeanManager.findMBeanInstance(notificationMBeanName.toString()) == null){ | |
65 | - NotificationEventListener listener = Beans.getReference(NotificationEventListener.class); | |
66 | - | |
67 | - ObjectInstance instance = MBeanHelper.register(listener.createNotificationBroadcaster(), notificationMBeanName.toString()); | |
68 | - mbeanManager.storeRegisteredMBean(instance); | |
69 | - } | |
70 | - } | |
71 | - | |
72 | - @Override | |
73 | - public void initialize(List<ManagedType> managedTypes) { | |
74 | - MBeanManager manager = Beans.getReference(MBeanManager.class); | |
75 | - JMXConfig configuration = Beans.getReference(JMXConfig.class); | |
76 | - | |
77 | - for (ManagedType type : managedTypes) { | |
78 | - DynamicMBeanProxy beanProxy = new DynamicMBeanProxy(type); | |
79 | - | |
80 | - Name nameAnnotation = type.getType().getAnnotation(Name.class); | |
81 | - String mbeanName = nameAnnotation != null ? nameAnnotation.value() : type.getType().getSimpleName(); | |
82 | - | |
83 | - StringBuffer name = new StringBuffer() | |
84 | - .append( configuration.getMbeanDomain()!=null ? configuration.getMbeanDomain() : type.getType().getPackage().getName() ) | |
85 | - .append(":name=") | |
86 | - .append( mbeanName ); | |
87 | - | |
88 | - | |
89 | - if (manager.findMBeanInstance(name.toString()) == null){ | |
90 | - ObjectInstance instance = MBeanHelper.register(beanProxy, name.toString()); | |
91 | - manager.storeRegisteredMBean(instance); | |
92 | - } | |
93 | - } | |
94 | - | |
95 | - registerNotificationMBean(); | |
96 | - } | |
97 | - | |
98 | - @Override | |
99 | - public void shutdown(List<ManagedType> managedTypes) { | |
100 | - MBeanManager manager = Beans.getReference(MBeanManager.class); | |
101 | - for (ObjectInstance instance : manager.listRegisteredMBeans()){ | |
102 | - MBeanHelper.unregister(instance.getObjectName()); | |
103 | - } | |
104 | - | |
105 | - manager.cleanRegisteredMBeans(); | |
106 | - } | |
107 | - | |
108 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/configuration/JMXConfig.java
... | ... | @@ -1,119 +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.jmx.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 | -@Configuration(prefix = "frameworkdemoiselle.management.jmx.") | |
46 | -public class JMXConfig { | |
47 | - | |
48 | - @Name("mbean.domain") | |
49 | - private String mbeanDomain; | |
50 | - | |
51 | - @Name("notification.domain") | |
52 | - private String notificationDomain = "br.gov.frameworkdemoiselle.jmx"; | |
53 | - | |
54 | - @Name("notification.name") | |
55 | - private String notificationMBeanName = "NotificationBroadcaster"; | |
56 | - | |
57 | - /** | |
58 | - * </p>The domain to register all {@link ManagementController} classes found during boot.</p> | |
59 | - * | |
60 | - * <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 | |
61 | - * parameter is the "domain" portion of the full name.</p> | |
62 | - * | |
63 | - * <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> | |
64 | - * | |
65 | - */ | |
66 | - public String getMbeanDomain() { | |
67 | - return mbeanDomain; | |
68 | - } | |
69 | - | |
70 | - /** | |
71 | - * @see #getMbeanDomain() | |
72 | - */ | |
73 | - public void setMbeanDomain(String mbeanDomain) { | |
74 | - this.mbeanDomain = mbeanDomain; | |
75 | - } | |
76 | - | |
77 | - /** | |
78 | - * <p>The name the {@link NotificationBroadcaster} MBean will be registered to. The full name | |
79 | - * of a MBean has the format of <code>domain:name=MBeanName</code> (ex: <code>br.gov.frameworkdemoiselle.jmx:name=NotificationBroadcaster</code>), this | |
80 | - * parameter is the ":name=MBeanName" portion without the ":name=".</p> | |
81 | - * | |
82 | - * <p>The default is the value returned by {@link Class#getSimpleName()} when called from the {@link NotificationBroadcaster} class.</p> | |
83 | - * | |
84 | - * @see #getMbeanDomain() | |
85 | - */ | |
86 | - public String getNotificationMBeanName() { | |
87 | - return notificationMBeanName; | |
88 | - } | |
89 | - | |
90 | - /** | |
91 | - * @see #getNotificationMBeanName() | |
92 | - */ | |
93 | - public void setNotificationMBeanName(String notificationMBeanName) { | |
94 | - this.notificationMBeanName = notificationMBeanName; | |
95 | - } | |
96 | - | |
97 | - /** | |
98 | - * </p>The domain to register the {@link NotificationBroadcaster} MBean.</p> | |
99 | - * | |
100 | - * <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 | |
101 | - * parameter is the "domain" portion of the full name.</p> | |
102 | - * | |
103 | - * <p>The default is <code>br.gov.frameworkdemoiselle.jmx</code>.</p> | |
104 | - * | |
105 | - */ | |
106 | - public String getNotificationDomain() { | |
107 | - return notificationDomain; | |
108 | - } | |
109 | - | |
110 | - /** | |
111 | - * @see #getNotificationDomain() | |
112 | - */ | |
113 | - public void setNotificationDomain(String notificationDomain) { | |
114 | - this.notificationDomain = notificationDomain; | |
115 | - } | |
116 | - | |
117 | - | |
118 | - | |
119 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/DynamicMBeanProxy.java
... | ... | @@ -1,264 +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.jmx.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.stereotype.ManagementController; | |
62 | -import br.gov.frameworkdemoiselle.util.Beans; | |
63 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
64 | - | |
65 | -/** | |
66 | - * <p> | |
67 | - * This class is a MBean that gets registered everytime you mark a class with {@link ManagementController}. It dynamicaly reads the | |
68 | - * fields and operations contained in a {@link ManagementController} class and exposes them to the MBean server. Everytime a client | |
69 | - * tries to call an operation or read/write a property inside a ManagementController class, this class will call the appropriate | |
70 | - * method and pass the result to the MBean client. | |
71 | - * </p> | |
72 | - * | |
73 | - * @author SERPRO | |
74 | - */ | |
75 | -public class DynamicMBeanProxy implements DynamicMBean { | |
76 | - | |
77 | - private MBeanInfo delegateInfo; | |
78 | - | |
79 | - private ManagedType managedType; | |
80 | - | |
81 | - private ResourceBundle bundle; | |
82 | - | |
83 | - public DynamicMBeanProxy(ManagedType type) { | |
84 | - if (type == null) { | |
85 | - throw new NullPointerException(getBundle().getString("mbean-null-type-defined")); | |
86 | - } | |
87 | - managedType = type; | |
88 | - } | |
89 | - | |
90 | - @Override | |
91 | - public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { | |
92 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
93 | - if (delegateInfo == null) { | |
94 | - initializeMBeanInfo(); | |
95 | - } | |
96 | - | |
97 | - Management manager = Beans.getReference(Management.class); | |
98 | - return manager.getProperty(managedType, attribute); | |
99 | - } | |
100 | - | |
101 | - @Override | |
102 | - public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, | |
103 | - MBeanException, ReflectionException { | |
104 | - | |
105 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
106 | - if (delegateInfo == null) { | |
107 | - initializeMBeanInfo(); | |
108 | - } | |
109 | - | |
110 | - Management manager = Beans.getReference(Management.class); | |
111 | - manager.setProperty(managedType, attribute.getName(), attribute.getValue()); | |
112 | - } | |
113 | - | |
114 | - @Override | |
115 | - public AttributeList getAttributes(String[] attributes) { | |
116 | - if (attributes != null) { | |
117 | - AttributeList list = new AttributeList(); | |
118 | - for (String attribute : attributes) { | |
119 | - try { | |
120 | - Object value = getAttribute(attribute); | |
121 | - list.add(new Attribute(attribute, value)); | |
122 | - } catch (Throwable t) { | |
123 | - } | |
124 | - } | |
125 | - | |
126 | - return list; | |
127 | - } | |
128 | - | |
129 | - return null; | |
130 | - } | |
131 | - | |
132 | - @Override | |
133 | - public AttributeList setAttributes(AttributeList attributes) { | |
134 | - AttributeList settedAttributes = new AttributeList(); | |
135 | - if (attributes != null) { | |
136 | - for (Attribute attribute : attributes.asList()) { | |
137 | - try { | |
138 | - setAttribute(attribute); | |
139 | - | |
140 | - // A razão para separarmos a criação do atributo de sua adição na lista é que | |
141 | - // caso a obtenção do novo valor do atributo dispare uma exceção então o atributo não será | |
142 | - // adicionado na lista de atributos que foram afetados. | |
143 | - Attribute attributeWithNewValue = new Attribute(attribute.getName(), | |
144 | - getAttribute(attribute.getName())); | |
145 | - settedAttributes.add(attributeWithNewValue); | |
146 | - } catch (Throwable t) { | |
147 | - } | |
148 | - } | |
149 | - } | |
150 | - | |
151 | - return settedAttributes; | |
152 | - } | |
153 | - | |
154 | - @Override | |
155 | - public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, | |
156 | - ReflectionException { | |
157 | - | |
158 | - // Se o bean ainda não foi lido para determinar seus atributos, o faz agora. | |
159 | - if (this.delegateInfo == null) { | |
160 | - initializeMBeanInfo(); | |
161 | - } | |
162 | - | |
163 | - Management manager = Beans.getReference(Management.class); | |
164 | - return manager.invoke(managedType, actionName, params); | |
165 | - } | |
166 | - | |
167 | - /** | |
168 | - * Initialize the Managed information for this instance of Managed | |
169 | - */ | |
170 | - private void initializeMBeanInfo() { | |
171 | - // Aqui vamos armazenar nossos atributos | |
172 | - ArrayList<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>(); | |
173 | - | |
174 | - // Aqui vamos armazenar nossas operações | |
175 | - ArrayList<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>(); | |
176 | - | |
177 | - // Para cada propriedade descoberta no ManagementController, cria um attributeInfo correspondente | |
178 | - for (Entry<String, FieldDetail> fieldEntry : managedType.getFields().entrySet()) { | |
179 | - | |
180 | - try { | |
181 | - | |
182 | - MBeanAttributeInfo attributeInfo = new MBeanAttributeInfo(fieldEntry.getKey(), fieldEntry.getValue() | |
183 | - .getDescription(), fieldEntry.getValue().getGetterMethod(), fieldEntry.getValue() | |
184 | - .getSetterMethod()); | |
185 | - attributes.add(attributeInfo); | |
186 | - | |
187 | - } catch (javax.management.IntrospectionException e) { | |
188 | - throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType() | |
189 | - .getSimpleName())); | |
190 | - } | |
191 | - } | |
192 | - | |
193 | - // Para cada operação descoberta no ManagementController, cria um operationInfo correspondente | |
194 | - for (Entry<String, MethodDetail> methodEntry : managedType.getOperationMethods().entrySet()) { | |
195 | - | |
196 | - MethodDetail methodDetail = methodEntry.getValue(); | |
197 | - | |
198 | - ParameterDetail[] parameterTypes = methodDetail.getParameterTypers(); | |
199 | - | |
200 | - MBeanParameterInfo[] parameters = parameterTypes.length > 0 ? new MBeanParameterInfo[parameterTypes.length] | |
201 | - : null; | |
202 | - | |
203 | - if (parameters != null) { | |
204 | - | |
205 | - for (int i = 0; i < parameterTypes.length; i++) { | |
206 | - | |
207 | - parameters[i] = new MBeanParameterInfo(parameterTypes[i].getParameterName(), parameterTypes[i] | |
208 | - .getParameterType().getCanonicalName(), parameterTypes[i].getParameterDescription()); | |
209 | - } | |
210 | - } | |
211 | - | |
212 | - // Com todas as informações, criamos nossa instância de MBeanOperationInfo e | |
213 | - // acrescentamos na lista de todas as operações. | |
214 | - int operationType = 0; | |
215 | - switch(methodDetail.getType()){ | |
216 | - case ACTION: | |
217 | - operationType = MBeanOperationInfo.ACTION; | |
218 | - break; | |
219 | - | |
220 | - case INFO: | |
221 | - operationType = MBeanOperationInfo.INFO; | |
222 | - break; | |
223 | - | |
224 | - case ACTION_INFO: | |
225 | - operationType = MBeanOperationInfo.ACTION_INFO; | |
226 | - break; | |
227 | - | |
228 | - default: | |
229 | - operationType = MBeanOperationInfo.UNKNOWN; | |
230 | - } | |
231 | - | |
232 | - MBeanOperationInfo operation = new MBeanOperationInfo(methodDetail.getMethod().getName(), | |
233 | - methodDetail.getDescription(), parameters, methodDetail.getMethod().getReturnType().getName(), | |
234 | - operationType); | |
235 | - | |
236 | - operations.add(operation); | |
237 | - | |
238 | - } | |
239 | - | |
240 | - // Por fim criamos nosso bean info. | |
241 | - delegateInfo = new MBeanInfo(managedType.getType().getCanonicalName(), managedType.getDescription(), | |
242 | - attributes.toArray(new MBeanAttributeInfo[0]), null, operations.toArray(new MBeanOperationInfo[0]), | |
243 | - null); | |
244 | - | |
245 | - } | |
246 | - | |
247 | - @Override | |
248 | - public MBeanInfo getMBeanInfo() { | |
249 | - if (delegateInfo == null) { | |
250 | - initializeMBeanInfo(); | |
251 | - } | |
252 | - | |
253 | - return delegateInfo; | |
254 | - } | |
255 | - | |
256 | - public ResourceBundle getBundle(){ | |
257 | - if (bundle==null){ | |
258 | - bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | |
259 | - } | |
260 | - | |
261 | - return bundle; | |
262 | - } | |
263 | - | |
264 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/MBeanHelper.java
... | ... | @@ -1,120 +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.jmx.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 | - // @Inject | |
66 | - // @Name("demoiselle-monitoring-bundle") | |
67 | - // private ResourceBundle bundle; | |
68 | - | |
69 | - /** | |
70 | - * Return the MBean Server instance. | |
71 | - * | |
72 | - * @return MBeanServer | |
73 | - */ | |
74 | - public static final MBeanServer getMBeanServer() { | |
75 | - return server; | |
76 | - } | |
77 | - | |
78 | - /** | |
79 | - * Register a given managed bean (MBean) with the specified name. | |
80 | - * | |
81 | - * @param mbean | |
82 | - * the managed bean to register | |
83 | - * @param name | |
84 | - * the name under which to register the bean | |
85 | - * @return the object name of the mbean, for later deregistration | |
86 | - */ | |
87 | - public static ObjectInstance register(final Object mbean, final String name) { | |
88 | - | |
89 | - logger.info(bundle.getString("mbean-registration",name)); | |
90 | - | |
91 | - ObjectInstance instance = null; | |
92 | - try { | |
93 | - ObjectName objectName = new ObjectName(name); | |
94 | - instance = server.registerMBean(mbean, objectName); | |
95 | - } catch (Exception e) { | |
96 | - logger.error(bundle.getString("mbean-registration-error",name),e); | |
97 | - throw new DemoiselleException(bundle.getString("mbean-registration-error",name), e); | |
98 | - } | |
99 | - | |
100 | - return instance; | |
101 | - } | |
102 | - | |
103 | - /** | |
104 | - * Remove the registration of a mbean. | |
105 | - * | |
106 | - * @param objectName | |
107 | - * the name of the bean to unregister | |
108 | - */ | |
109 | - public static void unregister(final ObjectName objectName) { | |
110 | - | |
111 | - logger.info(bundle.getString("mbean-deregistration",objectName.getCanonicalName())); | |
112 | - | |
113 | - try { | |
114 | - server.unregisterMBean(objectName); | |
115 | - } catch (Exception e) { | |
116 | - logger.error(bundle.getString("mbean-deregistration",objectName.getCanonicalName()),e); | |
117 | - throw new DemoiselleException(bundle.getString("mbean-deregistration",objectName.getCanonicalName()), e); | |
118 | - } | |
119 | - } | |
120 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/MBeanManager.java
... | ... | @@ -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.jmx.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/jmx/internal/NotificationBroadcaster.java
... | ... | @@ -1,86 +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.jmx.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.jmx.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 | -final class NotificationBroadcaster extends NotificationBroadcasterSupport implements NotificationBroadcasterMBean,Serializable { | |
58 | - | |
59 | - private static final long serialVersionUID = 1L; | |
60 | - | |
61 | - private int sequenceNumber = 1; | |
62 | - | |
63 | - /*public static final String NOTIFICATION_DEFAULT_MBEAN_NAME = NotificationBroadcaster.class.getPackage().getName() | |
64 | - +":name=" | |
65 | - +NotificationBroadcaster.class.getSimpleName();*/ | |
66 | - | |
67 | - private static final String NOTIFICATION_TYPE_GENERIC = "jmx.message"; | |
68 | - | |
69 | - protected void sendNotification( ManagementNotificationEvent event , JMXConfig config ) { | |
70 | - br.gov.frameworkdemoiselle.management.GenericNotification demoiselleNotification = event.getNotification(); | |
71 | - Notification n = new Notification(NOTIFICATION_TYPE_GENERIC, config.getNotificationMBeanName(), sequenceNumber++, System.currentTimeMillis(), demoiselleNotification.getMessage().toString()); | |
72 | - sendNotification(n); | |
73 | - } | |
74 | - | |
75 | - protected void sendAttributeChangedMessage( ManagementNotificationEvent event , JMXConfig config ) { | |
76 | - br.gov.frameworkdemoiselle.management.AttributeChangeNotification demoiselleNotification = (br.gov.frameworkdemoiselle.management.AttributeChangeNotification)event.getNotification(); | |
77 | - | |
78 | - AttributeChangeNotification n = new AttributeChangeNotification(config.getNotificationMBeanName(), sequenceNumber++ | |
79 | - , System.currentTimeMillis(), demoiselleNotification.getMessage().toString() | |
80 | - , demoiselleNotification.getAttributeName(), demoiselleNotification.getAttributeType().getSimpleName() | |
81 | - , demoiselleNotification.getOldValue(), demoiselleNotification.getNewValue()); | |
82 | - | |
83 | - sendNotification(n); | |
84 | - } | |
85 | - | |
86 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/NotificationBroadcasterMBean.java
... | ... | @@ -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.jmx.internal; | |
38 | - | |
39 | - | |
40 | - | |
41 | -/** | |
42 | - * MBean interface responsible for sending MBean notifications to remote clients. | |
43 | - * | |
44 | - * @author serpro | |
45 | - * | |
46 | - */ | |
47 | -interface NotificationBroadcasterMBean { | |
48 | -} |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/NotificationEventListener.java
... | ... | @@ -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.jmx.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.internal.management.qualifier.AttributeChange; | |
45 | -import br.gov.frameworkdemoiselle.internal.management.qualifier.Generic; | |
46 | -import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | |
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/test/java/management/tests/basic/DynamicMBeanProxyTest.java
... | ... | @@ -55,7 +55,7 @@ import org.junit.BeforeClass; |
55 | 55 | import org.junit.Test; |
56 | 56 | import org.junit.runner.RunWith; |
57 | 57 | |
58 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
58 | +import br.gov.frameworkdemoiselle.internal.MBeanManager; | |
59 | 59 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
60 | 60 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
61 | 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 | 57 | import org.junit.Test; |
58 | 58 | import org.junit.runner.RunWith; |
59 | 59 | |
60 | -import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | |
61 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
60 | +import br.gov.frameworkdemoiselle.configuration.JMXConfig; | |
61 | +import br.gov.frameworkdemoiselle.internal.MBeanManager; | |
62 | 62 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
63 | 63 | import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; |
64 | 64 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | ... | ... |
impl/extension/jpa/src/test/java/transaction/interceptor/JPATransactionTest.java
0 → 100644
... | ... | @@ -0,0 +1,93 @@ |
1 | +package transaction.interceptor; | |
2 | + | |
3 | +import javax.inject.Inject; | |
4 | +import javax.persistence.EntityManager; | |
5 | + | |
6 | +import junit.framework.Assert; | |
7 | + | |
8 | +import org.jboss.arquillian.container.test.api.Deployment; | |
9 | +import org.jboss.arquillian.junit.Arquillian; | |
10 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
11 | +import org.junit.Before; | |
12 | +import org.junit.Test; | |
13 | +import org.junit.runner.RunWith; | |
14 | + | |
15 | +import test.Tests; | |
16 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
17 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | |
18 | + | |
19 | +@RunWith(Arquillian.class) | |
20 | +public class JPATransactionTest { | |
21 | + | |
22 | + private static final String PATH = "src/test/resources/transaction/interceptor"; | |
23 | + | |
24 | + @Inject | |
25 | + private TransactionalBusiness tb; | |
26 | + | |
27 | + @Inject | |
28 | + @Name("pu1") | |
29 | + private EntityManager em1; | |
30 | + | |
31 | + @Inject | |
32 | + @Name("pu2") | |
33 | + private EntityManager em2; | |
34 | + | |
35 | + @Inject | |
36 | + private TransactionContext transactionContext; | |
37 | + | |
38 | + @Deployment | |
39 | + public static WebArchive createDeployment() { | |
40 | + WebArchive deployment = Tests.createDeployment(JPATransactionTest.class); | |
41 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml"); | |
42 | + | |
43 | + return deployment; | |
44 | + } | |
45 | + | |
46 | + @Before | |
47 | + public void eraseDatabases(){ | |
48 | + transactionContext.getCurrentTransaction().begin(); | |
49 | + em1.createQuery("DELETE FROM MyEntity1").executeUpdate(); | |
50 | + em2.createQuery("DELETE FROM MyEntity2").executeUpdate(); | |
51 | + transactionContext.getCurrentTransaction().commit(); | |
52 | + } | |
53 | + | |
54 | + @Test | |
55 | + public void isTransactionActiveWithInterceptor(){ | |
56 | + Assert.assertTrue(tb.isTransactionActiveWithInterceptor()); | |
57 | + } | |
58 | + | |
59 | + @Test | |
60 | + public void isTransactionActiveWithoutInterceptor(){ | |
61 | + Assert.assertFalse(tb.isTransactionActiveWithoutInterceptor()); | |
62 | + } | |
63 | + | |
64 | + @Test | |
65 | + public void commitWithSuccess() { | |
66 | + | |
67 | + tb.commitWithSuccess(); | |
68 | + | |
69 | + MyEntity1 entity1 = em1.find(MyEntity1.class, tb.createId("id-1")); | |
70 | + MyEntity2 entity2 = em2.find(MyEntity2.class, tb.createId("id-2")); | |
71 | + | |
72 | + Assert.assertEquals("desc-1", entity1.getDescription()); | |
73 | + Assert.assertEquals("desc-2", entity2.getDescription()); | |
74 | + } | |
75 | + | |
76 | + @Test | |
77 | + public void rollbackWithSuccess() { | |
78 | + | |
79 | + try{ | |
80 | + tb.rollbackWithSuccess(); | |
81 | + } catch (Exception e) { | |
82 | + Assert.assertEquals("Exceção criada para marcar transação para rollback", e.getMessage()); | |
83 | + } | |
84 | + finally{ | |
85 | + MyEntity1 entity1 = em1.find(MyEntity1.class, tb.createId("id-1")); | |
86 | + MyEntity2 entity2 = em2.find(MyEntity2.class, tb.createId("id-2")); | |
87 | + | |
88 | + Assert.assertNull(entity1); | |
89 | + Assert.assertNull(entity2); | |
90 | + } | |
91 | + } | |
92 | + | |
93 | +} | |
0 | 94 | \ No newline at end of file | ... | ... |
impl/extension/jpa/src/test/java/transaction/interceptor/MyEntity1.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package transaction.interceptor; | |
2 | + | |
3 | +import javax.persistence.Entity; | |
4 | +import javax.persistence.Id; | |
5 | + | |
6 | +@Entity | |
7 | +public class MyEntity1 { | |
8 | + | |
9 | + @Id | |
10 | + private String id; | |
11 | + | |
12 | + private String description; | |
13 | + | |
14 | + public String getId() { | |
15 | + return id; | |
16 | + } | |
17 | + | |
18 | + public void setId(String id) { | |
19 | + this.id = id; | |
20 | + } | |
21 | + | |
22 | + public String getDescription() { | |
23 | + return description; | |
24 | + } | |
25 | + | |
26 | + public void setDescription(String description) { | |
27 | + this.description = description; | |
28 | + } | |
29 | +} | ... | ... |
impl/extension/jpa/src/test/java/transaction/interceptor/MyEntity2.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package transaction.interceptor; | |
2 | + | |
3 | +import javax.persistence.Entity; | |
4 | +import javax.persistence.Id; | |
5 | + | |
6 | +@Entity | |
7 | +public class MyEntity2 { | |
8 | + | |
9 | + @Id | |
10 | + private String id; | |
11 | + | |
12 | + private String description; | |
13 | + | |
14 | + public String getId() { | |
15 | + return id; | |
16 | + } | |
17 | + | |
18 | + public void setId(String id) { | |
19 | + this.id = id; | |
20 | + } | |
21 | + | |
22 | + public String getDescription() { | |
23 | + return description; | |
24 | + } | |
25 | + | |
26 | + public void setDescription(String description) { | |
27 | + this.description = description; | |
28 | + } | |
29 | +} | ... | ... |
impl/extension/jpa/src/test/java/transaction/interceptor/TransactionalBusiness.java
0 → 100644
... | ... | @@ -0,0 +1,64 @@ |
1 | +package transaction.interceptor; | |
2 | + | |
3 | +import javax.inject.Inject; | |
4 | +import javax.persistence.EntityManager; | |
5 | + | |
6 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
7 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | |
8 | +import br.gov.frameworkdemoiselle.transaction.Transactional; | |
9 | + | |
10 | +public class TransactionalBusiness { | |
11 | + | |
12 | + @Inject | |
13 | + @Name("pu1") | |
14 | + private EntityManager em1; | |
15 | + | |
16 | + @Inject | |
17 | + @Name("pu2") | |
18 | + private EntityManager em2; | |
19 | + | |
20 | + @Inject | |
21 | + private TransactionContext transactionContext; | |
22 | + | |
23 | + @Transactional | |
24 | + public boolean isTransactionActiveWithInterceptor(){ | |
25 | + return transactionContext.getCurrentTransaction().isActive(); | |
26 | + } | |
27 | + | |
28 | + public boolean isTransactionActiveWithoutInterceptor(){ | |
29 | + return transactionContext.getCurrentTransaction().isActive(); | |
30 | + } | |
31 | + | |
32 | + @Transactional | |
33 | + public void commitWithSuccess() { | |
34 | + MyEntity1 entity1 = new MyEntity1(); | |
35 | + entity1.setId(createId("id-1")); | |
36 | + entity1.setDescription("desc-1"); | |
37 | + | |
38 | + MyEntity2 entity2 = new MyEntity2(); | |
39 | + entity2.setId(createId("id-2")); | |
40 | + entity2.setDescription("desc-2"); | |
41 | + | |
42 | + em1.persist(entity1); | |
43 | + em2.persist(entity2); | |
44 | + } | |
45 | + | |
46 | + @Transactional | |
47 | + public void rollbackWithSuccess() throws Exception { | |
48 | + MyEntity1 entity1 = new MyEntity1(); | |
49 | + entity1.setId(createId("id-3")); | |
50 | + | |
51 | + MyEntity2 entity2 = new MyEntity2(); | |
52 | + entity2.setId(createId("id-4")); | |
53 | + | |
54 | + em1.persist(entity1); | |
55 | + em2.persist(entity2); | |
56 | + | |
57 | + throw new Exception("Exceção criada para marcar transação para rollback"); | |
58 | + } | |
59 | + | |
60 | + String createId(String id) { | |
61 | + return this.getClass().getName() + "_" + id; | |
62 | + } | |
63 | + | |
64 | +} | ... | ... |
impl/extension/jpa/src/test/java/transaction/manual/JPATransactionTest.java
... | ... | @@ -9,6 +9,8 @@ import javax.inject.Inject; |
9 | 9 | import javax.persistence.EntityManager; |
10 | 10 | import javax.persistence.TransactionRequiredException; |
11 | 11 | |
12 | +import junit.framework.Assert; | |
13 | + | |
12 | 14 | import org.jboss.arquillian.container.test.api.Deployment; |
13 | 15 | import org.jboss.arquillian.junit.Arquillian; |
14 | 16 | import org.jboss.shrinkwrap.api.spec.WebArchive; |
... | ... | @@ -20,6 +22,8 @@ import br.gov.frameworkdemoiselle.annotation.Name; |
20 | 22 | import br.gov.frameworkdemoiselle.transaction.JPATransaction; |
21 | 23 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
22 | 24 | import br.gov.frameworkdemoiselle.transaction.TransactionContext; |
25 | +import br.gov.frameworkdemoiselle.util.Beans; | |
26 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
23 | 27 | |
24 | 28 | @RunWith(Arquillian.class) |
25 | 29 | public class JPATransactionTest { |
... | ... | @@ -37,7 +41,7 @@ public class JPATransactionTest { |
37 | 41 | @Name("pu2") |
38 | 42 | private EntityManager em2; |
39 | 43 | |
40 | - @Deployment(name = "2") | |
44 | + @Deployment | |
41 | 45 | public static WebArchive createDeployment() { |
42 | 46 | WebArchive deployment = Tests.createDeployment(JPATransactionTest.class); |
43 | 47 | deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml"); |
... | ... | @@ -120,6 +124,33 @@ public class JPATransactionTest { |
120 | 124 | assertNull(persisted1); |
121 | 125 | assertNull(persisted2); |
122 | 126 | } |
127 | + | |
128 | + @Test | |
129 | + public void checkEntityManagerCreatedAfterTransaction(){ | |
130 | + Transaction transaction = transactionContext.getCurrentTransaction(); | |
131 | + | |
132 | + String id = createId("id-5"); | |
133 | + MyEntity1 entity1 = new MyEntity1(); | |
134 | + entity1.setId(id); | |
135 | + entity1.setDescription("Test description"); | |
136 | + | |
137 | + Assert.assertFalse(transaction.isActive()); | |
138 | + transaction.begin(); | |
139 | + Assert.assertTrue(transaction.isActive()); | |
140 | + | |
141 | + EntityManager em1 = Beans.getReference(EntityManager.class, new NameQualifier("pu3")); | |
142 | + | |
143 | + try{ | |
144 | + em1.persist(entity1); | |
145 | + transaction.commit(); | |
146 | + } | |
147 | + catch(TransactionRequiredException te){ | |
148 | + Assert.fail("Entity Manager não ingressou em transação já em curso: "+te.getMessage()); | |
149 | + } | |
150 | + | |
151 | + entity1 = em1.find(MyEntity1.class, id); | |
152 | + Assert.assertEquals("Test description", entity1.getDescription()); | |
153 | + } | |
123 | 154 | |
124 | 155 | private String createId(String id) { |
125 | 156 | return this.getClass().getName() + "_" + id; | ... | ... |
impl/extension/jpa/src/test/resources/transaction/interceptor/persistence.xml
0 → 100644
... | ... | @@ -0,0 +1,96 @@ |
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 | +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
38 | + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | |
39 | + | |
40 | + <!-- | |
41 | + <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL"> | |
42 | + <non-jta-data-source>jdbc/arquillian1</non-jta-data-source> | |
43 | + | |
44 | + <class>transaction.manual.MyEntity1</class> | |
45 | + <class>transaction.manual.MyEntity2</class> | |
46 | + | |
47 | + <properties> | |
48 | + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> | |
49 | + <property name="eclipselink.logging.level.sql" value="FINE" /> | |
50 | + <property name="eclipselink.logging.parameters" value="true" /> | |
51 | + </properties> | |
52 | + </persistence-unit> | |
53 | + | |
54 | + <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL"> | |
55 | + <non-jta-data-source>jdbc/arquillian2</non-jta-data-source> | |
56 | + | |
57 | + <class>transaction.manual.MyEntity1</class> | |
58 | + <class>transaction.manual.MyEntity2</class> | |
59 | + | |
60 | + <properties> | |
61 | + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> | |
62 | + <property name="eclipselink.logging.level.sql" value="FINE" /> | |
63 | + <property name="eclipselink.logging.parameters" value="true" /> | |
64 | + </properties> | |
65 | + </persistence-unit> | |
66 | + --> | |
67 | + | |
68 | + <!-- | |
69 | + --> | |
70 | + <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL"> | |
71 | + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> | |
72 | + | |
73 | + <class>transaction.interceptor.MyEntity1</class> | |
74 | + <class>transaction.interceptor.MyEntity2</class> | |
75 | + | |
76 | + <properties> | |
77 | + <property name="hibernate.show_sql" value="true" /> | |
78 | + <property name="hibernate.format_sql" value="false" /> | |
79 | + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
80 | + </properties> | |
81 | + </persistence-unit> | |
82 | + | |
83 | + <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL"> | |
84 | + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> | |
85 | + | |
86 | + <class>transaction.interceptor.MyEntity1</class> | |
87 | + <class>transaction.interceptor.MyEntity2</class> | |
88 | + | |
89 | + <properties> | |
90 | + <property name="hibernate.show_sql" value="true" /> | |
91 | + <property name="hibernate.format_sql" value="false" /> | |
92 | + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
93 | + </properties> | |
94 | + </persistence-unit> | |
95 | + | |
96 | +</persistence> | |
0 | 97 | \ No newline at end of file | ... | ... |
impl/extension/jpa/src/test/resources/transaction/manual/persistence.xml
... | ... | @@ -92,5 +92,18 @@ |
92 | 92 | <property name="hibernate.hbm2ddl.auto" value="create-drop" /> |
93 | 93 | </properties> |
94 | 94 | </persistence-unit> |
95 | + | |
96 | + <persistence-unit name="pu3" transaction-type="RESOURCE_LOCAL"> | |
97 | + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source> | |
98 | + | |
99 | + <class>transaction.manual.MyEntity1</class> | |
100 | + <class>transaction.manual.MyEntity2</class> | |
101 | + | |
102 | + <properties> | |
103 | + <property name="hibernate.show_sql" value="true" /> | |
104 | + <property name="hibernate.format_sql" value="false" /> | |
105 | + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | |
106 | + </properties> | |
107 | + </persistence-unit> | |
95 | 108 | |
96 | 109 | </persistence> |
97 | 110 | \ No newline at end of file | ... | ... |
parent/bom/pom.xml
... | ... | @@ -311,7 +311,7 @@ |
311 | 311 | <!-- embedded containners --> |
312 | 312 | <dependency> |
313 | 313 | <groupId>org.glassfish.main.extras</groupId> |
314 | - <artifactId>glassfish-embedded-web</artifactId> | |
314 | + <artifactId>glassfish-embedded-all</artifactId> | |
315 | 315 | <version>${glassfish.embedded.version}</version> |
316 | 316 | </dependency> |
317 | 317 | |
... | ... | @@ -379,6 +379,13 @@ |
379 | 379 | <artifactId>easymock</artifactId> |
380 | 380 | <version>${easymock.version}</version> |
381 | 381 | </dependency> |
382 | + | |
383 | + <!-- Plug-ins --> | |
384 | + <dependency> | |
385 | + <groupId>org.apache.maven.plugins</groupId> | |
386 | + <artifactId>maven-surefire-plugin</artifactId> | |
387 | + <version>${maven.surefire.plugin.version}</version> | |
388 | + </dependency> | |
382 | 389 | </dependencies> |
383 | 390 | </dependencyManagement> |
384 | 391 | |
... | ... | @@ -422,7 +429,7 @@ |
422 | 429 | |
423 | 430 | <junit.version>4.8.1</junit.version> |
424 | 431 | <easymock.version>3.0</easymock.version> |
425 | - | |
432 | + | |
426 | 433 | <arquillian.version>1.1.1.Final</arquillian.version> |
427 | 434 | <!-- |
428 | 435 | <arquillian.version>1.0.4.Final</arquillian.version> |
... | ... | @@ -430,8 +437,10 @@ |
430 | 437 | <arquillian.weld.se.embedded.version>1.0.0.CR7</arquillian.weld.se.embedded.version> |
431 | 438 | <arquillian.persistence.version>1.0.0.Alpha6</arquillian.persistence.version> |
432 | 439 | <arquillian.glassfish.embedded.version>1.0.0.CR4</arquillian.glassfish.embedded.version> |
433 | - | |
434 | - <glassfish.embedded.version>3.1.2</glassfish.embedded.version> | |
440 | + | |
441 | + <glassfish.embedded.version>3.1.2.2</glassfish.embedded.version> | |
442 | + | |
443 | + <maven.surefire.plugin.version>2.16</maven.surefire.plugin.version> | |
435 | 444 | |
436 | 445 | <powermock.version>1.4.6</powermock.version> |
437 | 446 | <primefaces.version>3.4</primefaces.version> | ... | ... |
parent/extension/pom.xml
... | ... | @@ -79,6 +79,12 @@ |
79 | 79 | </dependencyManagement> |
80 | 80 | |
81 | 81 | <build> |
82 | + <testResources> | |
83 | + <testResource> | |
84 | + <directory>src/test/resources</directory> | |
85 | + <filtering>true</filtering> | |
86 | + </testResource> | |
87 | + </testResources> | |
82 | 88 | <plugins> |
83 | 89 | <plugin> |
84 | 90 | <groupId>org.apache.maven.plugins</groupId> |
... | ... | @@ -96,6 +102,10 @@ |
96 | 102 | <groupId>org.codehaus.mojo</groupId> |
97 | 103 | <artifactId>cobertura-maven-plugin</artifactId> |
98 | 104 | </plugin> |
105 | + <plugin> | |
106 | + <groupId>org.apache.maven.plugins</groupId> | |
107 | + <artifactId>maven-surefire-plugin</artifactId> | |
108 | + </plugin> | |
99 | 109 | </plugins> |
100 | 110 | </build> |
101 | 111 | ... | ... |