private void unregisterGmbal(StatsProviderRegistryElement spre) { // unregister the statsProvider from Gmbal ManagedObjectManager mom = spre.getManagedObjectManager(); if (mom != null) { mom.unregister(spre.getStatsProvider()); try { mom.close(); } catch (IOException ioe) { logger.log(Level.SEVERE, gmbalUnRegistrationFailed, ioe); } spre.setManagedObjectManager(null); } }
@Override public void mbeanRegistered( javax.management.ObjectName objectName, org.glassfish.external.amx.MBeanListener listener) { ObjectName MONITORING_SERVER = AMXGlassfish.DEFAULT.serverMon(AMXGlassfish.DEFAULT.dasName()); mom = ManagedObjectManagerFactory.createFederated(MONITORING_SERVER); if (mom != null) { mom.setJMXRegistrationDebug(false); mom.stripPackagePrefix(); mom.createRoot(deploymentBean, "webservices-deployment"); } LazyMOMProvider.INSTANCE.initMOMForScope(LazyMOMProvider.Scope.GLASSFISH_JMX); }
@Override public void preDestroy() { try { if (mom != null) { mom.close(); } } catch (IOException ioe) { // ignored nothing much can be done } }
private ManagedObjectManager registerGmbal(Object statsProvider, String mbeanName) { ManagedObjectManager mom = null; try { // 1 mom per statsProvider mom = ManagedObjectManagerFactory.createFederated(MONITORING_SERVER); if (mom != null) { mom.setJMXRegistrationDebug(false); if (mom.isManagedObject(statsProvider)) { mom.stripPackagePrefix(); if (mbeanName != null && !mbeanName.isEmpty()) { if (mbeanName.indexOf('\\') > 0) { mbeanName = StringUtils.removeChar(mbeanName, '\\'); } mbeanName = mbeanName.replaceAll(SystemPropertyConstants.SLASH, "/"); mom.createRoot(statsProvider, mbeanName); } else { mom.createRoot(statsProvider); } } else { String spName = statsProvider.getClass().getName(); logger.log(Level.INFO, notaManagedObject, new Object[] {spName}); } } // To register hierarchy in mom specify parent ManagedObject, and the ManagedObject itself // DynamicMBean mbean = (DynamicMBean)mom.register(parent, obj); } catch (Exception e) { // createRoot failed - need to return a null mom so we know not to unregister an mbean that // does not exist mom = null; logger.log(Level.SEVERE, gmbalRegistrationFailed, e); } return mom; }