http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DistributionLocatorJmxImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DistributionLocatorJmxImpl.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DistributionLocatorJmxImpl.java index ad60682..65c2477 100755 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DistributionLocatorJmxImpl.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DistributionLocatorJmxImpl.java @@ -1,81 +1,78 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; -//import org.apache.geode.admin.AdminException; -//import org.apache.geode.admin.DistributionLocator; +// import org.apache.geode.admin.AdminException; +// import org.apache.geode.admin.DistributionLocator; import org.apache.geode.admin.DistributionLocatorConfig; import org.apache.geode.admin.internal.AdminDistributedSystemImpl; import org.apache.geode.internal.i18n.LocalizedStrings; -//import org.apache.geode.internal.Assert; - -//import org.apache.commons.modeler.ManagedBean; -//import org.apache.commons.modeler.AttributeInfo; - -//import java.util.Date; -//import java.util.Set; - -//import javax.management.Attribute; -//import javax.management.AttributeList; -//import javax.management.Descriptor; -//import javax.management.JMException; -//import javax.management.MBeanServer; -//import javax.management.MalformedObjectNameException; -//import javax.management.Notification; -//import javax.management.NotificationListener; +// import org.apache.geode.internal.Assert; + +// import org.apache.commons.modeler.ManagedBean; +// import org.apache.commons.modeler.AttributeInfo; + +// import java.util.Date; +// import java.util.Set; + +// import javax.management.Attribute; +// import javax.management.AttributeList; +// import javax.management.Descriptor; +// import javax.management.JMException; +// import javax.management.MBeanServer; +// import javax.management.MalformedObjectNameException; +// import javax.management.Notification; +// import javax.management.NotificationListener; import javax.management.ObjectName; -//import javax.management.modelmbean.DescriptorSupport; +// import javax.management.modelmbean.DescriptorSupport; import javax.management.modelmbean.ModelMBean; -//import javax.management.modelmbean.ModelMBeanAttributeInfo; +// import javax.management.modelmbean.ModelMBeanAttributeInfo; /** * Provides MBean support for managing a distribution locator. * */ -public class DistributionLocatorJmxImpl -extends org.apache.geode.admin.internal.DistributionLocatorImpl -implements org.apache.geode.admin.jmx.internal.ManagedResource, - DistributionLocatorConfig { +public class DistributionLocatorJmxImpl + extends org.apache.geode.admin.internal.DistributionLocatorImpl + implements org.apache.geode.admin.jmx.internal.ManagedResource, DistributionLocatorConfig { /** The JMX object name of this managed resource */ private ObjectName objectName; // ------------------------------------------------------------------------- - // Constructor(s) + // Constructor(s) // ------------------------------------------------------------------------- - + /** - * Constructs new instance of DistributionLocatorJmxImpl for managing a - * distribution locator service via JMX. + * Constructs new instance of DistributionLocatorJmxImpl for managing a distribution locator + * service via JMX. */ public DistributionLocatorJmxImpl(DistributionLocatorConfig config, - AdminDistributedSystemImpl system) { + AdminDistributedSystemImpl system) { super(config, system); initializeMBean(); } /** Create and register the MBean to manage this resource */ private void initializeMBean() { - this.mbeanName = "GemFire:type=DistributionLocator,id=" + MBeanUtil.makeCompliantMBeanNameProperty(getId()); - this.objectName = - MBeanUtil.createMBean(this, MBeanUtil.lookupManagedBean(this)); + this.mbeanName = + "GemFire:type=DistributionLocator,id=" + MBeanUtil.makeCompliantMBeanNameProperty(getId()); + this.objectName = MBeanUtil.createMBean(this, MBeanUtil.lookupManagedBean(this)); } - //////////////////////// Configuration //////////////////////// + //////////////////////// Configuration //////////////////////// public String getHost() { return this.getConfig().getHost(); @@ -112,7 +109,7 @@ implements org.apache.geode.admin.jmx.internal.ManagedResource, public java.util.Properties getDistributedSystemProperties() { return this.getConfig().getDistributedSystemProperties(); } - + public void setDistributedSystemProperties(java.util.Properties props) { this.getConfig().setDistributedSystemProperties(props); } @@ -143,34 +140,35 @@ implements org.apache.geode.admin.jmx.internal.ManagedResource, } // ------------------------------------------------------------------------- - // MBean attributes - accessors/mutators + // MBean attributes - accessors/mutators // ------------------------------------------------------------------------- - + // ------------------------------------------------------------------------- - // JMX Notification listener + // JMX Notification listener // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- - // ManagedResource implementation + // ManagedResource implementation // ------------------------------------------------------------------------- - + /** The name of the MBean that will manage this resource */ private String mbeanName; /** The ModelMBean that is configured to manage this resource */ private ModelMBean modelMBean; - - public String getMBeanName() { - return this.mbeanName; - } - - public ModelMBean getModelMBean() { - return this.modelMBean; - } - public void setModelMBean(ModelMBean modelMBean) { - this.modelMBean = modelMBean; - } - + + public String getMBeanName() { + return this.mbeanName; + } + + public ModelMBean getModelMBean() { + return this.modelMBean; + } + + public void setModelMBean(ModelMBean modelMBean) { + this.modelMBean = modelMBean; + } + public ObjectName getObjectName() { return this.objectName; } @@ -178,8 +176,8 @@ implements org.apache.geode.admin.jmx.internal.ManagedResource, public ManagedResourceType getManagedResourceType() { return ManagedResourceType.DISTRIBUTION_LOCATOR; } - + public void cleanupResource() {} - + }
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DynamicManagedBean.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DynamicManagedBean.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DynamicManagedBean.java index 1b62fb0..32ee5b4 100755 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DynamicManagedBean.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/DynamicManagedBean.java @@ -1,18 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; @@ -26,17 +24,17 @@ import org.apache.commons.modeler.OperationInfo; import org.apache.commons.modeler.ManagedBean; /** - * Extends ManagedBean to allow for dynamically creating new instances of - * ManagedBean based on an existing instance of ManagedBean. + * Extends ManagedBean to allow for dynamically creating new instances of ManagedBean based on an + * existing instance of ManagedBean. * * @since GemFire 5.0.1 */ public class DynamicManagedBean extends org.apache.commons.modeler.ManagedBean { private static final long serialVersionUID = 4051924500150228160L; - + public DynamicManagedBean(ManagedBean managed) { super(); - + this.attributes = managed.getAttributes(); this.className = managed.getClassName(); this.constructors = managed.getConstructors(); @@ -48,9 +46,11 @@ public class DynamicManagedBean extends org.apache.commons.modeler.ManagedBean { this.notifications = managed.getNotifications(); this.operations = managed.getOperations(); this.type = managed.getType(); - - /* we don't use modelerType and it's nice to remove it to keep the list of - attributes cleaned up...*/ + + /* + * we don't use modelerType and it's nice to remove it to keep the list of attributes cleaned + * up... + */ removeAttribute("modelerType"); } @@ -70,22 +70,23 @@ public class DynamicManagedBean extends org.apache.commons.modeler.ManagedBean { attributesList.add(this.attributes[i]); } } - this.attributes = (AttributeInfo[]) - attributesList.toArray(new AttributeInfo[attributesList.size()]); - - /* super.info should be nulled out anytime the structure is changed, - * such as altering the attributes, operations, or notifications + this.attributes = + (AttributeInfo[]) attributesList.toArray(new AttributeInfo[attributesList.size()]); + + /* + * super.info should be nulled out anytime the structure is changed, such as altering the + * attributes, operations, or notifications * - * however super.info is private, so we need the following hack to cause - * the super class to null it out for us... + * however super.info is private, so we need the following hack to cause the super class to + * null it out for us... */ setType(this.type); // causes this in super: "this.info = null;" } } /** - * Removes the operation with the given name from thie - * <code>ManageBean</code>'s operation descriptor list. + * Removes the operation with the given name from thie <code>ManageBean</code>'s operation + * descriptor list. * * @since GemFire 4.0 */ @@ -101,14 +102,15 @@ public class DynamicManagedBean extends org.apache.commons.modeler.ManagedBean { operationsList.add(this.operations[i]); } } - this.operations = (OperationInfo[]) - operationsList.toArray(new OperationInfo[operationsList.size()]); - - /* super.info should be nulled out anytime the structure is changed, - * such as altering the operations, operations, or notifications + this.operations = + (OperationInfo[]) operationsList.toArray(new OperationInfo[operationsList.size()]); + + /* + * super.info should be nulled out anytime the structure is changed, such as altering the + * operations, operations, or notifications * - * however super.info is private, so we need the following hack to cause - * the super class to null it out for us... + * however super.info is private, so we need the following hack to cause the super class to + * null it out for us... */ setType(this.type); // causes this in super: "this.info = null;" } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthConfigJmxImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthConfigJmxImpl.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthConfigJmxImpl.java index f1bfa55..6c44811 100644 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthConfigJmxImpl.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthConfigJmxImpl.java @@ -1,18 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; @@ -25,29 +23,27 @@ import org.apache.geode.admin.GemFireHealthConfig; import org.apache.geode.admin.internal.GemFireHealthConfigImpl; /** - * The JMX "managed resource" that represents the configuration for - * the health of GemFire. Basically, it provides the behavior of - * <code>GemFireHealthConfigImpl</code>, but does some JMX stuff like - * registering beans with the agent. + * The JMX "managed resource" that represents the configuration for the health of GemFire. + * Basically, it provides the behavior of <code>GemFireHealthConfigImpl</code>, but does some JMX + * stuff like registering beans with the agent. * * <P> * - * Unlike other <code>ManagedResource</code>s this class cannot simply - * subclass <code>GemFireHealthImpl</code> because it instances are - * serialized and sent to other VMs. This is problematic because the - * other VMs most likely do not have JMX classes like - * <code>ModelMBean</code> on their classpaths. So, instead we - * delegate all of the <code>GemFireHealthConfig</code> behavior to - * another object which IS serialized. + * Unlike other <code>ManagedResource</code>s this class cannot simply subclass + * <code>GemFireHealthImpl</code> because it instances are serialized and sent to other VMs. This is + * problematic because the other VMs most likely do not have JMX classes like + * <code>ModelMBean</code> on their classpaths. So, instead we delegate all of the + * <code>GemFireHealthConfig</code> behavior to another object which IS serialized. * * @see GemFireHealthJmxImpl#createDistributedSystemHealthConfig * * * @since GemFire 3.5 */ -@edu.umd.cs.findbugs.annotations.SuppressWarnings(justification="This class is deprecated. Also, any further changes so close to the release is inadvisable.") +@edu.umd.cs.findbugs.annotations.SuppressWarnings( + justification = "This class is deprecated. Also, any further changes so close to the release is inadvisable.") public class GemFireHealthConfigJmxImpl - implements GemFireHealthConfig, ManagedResource, java.io.Serializable { + implements GemFireHealthConfig, ManagedResource, java.io.Serializable { private static final long serialVersionUID = 1482719647163239953L; @@ -66,34 +62,28 @@ public class GemFireHealthConfigJmxImpl /** The object name of this managed resource */ private ObjectName objectName; - /////////////////////// Constructors /////////////////////// + /////////////////////// Constructors /////////////////////// /** - * Creates a new <code>GemFireHealthConfigJmxImpl</code> that - * configures the health monitoring of components running on the - * given host. + * Creates a new <code>GemFireHealthConfigJmxImpl</code> that configures the health monitoring of + * components running on the given host. */ - GemFireHealthConfigJmxImpl(GemFireHealthJmxImpl health, - String hostName) - throws AdminException { + GemFireHealthConfigJmxImpl(GemFireHealthJmxImpl health, String hostName) throws AdminException { this.delegate = new GemFireHealthConfigImpl(hostName); this.health = health; - this.mbeanName = new StringBuffer() - .append(MBEAN_NAME_PREFIX) - .append("GemFireHealthConfig,id=") - .append(MBeanUtil.makeCompliantMBeanNameProperty(health.getDistributedSystem().getId())) - .append(",host=") - .append((hostName == null ? "default" : MBeanUtil.makeCompliantMBeanNameProperty(hostName))) - .toString(); + this.mbeanName = new StringBuffer().append(MBEAN_NAME_PREFIX).append("GemFireHealthConfig,id=") + .append(MBeanUtil.makeCompliantMBeanNameProperty(health.getDistributedSystem().getId())) + .append(",host=") + .append((hostName == null ? "default" : MBeanUtil.makeCompliantMBeanNameProperty(hostName))) + .toString(); this.objectName = MBeanUtil.createMBean(this); } - ////////////////////// Instance Methods ////////////////////// + ////////////////////// Instance Methods ////////////////////// /** - * Applies the changes made to this config back to the health - * monitor. + * Applies the changes made to this config back to the health monitor. * * @see GemFireHealth#setDistributedSystemHealthConfig */ @@ -110,7 +100,7 @@ public class GemFireHealthConfigJmxImpl public String getMBeanName() { return this.mbeanName; } - + public ModelMBean getModelMBean() { return this.modelMBean; } @@ -128,14 +118,13 @@ public class GemFireHealthConfigJmxImpl } /** - * Replace this object with the delegate that can be properly - * serialized. + * Replace this object with the delegate that can be properly serialized. */ public Object writeReplace() { return this.delegate; } - ////////////////////// MemberHealthConfig ////////////////////// + ////////////////////// MemberHealthConfig ////////////////////// public long getMaxVMProcessSize() { return delegate.getMaxVMProcessSize(); @@ -164,14 +153,14 @@ public class GemFireHealthConfigJmxImpl public double getMaxRetransmissionRatio() { return delegate.getMaxRetransmissionRatio(); } - + public void setMaxRetransmissionRatio(double ratio) { delegate.setMaxRetransmissionRatio(ratio); } - ////////////////////// CacheHealthConfig ////////////////////// + ////////////////////// CacheHealthConfig ////////////////////// - public long getMaxNetSearchTime() { + public long getMaxNetSearchTime() { return delegate.getMaxNetSearchTime(); } @@ -203,7 +192,7 @@ public class GemFireHealthConfigJmxImpl delegate.setMaxEventQueueSize(maxEventQueueSize); } - ////////////////////// GemFireHealthConfig ////////////////////// + ////////////////////// GemFireHealthConfig ////////////////////// public String getHostName() { return delegate.getHostName(); @@ -218,5 +207,5 @@ public class GemFireHealthConfigJmxImpl } public void cleanupResource() {} - + } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthJmxImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthJmxImpl.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthJmxImpl.java index 1f8d322..a47ff27 100644 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthJmxImpl.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GemFireHealthJmxImpl.java @@ -1,18 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; @@ -31,24 +29,22 @@ import org.apache.geode.admin.internal.GemFireHealthImpl; import org.apache.geode.internal.admin.GfManagerAgent; import org.apache.geode.internal.i18n.LocalizedStrings; import org.apache.geode.internal.logging.LogService; -//import org.apache.commons.modeler.ManagedBean; +// import org.apache.commons.modeler.ManagedBean; /** - * The JMX "managed resource" that represents the health of GemFire. - * Basically, it provides the behavior of - * <code>GemFireHealthImpl</code>, but does some JMX stuff like - * registering beans with the agent. + * The JMX "managed resource" that represents the health of GemFire. Basically, it provides the + * behavior of <code>GemFireHealthImpl</code>, but does some JMX stuff like registering beans with + * the agent. * * @see AdminDistributedSystemJmxImpl#createGemFireHealth * * * @since GemFire 3.5 */ -public class GemFireHealthJmxImpl extends GemFireHealthImpl - implements ManagedResource { +public class GemFireHealthJmxImpl extends GemFireHealthImpl implements ManagedResource { private static final Logger logger = LogService.getLogger(); - + /** The name of the MBean that will manage this resource */ private String mbeanName; @@ -58,71 +54,67 @@ public class GemFireHealthJmxImpl extends GemFireHealthImpl /** The object name of the MBean created for this managed resource */ private final ObjectName objectName; - /////////////////////// Constructors /////////////////////// + /////////////////////// Constructors /////////////////////// /** - * Creates a new <code>GemFireHealthJmxImpl</code> that monitors the - * health of the given distributed system and uses the given JMX - * agent. + * Creates a new <code>GemFireHealthJmxImpl</code> that monitors the health of the given + * distributed system and uses the given JMX agent. */ - GemFireHealthJmxImpl(GfManagerAgent agent, - AdminDistributedSystemJmxImpl system) - throws AdminException { + GemFireHealthJmxImpl(GfManagerAgent agent, AdminDistributedSystemJmxImpl system) + throws AdminException { super(agent, system); - this.mbeanName = new StringBuffer() - .append(MBEAN_NAME_PREFIX) - .append("GemFireHealth,id=") - .append(MBeanUtil.makeCompliantMBeanNameProperty(system.getId())) - .toString(); + this.mbeanName = new StringBuffer().append(MBEAN_NAME_PREFIX).append("GemFireHealth,id=") + .append(MBeanUtil.makeCompliantMBeanNameProperty(system.getId())).toString(); this.objectName = MBeanUtil.createMBean(this); } - ////////////////////// Instance Methods ////////////////////// + ////////////////////// Instance Methods ////////////////////// public String getHealthStatus() { return getHealth().toString(); } - - public ObjectName manageGemFireHealthConfig(String hostName) - throws MalformedObjectNameException { + + public ObjectName manageGemFireHealthConfig(String hostName) throws MalformedObjectNameException { try { GemFireHealthConfig config = getGemFireHealthConfig(hostName); GemFireHealthConfigJmxImpl jmx = (GemFireHealthConfigJmxImpl) config; return new ObjectName(jmx.getMBeanName()); - } //catch (AdminException e) { logWriter.warning(e); throw e; } - catch (RuntimeException e) { - logger.warn(e.getMessage(), e); - throw e; + } // catch (AdminException e) { logWriter.warning(e); throw e; } + catch (RuntimeException e) { + logger.warn(e.getMessage(), e); + throw e; } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); - // If this ever returns, rethrow the error. We're poisoned + // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; - } catch (Error e) { + } catch (Error e) { // Whenever you catch Error or Throwable, you must also - // catch VirtualMachineError (see above). However, there is + // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: SystemFailure.checkFailure(); logger.error(e.getMessage(), e); - throw e; + throw e; } } - + /** * Creates a new {@link DistributedSystemHealthConfigJmxImpl} */ @Override - protected DistributedSystemHealthConfig - createDistributedSystemHealthConfig() { + protected DistributedSystemHealthConfig createDistributedSystemHealthConfig() { try { return new DistributedSystemHealthConfigJmxImpl(this); } catch (AdminException ex) { - throw new RuntimeAdminException(LocalizedStrings.GemFireHealthJmxImpl_WHILE_GETTING_THE_DISTRIBUTEDSYSTEMHEALTHCONFIG.toLocalizedString(), ex); + throw new RuntimeAdminException( + LocalizedStrings.GemFireHealthJmxImpl_WHILE_GETTING_THE_DISTRIBUTEDSYSTEMHEALTHCONFIG + .toLocalizedString(), + ex); } } @@ -130,31 +122,32 @@ public class GemFireHealthJmxImpl extends GemFireHealthImpl * Creates a new {@link GemFireHealthConfigJmxImpl} */ @Override - protected GemFireHealthConfig - createGemFireHealthConfig(String hostName) { + protected GemFireHealthConfig createGemFireHealthConfig(String hostName) { try { return new GemFireHealthConfigJmxImpl(this, hostName); } catch (AdminException ex) { - throw new RuntimeAdminException(LocalizedStrings.GemFireHealthJmxImpl_WHILE_GETTING_THE_GEMFIREHEALTHCONFIG.toLocalizedString(), ex); + throw new RuntimeAdminException( + LocalizedStrings.GemFireHealthJmxImpl_WHILE_GETTING_THE_GEMFIREHEALTHCONFIG + .toLocalizedString(), + ex); } } /** - * Ensures that the three primary Health MBeans are registered and returns - * their ObjectNames. + * Ensures that the three primary Health MBeans are registered and returns their ObjectNames. */ protected void ensureMBeansAreRegistered() { MBeanUtil.ensureMBeanIsRegistered(this); - MBeanUtil.ensureMBeanIsRegistered((ManagedResource)this.defaultConfig); - MBeanUtil.ensureMBeanIsRegistered((ManagedResource)this.dsHealthConfig); + MBeanUtil.ensureMBeanIsRegistered((ManagedResource) this.defaultConfig); + MBeanUtil.ensureMBeanIsRegistered((ManagedResource) this.dsHealthConfig); } - + public String getMBeanName() { return this.mbeanName; } - + public ModelMBean getModelMBean() { return this.modelMBean; } @@ -174,5 +167,5 @@ public class GemFireHealthJmxImpl extends GemFireHealthImpl public void cleanupResource() { close(); } - + } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GenerateMBeanHTML.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GenerateMBeanHTML.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GenerateMBeanHTML.java index 2c4f63e..5375a19 100644 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GenerateMBeanHTML.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/GenerateMBeanHTML.java @@ -1,18 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; @@ -24,12 +22,11 @@ import javax.xml.parsers.SAXParserFactory; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import java.io.*; -//import java.util.*; +// import java.util.*; /** - * A tool that reads the XML description of MBeans used with the - * Jakarta Commons Modeler and generates an HTML file that documents - * each MBean. + * A tool that reads the XML description of MBeans used with the Jakarta Commons Modeler and + * generates an HTML file that documents each MBean. * * @since GemFire 3.5 */ @@ -37,15 +34,15 @@ public class GenerateMBeanHTML extends DefaultHandler { /** The location of the DTD for the MBean descriptions */ private static final String DTD_LOCATION = - "/org/apache/geode/admin/jmx/internal/doc-files/mbeans-descriptors.dtd"; + "/org/apache/geode/admin/jmx/internal/doc-files/mbeans-descriptors.dtd"; -// /** The system id of MBean description's DTD */ -// private static final String SYSTEM_ID = -// "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd"; + // /** The system id of MBean description's DTD */ + // private static final String SYSTEM_ID = + // "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd"; -// /** The public id for the DTD */ -// private static final String PUBLIC_ID = -// "-//Apache Software Foundation//DTD Model MBeans Configuration File"; + // /** The public id for the DTD */ + // private static final String PUBLIC_ID = + // "-//Apache Software Foundation//DTD Model MBeans Configuration File"; /** The name of the "mbean-descriptors" element */ private static final String MBEANS_DESCRIPTORS = "mbeans-descriptors"; @@ -80,8 +77,8 @@ public class GenerateMBeanHTML extends DefaultHandler { /** The name of the "notification" element */ private static final String NOTIFICATION = "notification"; -// /** The name of the "description" element */ -// private static final String DESCRIPTOR = "descriptor"; + // /** The name of the "description" element */ + // private static final String DESCRIPTOR = "descriptor"; /** The name of the "field" element */ private static final String FIELD = "field"; @@ -89,7 +86,7 @@ public class GenerateMBeanHTML extends DefaultHandler { /** The name of the "value" attribute */ private static final String VALUE = "value"; - ////////////////////// Instance Fields /////////////////////// + ////////////////////// Instance Fields /////////////////////// /** Where the generated HTML data is written */ private PrintWriter pw; @@ -103,14 +100,13 @@ public class GenerateMBeanHTML extends DefaultHandler { /** Have we seen notifications for the current MBean? */ private boolean seenNotifications = false; - /////////////////////// Static Methods /////////////////////// + /////////////////////// Static Methods /////////////////////// /** - * Converts data from the given <code>InputStream</code> into HTML - * that is written to the given <code>PrintWriter</code> + * Converts data from the given <code>InputStream</code> into HTML that is written to the given + * <code>PrintWriter</code> */ - private static void convert(InputStream in, PrintWriter out) - throws Exception { + private static void convert(InputStream in, PrintWriter out) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); @@ -119,45 +115,47 @@ public class GenerateMBeanHTML extends DefaultHandler { parser.parse(in, handler); } - //////////////////////// Constructors //////////////////////// + //////////////////////// Constructors //////////////////////// /** - * Creates a new <code>GenerateMBeanHTML</code> that writes to the - * given <code>PrintWriter</code>. + * Creates a new <code>GenerateMBeanHTML</code> that writes to the given <code>PrintWriter</code>. */ private GenerateMBeanHTML(PrintWriter pw) { this.pw = pw; } - ////////////////////// Instance Methods ////////////////////// + ////////////////////// Instance Methods ////////////////////// /** - * Given a public id, attempt to resolve it to a DTD. Returns an - * <code>InputSoure</code> for the DTD. + * Given a public id, attempt to resolve it to a DTD. Returns an <code>InputSoure</code> for the + * DTD. */ @Override - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException { + public InputSource resolveEntity(String publicId, String systemId) throws SAXException { if (publicId == null || systemId == null) { - throw new SAXException(LocalizedStrings.GenerateMBeanHTML_PUBLIC_ID_0_SYSTEM_ID_1.toLocalizedString(new Object[] {publicId, systemId})); + throw new SAXException(LocalizedStrings.GenerateMBeanHTML_PUBLIC_ID_0_SYSTEM_ID_1 + .toLocalizedString(new Object[] {publicId, systemId})); } // Figure out the location for the publicId. String location = DTD_LOCATION; InputSource result; -// if (location != null) (cannot be null) + // if (location != null) (cannot be null) { InputStream stream = ClassPathLoader.getLatest().getResourceAsStream(getClass(), location); if (stream != null) { result = new InputSource(stream); } else { - throw new SAXNotRecognizedException(LocalizedStrings.GenerateMBeanHTML_DTD_NOT_FOUND_0.toLocalizedString(location)); + throw new SAXNotRecognizedException( + LocalizedStrings.GenerateMBeanHTML_DTD_NOT_FOUND_0.toLocalizedString(location)); } -// } else { -// throw new SAXNotRecognizedException(LocalizedStrings.GenerateMBeanHTML_COULD_NOT_FIND_DTD_FOR_0_1.toLocalizedString(new Object[] {publicId, systemId})); + // } else { + // throw new + // SAXNotRecognizedException(LocalizedStrings.GenerateMBeanHTML_COULD_NOT_FIND_DTD_FOR_0_1.toLocalizedString(new + // Object[] {publicId, systemId})); } return result; @@ -167,7 +165,7 @@ public class GenerateMBeanHTML extends DefaultHandler { * Warnings are ignored */ @Override - public void warning(SAXParseException ex) throws SAXException { + public void warning(SAXParseException ex) throws SAXException { } @@ -178,7 +176,7 @@ public class GenerateMBeanHTML extends DefaultHandler { public void error(SAXParseException ex) throws SAXException { throw ex; } - + /** * Rethrow the <code>SAXParseException</code> */ @@ -186,7 +184,7 @@ public class GenerateMBeanHTML extends DefaultHandler { public void fatalError(SAXParseException ex) throws SAXException { throw ex; } - + /** * Starts the HTML document */ @@ -198,9 +196,9 @@ public class GenerateMBeanHTML extends DefaultHandler { pw.println(""); pw.println("<h1>GemFire Management Beans</h1>"); pw.println(""); - pw.println("<P>This document describes the attributes, operations,"); + pw.println("<P>This document describes the attributes, operations,"); pw.println("and notifications of the GemFire Administration"); - pw.println("Management Beans (MBeans).</P>"); + pw.println("Management Beans (MBeans).</P>"); pw.println(""); } @@ -216,7 +214,7 @@ public class GenerateMBeanHTML extends DefaultHandler { */ private void startMBean(Attributes atts) { String name = atts.getValue(NAME); - /*String description =*/ atts.getValue(DESCRIPTION); + /* String description = */ atts.getValue(DESCRIPTION); pw.println("<h2><b>" + name + "</b> MBean</h2>"); pw.println("<table border=\"0\" cellpadding=\"3\">"); pw.println("<tr valign=\"top\">"); @@ -287,7 +285,7 @@ public class GenerateMBeanHTML extends DefaultHandler { pw.println("</tr>"); } else { - String title = "Operations and Parameters"; + String title = "Operations and Parameters"; pw.println("<tr valign=\"top\">"); pw.println(" <th align=\"left\" colspan=\"6\">" + title + "</th>"); pw.println("</tr>"); @@ -306,7 +304,7 @@ public class GenerateMBeanHTML extends DefaultHandler { pw.println(" <td>" + type + "</td>"); pw.println(" <td colspan=\"2\">" + description + "</td>"); pw.println("</tr>"); - + } /** @@ -352,13 +350,13 @@ public class GenerateMBeanHTML extends DefaultHandler { String name = atts.getValue(NAME); String description = atts.getValue(DESCRIPTION); - + pw.println("<tr valign=\"top\">"); pw.println(" <td></td>"); pw.println(" <td colspan=\"3\">" + name + "</td>"); pw.println(" <td colspan=\"3\">" + description + "</td>"); pw.println("</tr>"); - + } /** @@ -374,13 +372,12 @@ public class GenerateMBeanHTML extends DefaultHandler { pw.println(" <td colspan=\"2\">" + name + "</td>"); pw.println(" <td colspan=\"2\">" + value + "</td>"); pw.println("</tr>"); - + } @Override - public void startElement(String namespaceURI, String localName, - String qName, Attributes atts) - throws SAXException { + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) + throws SAXException { if (qName.equals(MBEANS_DESCRIPTORS)) { startMBeansDescriptors(); @@ -408,9 +405,7 @@ public class GenerateMBeanHTML extends DefaultHandler { @Override - public void endElement(String namespaceURI, String localName, - String qName) - throws SAXException { + public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (qName.equals(MBEANS_DESCRIPTORS)) { endMBeansDescriptors(); @@ -421,45 +416,40 @@ public class GenerateMBeanHTML extends DefaultHandler { } - ////////// Inherited methods that don't do anything ////////// + ////////// Inherited methods that don't do anything ////////// @Override - public void characters(char[] ch, int start, int length) - throws SAXException { + public void characters(char[] ch, int start, int length) throws SAXException { } @Override - public void setDocumentLocator(Locator locator) { } + public void setDocumentLocator(Locator locator) {} @Override - public void startDocument() throws SAXException { } + public void startDocument() throws SAXException {} @Override - public void endDocument() throws SAXException { } + public void endDocument() throws SAXException {} @Override - public void startPrefixMapping(String prefix, String uri) - throws SAXException { } + public void startPrefixMapping(String prefix, String uri) throws SAXException {} @Override - public void endPrefixMapping(String prefix) - throws SAXException { } + public void endPrefixMapping(String prefix) throws SAXException {} @Override - public void ignorableWhitespace(char[] ch, int start, int length) - throws SAXException { } + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {} @Override - public void processingInstruction(String target, String data) - throws SAXException { } + public void processingInstruction(String target, String data) throws SAXException {} @Override - public void skippedEntity(String name) throws SAXException { } + public void skippedEntity(String name) throws SAXException {} - //////////////////////// Main Program //////////////////////// + //////////////////////// Main Program //////////////////////// -// private static final PrintStream out = System.out; + // private static final PrintStream out = System.out; private static final PrintStream err = System.err; /** @@ -506,8 +496,7 @@ public class GenerateMBeanHTML extends DefaultHandler { } File htmlFile = new File(htmlFileName); - convert(new FileInputStream(xmlFile), - new PrintWriter(new FileWriter(htmlFile), true)); + convert(new FileInputStream(xmlFile), new PrintWriter(new FileWriter(htmlFile), true)); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtil.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtil.java b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtil.java index d805b8a..b2c5883 100755 --- a/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtil.java +++ b/geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtil.java @@ -1,18 +1,16 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.geode.admin.jmx.internal; @@ -52,48 +50,48 @@ import org.apache.geode.internal.logging.InternalLogWriter; import org.apache.geode.internal.logging.LogService; /** - * Common support for MBeans and {@link ManagedResource}s. Static loading of - * this class creates the MBeanServer and Modeler Registry. + * Common support for MBeans and {@link ManagedResource}s. Static loading of this class creates the + * MBeanServer and Modeler Registry. * - * @since GemFire 3.5 + * @since GemFire 3.5 * */ public class MBeanUtil { - + private static final Logger logger = LogService.getLogger(); - + /** The default MBeanServer domain name is "GemFire" */ private static final String DEFAULT_DOMAIN = "GemFire"; /** MBean Name for refreshTimer */ private static String REFRESH_TIMER_NAME = DEFAULT_DOMAIN + ":type=RefreshTimer"; - + /* indicates whether the mbeanServer, registry & refreshTimer are started */ private static boolean isStarted; - + /** The Commons-Modeler configuration registry for our managed beans */ private static Registry registry; /** The <code>MBeanServer</code> for this application */ private static MBeanServer mbeanServer; - + /** MBean name of the Timer which handles refresh notifications */ private static ObjectName refreshTimerObjectName; - + /** Actual TimerMBean responsible for refresh notifications */ private static TimerMBean refreshTimer; - - /** + + /** * Map of ObjectNames to current timerNotificationIds * <p> - * map: key=ObjectName, - * value=map: key=RefreshNotificationType, - * value=timerNotificationId + * map: key=ObjectName, value=map: key=RefreshNotificationType, value=timerNotificationId */ - private static Map<NotificationListener, Map<RefreshNotificationType, Integer>> refreshClients = new HashMap<NotificationListener, Map<RefreshNotificationType, Integer>>(); - + private static Map<NotificationListener, Map<RefreshNotificationType, Integer>> refreshClients = + new HashMap<NotificationListener, Map<RefreshNotificationType, Integer>>(); + /** key=ObjectName, value=ManagedResource */ - private final static Map<ObjectName, ManagedResource> managedResources = new HashMap<ObjectName, ManagedResource>(); + private final static Map<ObjectName, ManagedResource> managedResources = + new HashMap<ObjectName, ManagedResource>(); static { try { @@ -102,18 +100,17 @@ public class MBeanUtil { logStackTrace(Level.ERROR, e); } } - + /** - * Initializes Mbean Server, Registry, Refresh Timer & registers Server - * Notification Listener. + * Initializes Mbean Server, Registry, Refresh Timer & registers Server Notification Listener. * * @return reference to the mbeanServer */ static MBeanServer start() { if (!isStarted) { mbeanServer = createMBeanServer(); - registry = createRegistry(); - + registry = createRegistry(); + registerServerNotificationListener(); createRefreshTimer(); isStarted = true; @@ -121,25 +118,24 @@ public class MBeanUtil { return mbeanServer; } - + /** * Stops Registry, Refresh Timer. Releases Mbean Server after. */ static void stop() { if (isStarted) { stopRefreshTimer(); - + registry.stop(); registry = null; - releaseMBeanServer();//makes mbeanServer null + releaseMBeanServer();// makes mbeanServer null isStarted = false; } } /** - * Create and configure (if necessary) and return the <code>MBeanServer</code> - * with which we will be registering our <code>ModelMBean</code> - * implementations. + * Create and configure (if necessary) and return the <code>MBeanServer</code> with which we will + * be registering our <code>ModelMBean</code> implementations. * * @see javax.management.MBeanServer */ @@ -151,8 +147,8 @@ public class MBeanUtil { } /** - * Create and configure (if necessary) and return the Commons-Modeler registry - * of managed object descriptions. + * Create and configure (if necessary) and return the Commons-Modeler registry of managed object + * descriptions. * * @see org.apache.commons.modeler.Registry */ @@ -161,37 +157,37 @@ public class MBeanUtil { try { registry = Registry.getRegistry(null, null); if (mbeanServer == null) { - throw new IllegalStateException(LocalizedStrings.MBeanUtil_MBEAN_SERVER_NOT_INITIALIZED_YET.toLocalizedString()); + throw new IllegalStateException( + LocalizedStrings.MBeanUtil_MBEAN_SERVER_NOT_INITIALIZED_YET.toLocalizedString()); } registry.setMBeanServer(mbeanServer); - + String mbeansResource = getOSPath("/org/apache/geode/admin/jmx/mbeans-descriptors.xml"); - //System.out.println(LocalizedStrings.MBeanUtil_LOADING_RESOURCE_0.toLocalizedString(mbeansResource)); - + // System.out.println(LocalizedStrings.MBeanUtil_LOADING_RESOURCE_0.toLocalizedString(mbeansResource)); + URL url = ClassPathLoader.getLatest().getResource(MBeanUtil.class, mbeansResource); - raiseOnFailure(url != null, - LocalizedStrings.MBeanUtil_FAILED_TO_FIND_0.toLocalizedString(new Object[] {mbeansResource})); + raiseOnFailure(url != null, LocalizedStrings.MBeanUtil_FAILED_TO_FIND_0 + .toLocalizedString(new Object[] {mbeansResource})); registry.loadMetadata(url); - + // simple test to make sure the xml was actually loaded and is valid... String[] test = registry.findManagedBeans(); - raiseOnFailure(test != null && test.length > 0, - LocalizedStrings.MBeanUtil_FAILED_TO_LOAD_0.toLocalizedString(new Object[] {mbeansResource})); + raiseOnFailure(test != null && test.length > 0, LocalizedStrings.MBeanUtil_FAILED_TO_LOAD_0 + .toLocalizedString(new Object[] {mbeansResource})); } catch (Exception e) { logStackTrace(Level.WARN, e); - throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_GET_MBEAN_REGISTRY.toLocalizedString(), e); + throw new RuntimeAdminException( + LocalizedStrings.MBeanUtil_FAILED_TO_GET_MBEAN_REGISTRY.toLocalizedString(), e); } } return registry; } /** - * Creates and registers a <code>ModelMBean</code> for the specified - * <code>ManagedResource</code>. State changing callbacks into the - * <code>ManagedResource</code> will also be made. + * Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>. + * State changing callbacks into the <code>ManagedResource</code> will also be made. * - * @param resource - * the ManagedResource to create a managing MBean for + * @param resource the ManagedResource to create a managing MBean for * * @return The object name of the newly-created MBean * @@ -200,14 +196,13 @@ public class MBeanUtil { static ObjectName createMBean(ManagedResource resource) { return createMBean(resource, lookupManagedBean(resource)); } - + /** - * Creates and registers a <code>ModelMBean</code> for the specified - * <code>ManagedResource</code>. State changing callbacks into the - * <code>ManagedResource</code> will also be made. + * Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>. + * State changing callbacks into the <code>ManagedResource</code> will also be made. * * @param resource the ManagedResource to create a managing MBean for - * @param managed the ManagedBean definition to create the MBean with + * @param managed the ManagedBean definition to create the MBean with * @see ManagedResource#setModelMBean */ static ObjectName createMBean(ManagedResource resource, ManagedBean managed) { @@ -215,17 +210,18 @@ public class MBeanUtil { try { DynamicManagedBean mb = new DynamicManagedBean(managed); resource.setModelMBean(mb.createMBean(resource)); - + // create the ObjectName and register the MBean... final ObjectName objName; try { objName = ObjectName.getInstance(resource.getMBeanName()); } catch (MalformedObjectNameException e) { - throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1.toLocalizedString(new Object[] { e.getMessage(), resource.getMBeanName()} ) ); + throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1 + .toLocalizedString(new Object[] {e.getMessage(), resource.getMBeanName()})); } synchronized (MBeanUtil.class) { - // Only register a bean once. Otherwise, you risk race + // Only register a bean once. Otherwise, you risk race // conditions with things like the RMI connector accessing it. if (mbeanServer != null && !mbeanServer.isRegistered(objName)) { @@ -237,19 +233,18 @@ public class MBeanUtil { } return objName; } catch (java.lang.Exception e) { - throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0.toLocalizedString(new Object[]{resource.getMBeanName()}), e); + throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0 + .toLocalizedString(new Object[] {resource.getMBeanName()}), e); } } - + /** - * Ensures that an MBean is registered for the specified - * <code>ManagedResource</code>. If an MBean cannot be found in the - * <code>MBeanServer</code>, then this creates and registers a - * <code>ModelMBean</code>. State changing callbacks into the - * <code>ManagedResource</code> will also be made. + * Ensures that an MBean is registered for the specified <code>ManagedResource</code>. If an MBean + * cannot be found in the <code>MBeanServer</code>, then this creates and registers a + * <code>ModelMBean</code>. State changing callbacks into the <code>ManagedResource</code> will + * also be made. * - * @param resource - * the ManagedResource to create a managing MBean for + * @param resource the ManagedResource to create a managing MBean for * * @return The object name of the MBean that manages the ManagedResource * @@ -263,18 +258,18 @@ public class MBeanUtil { return createMBean(resource); } } - raiseOnFailure(mbeanServer.isRegistered(objName), - LocalizedStrings.MBeanUtil_COULDNT_FIND_MBEAN_REGISTERED_WITH_OBJECTNAME_0.toLocalizedString(new Object[] {objName.toString()})); + raiseOnFailure(mbeanServer.isRegistered(objName), + LocalizedStrings.MBeanUtil_COULDNT_FIND_MBEAN_REGISTERED_WITH_OBJECTNAME_0 + .toLocalizedString(new Object[] {objName.toString()})); return objName; - } - catch (java.lang.Exception e) { + } catch (java.lang.Exception e) { throw new RuntimeAdminException(e); } } - + /** - * Retrieves the <code>ManagedBean</code> configuration from the Registry for - * the specified <code>ManagedResource</code> + * Retrieves the <code>ManagedBean</code> configuration from the Registry for the specified + * <code>ManagedResource</code> * * @param resource the ManagedResource to find the configuration for */ @@ -282,60 +277,62 @@ public class MBeanUtil { // find the registry defn for our MBean... ManagedBean managed = null; if (registry != null) { - managed = registry.findManagedBean( - resource.getManagedResourceType().getClassTypeName()); + managed = registry.findManagedBean(resource.getManagedResourceType().getClassTypeName()); } else { - throw new IllegalArgumentException(LocalizedStrings.MBeanUtil_MANAGEDBEAN_IS_NULL.toLocalizedString()); + throw new IllegalArgumentException( + LocalizedStrings.MBeanUtil_MANAGEDBEAN_IS_NULL.toLocalizedString()); } - + if (managed == null) { - throw new IllegalArgumentException(LocalizedStrings.MBeanUtil_MANAGEDBEAN_IS_NULL.toLocalizedString()); + throw new IllegalArgumentException( + LocalizedStrings.MBeanUtil_MANAGEDBEAN_IS_NULL.toLocalizedString()); } - + // customize the defn... - managed.setClassName( - "org.apache.geode.admin.jmx.internal.MX4JModelMBean"); + managed.setClassName("org.apache.geode.admin.jmx.internal.MX4JModelMBean"); return managed; } /** - * Registers a refresh notification for the specified client MBean. - * Specifying zero for the refreshInterval disables notification for the - * refresh client. Note: this does not currently support remote connections. + * Registers a refresh notification for the specified client MBean. Specifying zero for the + * refreshInterval disables notification for the refresh client. Note: this does not currently + * support remote connections. * - * @param client client to listen for refresh notifications - * @param userData userData to register with the Notification - * @param type refresh notification type the client will use + * @param client client to listen for refresh notifications + * @param userData userData to register with the Notification + * @param type refresh notification type the client will use * @param refreshInterval the seconds between refreshes */ - static void registerRefreshNotification(NotificationListener client, - Object userData, - RefreshNotificationType type, - int refreshInterval) { + static void registerRefreshNotification(NotificationListener client, Object userData, + RefreshNotificationType type, int refreshInterval) { if (client == null) { - throw new IllegalArgumentException(LocalizedStrings.MBeanUtil_NOTIFICATIONLISTENER_IS_REQUIRED.toLocalizedString()); + throw new IllegalArgumentException( + LocalizedStrings.MBeanUtil_NOTIFICATIONLISTENER_IS_REQUIRED.toLocalizedString()); } if (type == null) { - throw new IllegalArgumentException(LocalizedStrings.MBeanUtil_REFRESHNOTIFICATIONTYPE_IS_REQUIRED.toLocalizedString()); + throw new IllegalArgumentException( + LocalizedStrings.MBeanUtil_REFRESHNOTIFICATIONTYPE_IS_REQUIRED.toLocalizedString()); } if (refreshTimerObjectName == null || refreshTimer == null) { - throw new IllegalStateException(LocalizedStrings.MBeanUtil_REFRESHTIMER_HAS_NOT_BEEN_PROPERLY_INITIALIZED.toLocalizedString()); + throw new IllegalStateException( + LocalizedStrings.MBeanUtil_REFRESHTIMER_HAS_NOT_BEEN_PROPERLY_INITIALIZED + .toLocalizedString()); } - + try { // get the notifications for the specified client... Map<RefreshNotificationType, Integer> notifications = null; synchronized (refreshClients) { - notifications = (Map<RefreshNotificationType, Integer>) refreshClients.get(client); + notifications = (Map<RefreshNotificationType, Integer>) refreshClients.get(client); } - + if (notifications == null) { // If refreshInterval is being set to zero and notifications is removed return if (refreshInterval <= 0) { return; } - + // never registered before, so add client... notifications = new HashMap<RefreshNotificationType, Integer>(); synchronized (refreshClients) { @@ -344,20 +341,21 @@ public class MBeanUtil { validateRefreshTimer(); try { // register client as a listener with MBeanServer... - mbeanServer.addNotificationListener( - refreshTimerObjectName, // timer to listen to - client, // the NotificationListener object - null, // optional NotificationFilter TODO: convert to using - new Object() // not used but null throws IllegalArgumentException - ); + mbeanServer.addNotificationListener(refreshTimerObjectName, // timer to listen to + client, // the NotificationListener object + null, // optional NotificationFilter TODO: convert to using + new Object() // not used but null throws IllegalArgumentException + ); } catch (InstanceNotFoundException e) { // should not happen since we already checked refreshTimerObjectName - logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_COULD_NOT_FIND_REGISTERED_REFRESHTIMER_INSTANCE.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_COULD_NOT_FIND_REGISTERED_REFRESHTIMER_INSTANCE + .toLocalizedString()); } } // TODO: change to manipulating timer indirectly thru mserver... - + // check for pre-existing refresh notification entry... Integer timerNotificationId = (Integer) notifications.get(type); if (timerNotificationId != null) { @@ -371,33 +369,31 @@ public class MBeanUtil { notifications.put(type, null); } } - + if (refreshInterval > 0) { // add notification to the refresh timer... - timerNotificationId = refreshTimer.addNotification( - type.getType(), // type - type.getMessage(), // message = "refresh" - userData, // userData - new Date(System.currentTimeMillis() + - refreshInterval * 1000), // first occurence - refreshInterval * 1000); // period to repeat - + timerNotificationId = refreshTimer.addNotification(type.getType(), // type + type.getMessage(), // message = "refresh" + userData, // userData + new Date(System.currentTimeMillis() + refreshInterval * 1000), // first occurence + refreshInterval * 1000); // period to repeat + // put an entry into the map for the listener... notifications.put(type, timerNotificationId); } else { - // do nothing! refreshInterval must be over 0 to do anything... + // do nothing! refreshInterval must be over 0 to do anything... } } catch (java.lang.RuntimeException e) { logStackTrace(Level.WARN, e); throw e; } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); - // If this ever returns, rethrow the error. We're poisoned + // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; } catch (java.lang.Error e) { // Whenever you catch Error or Throwable, you must also - // catch VirtualMachineError (see above). However, there is + // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: @@ -408,25 +404,25 @@ public class MBeanUtil { } /** - * Verifies a refresh notification for the specified client MBean. - * If notification is not registered, then returns a false + * Verifies a refresh notification for the specified client MBean. If notification is not + * registered, then returns a false * - * @param client client to listen for refresh notifications - * @param type refresh notification type the client will use + * @param client client to listen for refresh notifications + * @param type refresh notification type the client will use * - * @return isRegistered boolean indicating if a notification is registered + * @return isRegistered boolean indicating if a notification is registered */ static boolean isRefreshNotificationRegistered(NotificationListener client, - RefreshNotificationType type) { + RefreshNotificationType type) { boolean isRegistered = false; // get the notifications for the specified client... Map<RefreshNotificationType, Integer> notifications = null; - synchronized(refreshClients) { + synchronized (refreshClients) { notifications = (Map<RefreshNotificationType, Integer>) refreshClients.get(client); } - // never registered before if null ... + // never registered before if null ... if (notifications != null) { // check for pre-existing refresh notification entry... Integer timerNotificationId = notifications.get(type); @@ -437,60 +433,62 @@ public class MBeanUtil { return isRegistered; } - - /** - * Validates refreshTimer has been registered without problems and attempts - * to re-register if there is a problem. + + /** + * Validates refreshTimer has been registered without problems and attempts to re-register if + * there is a problem. */ static void validateRefreshTimer() { if (refreshTimerObjectName == null || refreshTimer == null) { - //if (refreshTimerObjectName == null) System.out.println("refreshTimerObjectName is null"); - //if (refreshTimer == null) System.out.println("refreshTimer is null"); - //System.out.println("[validateRefreshTimer] createRefreshTimer"); + // if (refreshTimerObjectName == null) System.out.println("refreshTimerObjectName is null"); + // if (refreshTimer == null) System.out.println("refreshTimer is null"); + // System.out.println("[validateRefreshTimer] createRefreshTimer"); createRefreshTimer(); } - - raiseOnFailure(refreshTimer != null, - "Failed to validate Refresh Timer"); + + raiseOnFailure(refreshTimer != null, "Failed to validate Refresh Timer"); if (mbeanServer != null && !mbeanServer.isRegistered(refreshTimerObjectName)) { - //System.out.println("[validateRefreshTimer] registerMBean"); + // System.out.println("[validateRefreshTimer] registerMBean"); try { mbeanServer.registerMBean(refreshTimer, refreshTimerObjectName); - } catch (JMException e) { - logStackTrace(Level.WARN, e); - } catch (JMRuntimeException e) { - logStackTrace(Level.WARN, e); - } - } + } catch (JMException e) { + logStackTrace(Level.WARN, e); + } catch (JMRuntimeException e) { + logStackTrace(Level.WARN, e); + } + } } - + /** * Initializes the timer for sending refresh notifications. */ - static void createRefreshTimer() { + static void createRefreshTimer() { try { refreshTimer = new javax.management.timer.Timer(); mbeanServer.registerMBean(refreshTimer, refreshTimerObjectName); - + refreshTimer.start(); } catch (JMException e) { - logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); } catch (JMRuntimeException e) { - logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); } catch (Exception e) { - logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_REFRESH_TIMER.toLocalizedString()); } } - + /** * Initializes the timer for sending refresh notifications. */ - static void stopRefreshTimer() { + static void stopRefreshTimer() { try { if (refreshTimer != null && mbeanServer != null) { mbeanServer.unregisterMBean(refreshTimerObjectName); - + refreshTimer.stop(); } } catch (JMException e) { @@ -498,26 +496,24 @@ public class MBeanUtil { } catch (JMRuntimeException e) { logStackTrace(Level.WARN, e); } catch (Exception e) { - logStackTrace(Level.DEBUG,e, "Failed to stop refresh timer for MBeanUtil"); + logStackTrace(Level.DEBUG, e, "Failed to stop refresh timer for MBeanUtil"); } } - + /** - * Return a String that been modified to be compliant as a property of an - * ObjectName. + * Return a String that been modified to be compliant as a property of an ObjectName. * <p> - * The property name of an ObjectName may not contain any of the following - * characters: <b><i>: , = * ?</i></b> + * The property name of an ObjectName may not contain any of the following characters: <b><i>: , = + * * ?</i></b> * <p> - * This method will replace the above non-compliant characters with a - * dash: <b><i>-</i></b> + * This method will replace the above non-compliant characters with a dash: <b><i>-</i></b> * <p> * If value is empty, this method will return the string "nothing". * <p> - * Note: this is <code>public</code> because certain tests call this from - * outside of the package. TODO: clean this up + * Note: this is <code>public</code> because certain tests call this from outside of the package. + * TODO: clean this up * - * @param value the potentially non-compliant ObjectName property + * @param value the potentially non-compliant ObjectName property * @return the value modified to be compliant as an ObjectName property */ public static String makeCompliantMBeanNameProperty(String value) { @@ -531,38 +527,41 @@ public class MBeanUtil { } return value; } - + /** - * Unregisters all GemFire MBeans and then releases the MBeanServer for - * garbage collection. + * Unregisters all GemFire MBeans and then releases the MBeanServer for garbage collection. */ static void releaseMBeanServer() { try { // unregister all GemFire mbeans... Iterator iter = mbeanServer.queryNames(null, null).iterator(); while (iter.hasNext()) { - ObjectName name = (ObjectName)iter.next(); + ObjectName name = (ObjectName) iter.next(); if (name.getDomain().startsWith(DEFAULT_DOMAIN)) { unregisterMBean(name); } } - + // last, release the mbean server... MBeanServerFactory.releaseMBeanServer(mbeanServer); mbeanServer = null; - } catch (JMRuntimeException e) { - logStackTrace(Level.WARN, e); - } - /* See #42391. Cleaning up the static maps which might be still holding - * references to ManagedResources */ - synchronized (MBeanUtil.managedResources) { - MBeanUtil.managedResources.clear(); - } - synchronized (refreshClients) { - refreshClients.clear(); - } - /* See #42391. Cleaning up the static maps which might be still holding - * references to ManagedResources */ + } catch (JMRuntimeException e) { + logStackTrace(Level.WARN, e); + } + /* + * See #42391. Cleaning up the static maps which might be still holding references to + * ManagedResources + */ + synchronized (MBeanUtil.managedResources) { + MBeanUtil.managedResources.clear(); + } + synchronized (refreshClients) { + refreshClients.clear(); + } + /* + * See #42391. Cleaning up the static maps which might be still holding references to + * ManagedResources + */ synchronized (MBeanUtil.managedResources) { MBeanUtil.managedResources.clear(); } @@ -570,19 +569,18 @@ public class MBeanUtil { refreshClients.clear(); } } - + /** * Returns true if a MBean with given ObjectName is registered. * - * @param objectName - * ObjectName to use for checking if MBean is registered - * @return true if MBeanServer is not null & MBean with given ObjectName is - * registered with the MBeanServer + * @param objectName ObjectName to use for checking if MBean is registered + * @return true if MBeanServer is not null & MBean with given ObjectName is registered with the + * MBeanServer */ static boolean isRegistered(ObjectName objectName) { return mbeanServer != null && mbeanServer.isRegistered(objectName); } - + /** * Unregisters the identified MBean if it's registered. */ @@ -592,25 +590,32 @@ public class MBeanUtil { mbeanServer.unregisterMBean(objectName); } } catch (MBeanRegistrationException e) { - logStackTrace(Level.WARN, null, LocalizedStrings.MBeanUtil_FAILED_WHILE_UNREGISTERING_MBEAN_WITH_OBJECTNAME_0.toLocalizedString(new Object[] {objectName})); + logStackTrace(Level.WARN, null, + LocalizedStrings.MBeanUtil_FAILED_WHILE_UNREGISTERING_MBEAN_WITH_OBJECTNAME_0 + .toLocalizedString(new Object[] {objectName})); } catch (InstanceNotFoundException e) { - logStackTrace(Level.WARN, null, LocalizedStrings.MBeanUtil_WHILE_UNREGISTERING_COULDNT_FIND_MBEAN_WITH_OBJECTNAME_0.toLocalizedString(new Object[] {objectName})); - } catch (JMRuntimeException e) { - logStackTrace(Level.WARN, null, LocalizedStrings.MBeanUtil_COULD_NOT_UNREGISTER_MBEAN_WITH_OBJECTNAME_0.toLocalizedString(new Object[] {objectName})); + logStackTrace(Level.WARN, null, + LocalizedStrings.MBeanUtil_WHILE_UNREGISTERING_COULDNT_FIND_MBEAN_WITH_OBJECTNAME_0 + .toLocalizedString(new Object[] {objectName})); + } catch (JMRuntimeException e) { + logStackTrace(Level.WARN, null, + LocalizedStrings.MBeanUtil_COULD_NOT_UNREGISTER_MBEAN_WITH_OBJECTNAME_0 + .toLocalizedString(new Object[] {objectName})); } } + static void unregisterMBean(ManagedResource resource) { if (resource != null) { unregisterMBean(resource.getObjectName()); - + // call cleanup on managedResource here and not rely on listener // since it is possible that notification listener not deliver - // all notifications of un-registration. If resource is + // all notifications of un-registration. If resource is // cleaned here, another call from the listener should be as good as a no-op cleanupResource(resource); } } - + // cleanup resource private static void cleanupResource(ManagedResource resource) { synchronized (MBeanUtil.managedResources) { @@ -624,17 +629,17 @@ public class MBeanUtil { notifications = (Map<RefreshNotificationType, Integer>) refreshClients.remove(resource); } - // never registered before if null ... - // Also as of current, there is ever only 1 Notification type per + // never registered before if null ... + // Also as of current, there is ever only 1 Notification type per // MBean, so we do need need a while loop here if (notifications != null) { // Fix for findbugs reported inefficiency with keySet(). Set<Map.Entry<RefreshNotificationType, Integer>> entries = notifications.entrySet(); - - for(Map.Entry<RefreshNotificationType, Integer> e : entries) { + + for (Map.Entry<RefreshNotificationType, Integer> e : entries) { Integer timerNotificationId = e.getValue(); - if(null != timerNotificationId) { + if (null != timerNotificationId) { try { // found one, so let's remove it... refreshTimer.removeNotification(timerNotificationId); @@ -644,13 +649,12 @@ public class MBeanUtil { } } } - + try { if (mbeanServer != null && mbeanServer.isRegistered(refreshTimerObjectName)) { // remove client as a listener with MBeanServer... - mbeanServer.removeNotificationListener( - refreshTimerObjectName, // timer to listen to - (NotificationListener)resource // the NotificationListener object + mbeanServer.removeNotificationListener(refreshTimerObjectName, // timer to listen to + (NotificationListener) resource // the NotificationListener object ); } } catch (ListenerNotFoundException xptn) { @@ -658,11 +662,13 @@ public class MBeanUtil { logStackTrace(Level.WARN, null, xptn.getMessage()); } catch (InstanceNotFoundException xptn) { // should not happen since we already checked refreshTimerObjectName - logStackTrace(Level.WARN, null, LocalizedStrings.MBeanUtil_WHILE_UNREGISTERING_COULDNT_FIND_MBEAN_WITH_OBJECTNAME_0.toLocalizedString(new Object[] {refreshTimerObjectName})); + logStackTrace(Level.WARN, null, + LocalizedStrings.MBeanUtil_WHILE_UNREGISTERING_COULDNT_FIND_MBEAN_WITH_OBJECTNAME_0 + .toLocalizedString(new Object[] {refreshTimerObjectName})); } } } - + // ----- borrowed the following from admin.internal.RemoteCommand ----- /** Translates the path between Windows and UNIX. */ static String getOSPath(String path) { @@ -676,8 +682,8 @@ public class MBeanUtil { /** Returns true if the path is on Windows. */ static boolean pathIsWindows(String path) { if (path != null && path.length() > 1) { - return (Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') || - (path.startsWith("//") || path.startsWith("\\\\")); + return (Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') + || (path.startsWith("//") || path.startsWith("\\\\")); } return false; } @@ -689,75 +695,68 @@ public class MBeanUtil { try { // the MBeanServerDelegate name is spec'ed as the following... ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); - mbeanServer.addNotificationListener( - delegate, - new NotificationListener() { - public void handleNotification(Notification notification, Object handback) { - MBeanServerNotification serverNotification = (MBeanServerNotification) notification; - if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) { - ObjectName objectName = serverNotification.getMBeanName(); - synchronized (MBeanUtil.managedResources) { - Object entry = MBeanUtil.managedResources.get(objectName); - if (entry == null) return; - if (!(entry instanceof ManagedResource)) { - throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE.toLocalizedString(new Object[] {entry.getClass().getName()})); - } - ManagedResource resource = (ManagedResource) entry; - { - // call cleanup on managedResource - cleanupResource(resource); - } + mbeanServer.addNotificationListener(delegate, new NotificationListener() { + public void handleNotification(Notification notification, Object handback) { + MBeanServerNotification serverNotification = (MBeanServerNotification) notification; + if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION + .equals(serverNotification.getType())) { + ObjectName objectName = serverNotification.getMBeanName(); + synchronized (MBeanUtil.managedResources) { + Object entry = MBeanUtil.managedResources.get(objectName); + if (entry == null) + return; + if (!(entry instanceof ManagedResource)) { + throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE + .toLocalizedString(new Object[] {entry.getClass().getName()})); + } + ManagedResource resource = (ManagedResource) entry; + { + // call cleanup on managedResource + cleanupResource(resource); } } } - }, - null, null); + } + }, null, null); } catch (JMException e) { - logStackTrace(Level.WARN, e, - LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER + .toLocalizedString()); } catch (JMRuntimeException e) { - logStackTrace(Level.WARN, e, - LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString()); + logStackTrace(Level.WARN, e, + LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER + .toLocalizedString()); } } /** - * Logs the stack trace for the given Throwable if logger is initialized else - * prints the stack trace using System.out. + * Logs the stack trace for the given Throwable if logger is initialized else prints the stack + * trace using System.out. * - * @param level - * severity level to log at - * @param throwable - * Throwable to log stack trace for + * @param level severity level to log at + * @param throwable Throwable to log stack trace for */ public static void logStackTrace(Level level, Throwable throwable) { logStackTrace(level, throwable, null); } /** - * Logs the stack trace for the given Throwable if logger is initialized else - * prints the stack trace using System.out. + * Logs the stack trace for the given Throwable if logger is initialized else prints the stack + * trace using System.out. * - * @param level - * severity level to log at - * @param throwable - * Throwable to log stack trace for - * @param message - * user friendly error message to show + * @param level severity level to log at + * @param throwable Throwable to log stack trace for + * @param message user friendly error message to show */ - public static void logStackTrace(Level level, Throwable throwable, - String message) { + public static void logStackTrace(Level level, Throwable throwable, String message) { logger.log(level, message, throwable); } /** - * Raises RuntimeAdminException with given 'message' if given 'condition' is - * false. + * Raises RuntimeAdminException with given 'message' if given 'condition' is false. * - * @param condition - * condition to evaluate - * @param message - * failure message + * @param condition condition to evaluate + * @param message failure message */ private static void raiseOnFailure(boolean condition, String message) { if (!condition) {