@Override public final void onInit() throws Exception { Assert.isTrue( this.getBeanFactory() instanceof ListableBeanFactory, "A ListableBeanFactory is required."); Map<String, MBeanExporter> exporters = BeanFactoryUtils.beansOfTypeIncludingAncestors( (ListableBeanFactory) this.getBeanFactory(), MBeanExporter.class); Assert.isTrue(exporters.size() > 0, "No MBeanExporter is available in the current context."); MBeanExporter exporter = null; for (MBeanExporter exp : exporters.values()) { exporter = exp; if (exporter instanceof IntegrationMBeanExporter) { break; } } if (this.notificationMapper == null) { this.notificationMapper = new DefaultNotificationMapper(this.objectName, this.defaultNotificationType); } exporter.registerManagedResource(this.delegate, this.objectName); if (this.logger.isInfoEnabled()) { this.logger.info( "Registered JMX notification publisher as MBean with ObjectName: " + this.objectName); } }
/** Marks this repository as complete and ready for use. */ @Override public void start() { final Status status = _status.get(); if (status == Status.STARTING) { return; // already starting } checkStatus(status, Status.CREATING); if (_status.compareAndSet(status, Status.STARTING) == false) { return; // another thread just beat this one } try { // Spring interfaces for (final Lifecycle obj : _lifecycles) { obj.start(); } // JMX managed resources final MBeanServer jmxServer = findInstance(MBeanServer.class); if (jmxServer != null) { final MBeanExporter exporter = new MBeanExporter(); exporter.setServer(jmxServer); for (final Map.Entry<ObjectName, Object> resourceEntry : _managedResources.entrySet()) { exporter.registerManagedResource(resourceEntry.getValue(), resourceEntry.getKey()); } } _status.set(Status.RUNNING); } catch (final RuntimeException ex) { _status.set(Status.FAILED); throw ex; } finally { // reduce memory usage and avoid memory leaks _managedResources.clear(); _initialized.clear(); } }