Skip to content

Commit 553963e

Browse files
authored
Merge pull request #296 from rombert/issue/ARIES-2160
ARIES-2160: Simple MBeanServer based on the platform implementation
2 parents d23d9ec + cae5118 commit 553963e

File tree

6 files changed

+161
-45
lines changed

6 files changed

+161
-45
lines changed

jmx/jmx-itests/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<artifactId>org.apache.aries.jmx.core.whiteboard</artifactId>
7777
<version>1.1.7-SNAPSHOT</version>
7878
</dependency>
79+
<dependency>
80+
<groupId>org.apache.aries.jmx</groupId>
81+
<artifactId>org.apache.aries.jmx.mbeanserver-platform</artifactId>
82+
<version>0.0.1-SNAPSHOT</version>
83+
</dependency>
7984
<dependency>
8085
<groupId>org.osgi</groupId>
8186
<artifactId>org.osgi.compendium</artifactId>

jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@
4040
import javax.management.MBeanServerInvocationHandler;
4141
import javax.management.ObjectName;
4242

43-
import org.apache.aries.jmx.test.MbeanServerActivator;
4443
import org.junit.runner.RunWith;
4544
import org.ops4j.pax.exam.Option;
4645
import org.ops4j.pax.exam.junit.PaxExam;
47-
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
4846
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
4947
import org.ops4j.pax.exam.spi.reactors.PerClass;
5048
import org.osgi.framework.Bundle;
@@ -87,17 +85,10 @@ protected Option jmxRuntime() {
8785
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.api").versionAsInProject(),
8886
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.whiteboard").versionAsInProject(),
8987
mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit").versionAsInProject(),
90-
mbeanServerBundle()
88+
mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.mbeanserver-platform").versionAsInProject()
9189
);
9290
}
9391

94-
protected Option mbeanServerBundle() {
95-
return provision(bundle()
96-
.add(MbeanServerActivator.class)
97-
.set(Constants.BUNDLE_ACTIVATOR, MbeanServerActivator.class.getName())
98-
.build(withBnd()));
99-
}
100-
10192
protected Option bundlea() {
10293
return provision(bundle()
10394
.add(org.apache.aries.jmx.test.bundlea.Activator.class)

jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/MbeanServerActivator.java

-35
This file was deleted.

jmx/jmx-mbeanserver-platform/pom.xml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>org.apache.aries.jmx</groupId>
26+
<artifactId>org.apache.aries.jmx.parent</artifactId>
27+
<version>1.1.5</version>
28+
<relativePath>../jmx-parent</relativePath>
29+
</parent>
30+
31+
<artifactId>org.apache.aries.jmx.mbeanserver-platform</artifactId>
32+
<version>0.0.1-SNAPSHOT</version>
33+
<packaging>bundle</packaging>
34+
<name>Apache Aries JMX MBeanServer (Platform)</name>
35+
<description>
36+
This bundle registers a MBeanServer service based on the Platform MBeanServer.
37+
</description>
38+
39+
<scm>
40+
<connection>scm:git:[email protected]:apache/aries.git</connection>
41+
<developerConnection>scm:git:[email protected]:apache/aries.git</developerConnection>
42+
<tag>HEAD</tag>
43+
</scm>
44+
45+
<properties>
46+
47+
<aries.osgi.activator>
48+
org.apache.aries.jmx.mbean_server.platform.impl.Activator
49+
</aries.osgi.activator>
50+
<aries.osgi.export.pkg/>
51+
<aries.osgi.private.pkg>
52+
org.apache.aries.jmx.mbean_server.platform.impl
53+
</aries.osgi.private.pkg>
54+
<lastReleaseVersion>0.1.0-SNAPSHOT</lastReleaseVersion>
55+
</properties>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.osgi</groupId>
60+
<artifactId>org.osgi.core</artifactId>
61+
<scope>provided</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.aries.versioning</groupId>
69+
<artifactId>org.apache.aries.versioning.plugin</artifactId>
70+
<executions>
71+
<execution>
72+
<id>default-verify</id>
73+
<phase>none</phase> <!-- TODO: switch to verify after the first release -->
74+
<goals>
75+
<goal>version-check</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.aries.jmx.mbean_server.platform.impl;
20+
21+
import java.lang.management.ManagementFactory;
22+
import java.util.Hashtable;
23+
24+
import javax.management.Attribute;
25+
import javax.management.AttributeList;
26+
import javax.management.MBeanServer;
27+
import javax.management.ObjectName;
28+
29+
import org.osgi.framework.BundleActivator;
30+
import org.osgi.framework.BundleContext;
31+
import org.osgi.framework.ServiceRegistration;
32+
33+
public class Activator implements BundleActivator {
34+
35+
private final Object registrationLock = new Object();
36+
private ServiceRegistration<MBeanServer> registration;
37+
38+
@Override
39+
public void start(BundleContext context) throws Exception {
40+
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
41+
Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
42+
ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
43+
AttributeList attrs = platformMBeanServer.getAttributes(beanName, new String[] {
44+
"MBeanServerId",
45+
"SpecificationName",
46+
"SpecificationVersion",
47+
"SpecificationVendor",
48+
"ImplementationName",
49+
"ImplementationVersion",
50+
"ImplementationVendor"
51+
});
52+
for (Object object : attrs) {
53+
Attribute attr = (Attribute) object;
54+
if (attr.getValue() != null) {
55+
mbeanProps.put(attr.getName(), attr.getValue().toString());
56+
}
57+
}
58+
synchronized (registrationLock) {
59+
registration = context.registerService(MBeanServer.class, platformMBeanServer, mbeanProps);
60+
}
61+
}
62+
63+
@Override
64+
public void stop(BundleContext context) throws Exception {
65+
synchronized (registrationLock) {
66+
if (registration != null) {
67+
registration.unregister();
68+
registration = null;
69+
}
70+
}
71+
}
72+
}

jmx/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<module>jmx-bundle</module>
5252
<module>jmx-blueprint-bundle</module>
5353
<module>jmx-itests</module>
54+
<module>jmx-mbeanserver-platform</module>
5455
</modules>
5556

5657
</project>

0 commit comments

Comments
 (0)