Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[ARIES-984] When shutting down, the JMX agent should wait for threads…

… to be terminated

Conflicts:
	jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java

git-svn-id: https://svn.apache.org/repos/asf/aries/trunk@1421116 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 5b4d5d223fbcbdd50410008eaa69daef8b8901f3 1 parent 414dc66
@gnodet gnodet authored
View
25 jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java
@@ -20,7 +20,7 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-
+import java.util.concurrent.TimeUnit;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
@@ -185,11 +185,6 @@ public synchronized void unregisterMBeans(final MBeanServer server) {
*/
public synchronized void registerMBean(final MBeanHandler mBeanHandler) {
Object[] servers = getMBeanServers();
- if (servers == null) {
- logger.log(LogService.LOG_WARNING, "There are no MBean servers registred, can't register MBeans");
- return;
- }
-
for (Object server : servers) {
String name = mBeanHandler.getName();
StandardMBean mbean = mBeanHandler.getMbean();
@@ -270,14 +265,21 @@ public synchronized void unregisterMBean(final String name) {
/**
* @see org.apache.aries.jmx.agent.JMXAgent#stop()
*/
- public synchronized void stop() {
+ public void stop() {
logger.log(LogService.LOG_INFO, "Stopping JMX OSGi agent");
- mbeanServiceTracker.close();
- for (MBeanHandler mBeanHandler : mbeansHandlers.keySet()) {
- mBeanHandler.close();
+ synchronized (this) {
+ mbeanServiceTracker.close();
+ for (MBeanHandler mBeanHandler : mbeansHandlers.keySet()) {
+ mBeanHandler.close();
+ }
}
if (registrationExecutor != null && !registrationExecutor.isShutdown()) {
registrationExecutor.shutdown();
+ try {
+ registrationExecutor.awaitTermination(5 * 60, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ logger.log(LogService.LOG_WARNING, "Interrupted while waiting for executor shutdown", e);
+ }
}
}
@@ -301,7 +303,8 @@ public void setAgentContext(JMXAgentContext agentContext) {
* @return array of MBean servers.
*/
private Object[] getMBeanServers() {
- return mbeanServiceTracker.getServices();
+ Object[] servers = mbeanServiceTracker.getServices();
+ return servers != null ? servers : new Object[0];
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.